Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Folder in Internal memory

Tags:

android

I am unable to get the methods for creating folder in Internal Memory,

i gone through few conversations in Android create folders in Internal Memory and Problem facing in reading file from Internal memory of android. But still i am unable to meet my requirement.

My requirement is , I want to create a folder in Internal Memory, there i want to Store one video.

Thankyou you very much in advance for valuable feedbacks.

like image 485
Naveen Avatar asked Apr 05 '13 10:04

Naveen


1 Answers

To create directory on phone primary storage memory (generally internal memory) you should use following code. Please note that ExternalStorage in Environment.getExternalStorageDirectory() does not necessarily refers to sdcard, it returns phone primary storage memory

File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "MyDirName");

if (!mediaStorageDir.exists()) {
    if (!mediaStorageDir.mkdirs()) {
        Log.d("App", "failed to create directory");
        return null;
    }
}

Directory created using this code will be visible to phone user. The other method (as in accepted answer) creates directory in location (/data/data/package.name/app_MyDirName), hence normal phone user will not be able to access it easily and so you should not use it to store video/photo etc.

You will need permissions, in AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
like image 86
prodev Avatar answered Oct 16 '22 22:10

prodev