user4773439
user4773439

Reputation:

unable to create directory in external storage android

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.

Upvotes: 0

Views: 1591

Answers (2)

OBX
OBX

Reputation: 6114

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.

Upvotes: 0

Melvin Mauricio
Melvin Mauricio

Reputation: 387

Please try this method

res = _dir.mkdirs();

Upvotes: 1

Related Questions