Creating Folder In Internal Memory
Solution 1:
try the below
Filemydir= context.getDir("users", Context.MODE_PRIVATE); //Creating an internal dir;if (!mydir.exists())
{
mydir.mkdirs();
}
Solution 2:
Here is the code which I am using for creating files in internal memory :
FilemyDir= context.getFilesDir();
// Documents PathStringdocuments="documents/data";
FiledocumentsFolder=newFile(myDir, documents);
documentsFolder.mkdirs(); // this line creates data folder at documents directoryStringpublicC="documents/public/api." + server;
FilepublicFolder=newFile(myDir, publicC);
publicFolder.mkdirs(); // and this line creates public/api.myservername folder in internal memory
Solution 3:
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
FilemediaStorageDir=newFile(Environment.getExternalStorageDirectory(), "MyDirName");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("App", "failed to create directory");
returnnull;
}
}
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-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_INTERNAL_STORAGE" />
Solution 4:
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" />
Filedirect=newFile(Environment.getExternalStorageDirectory()+"/folder_name");
if(!direct.exists()) {
if(direct.mkdir()); //directory is created;
}
Solution 5:
There is a "cacheDirectory" in your "data/package_name" directory.
If you want to store something in that cache memory,
FilecacheDir=newFile(this.getCacheDir(), "temp");
if (!cacheDir.exists())
cacheDir.mkdir();
where this is context.
Post a Comment for "Creating Folder In Internal Memory"