0

I have problem creating a directory,this the code that i'm using:

private void CreateDirectoryForPictures(){
    boolean res = isExternalStorageWritable();
    _dir = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "camerarealstate");
    if (!_dir.exists())
    {
        res = _dir.mkdir();
    }
}

also i have the following permission in the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.realstatediary.jperera.realstatediary" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

the method isExternalStorageWritable return true, i have added to the emulator an external sdCard. I don't know why i can't create the directory, i know this question is redundant in the forum but i check all the answers and i don't find the solution. I will appreciate any help with this. Thanks in advanced I don't have problem saving files, i have problem creating the directory, maybe is something about any configuration because as i know i don't have problem in the code, maybe someone had the same issue any time and could help me with any idea.

  • possible duplicate of [Write a file in external storage in Android](http://stackoverflow.com/questions/8330276/write-a-file-in-external-storage-in-android) – Jared Burrows Jul 30 '15 at 01:19
  • Is not the same, my problem is with the directories not to save the file, the problem is with the mkDir() method. –  Jul 30 '15 at 01:22
  • Did your try `_dir.mkdirs();`? – zzas11 Jul 30 '15 at 01:23

2 Answers2

1

Please try this method

res = _dir.mkdirs();
Melvin Mauricio
  • 387
  • 1
  • 6
0

Had a Similar problem, Somehow in the code:

 if (!_dir.exists())
{
    res = _dir.mkdir();
}

the body of loop doesn't get executed.

My advice is to try :

     File directory = new File(Environment.getExternalStorageDirectory()+"/myAppCache/");
     directory.mkdirs();

where mkdirs() creates parent directory.

OBX
  • 6,044
  • 7
  • 33
  • 77
  • thanks @oblivion i change mkdir() for mkdirs() and everything work fine! –  Jul 30 '15 at 01:33