tags:

views:

223

answers:

1

I use the following code to create a folder "mymir" and a file ".nomedia" (in the mymir-folder) on the sdcard of an android unit. However, somehow it fails with the exception that the folder the ".nomedia"-file is to be placed in dosn't exist. Here's the code:

private String EnsureRootDir() throws IOException
{
    File sdcard = Environment.getExternalStorageDirectory();
    File mymirFolder = new File(sdcard.getAbsolutePath() + "/mymir/");
    if(!mymirFolder.exists())
    {
        File noMedia = new File(mymirFolder.getAbsolutePath() + "/.nomedia");
        noMedia.mkdirs();
        noMedia.createNewFile();
    }
    return mymirFolder.getAbsolutePath();
}
+2  A: 

I SD really there?

Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) == true

If targeting 1.6+, have you declared

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

?
The exact Exception could help.

alex
I didn't get an exception on trying to create the dir. It only returned false. However, the problem was the user-permission I didn't have. I just found out, but thank you anyway :-)
Alxandr