At some points while running my android application, I need to create a directory on the sd card, for a small number of users this fails and I can't figure out the reason for it...
(I've found similar problems caused by the WRITE_EXTERNAL_STORAGE permission missing, it's there and it works for almost all users so I don't think this is reason)
When mkdirs returns false I crash the program and log the following java.io.File properties, starting at the directory I want to create, then recursive printing properties of the parent directory and so on...
/sdcard/MyDirectory/Dir1/Dir2 (exists: false, canWrite: false, isDirectory: false, isFile: false);
/sdcard/MyDirectory/Dir1 (exists: true, canWrite: true, isDirectory: true, isFile: false);
/sdcard/MyDirectory (exists: true, canWrite: true, isDirectory: true, isFile: false);
/sdcard (exists: true, canWrite: true, isDirectory: true, isFile: false);
/ (exists: true, canWrite: false, isDirectory: true, isFile: false);
The strange thing is that the parent directory is writable (canWrite=true), I can't print the execute file permission but from what I've read, write is what you need when creating directories...
What I've looked at so far is the WRITE_EXTERNAL_STORAGE permission, if the sd card is full and if the sdcard is mounted read only:
ExternalStorageState = mounted
AvailableSpace = 6467747840b
Also relevant I think, I've only got reports from users on Android 1.6 for this problem.. The devices vary but all of them are running 1.6..
Solutions, suggestions, ideas, all is welcome...
Thanks for any help...
Edit:
The actual code is a bit hard to post because it is located in a number of different classes and a settings file, what it comes down to is this:
File directory = new File(Environment.getExternalStorageDirectory(), "MyDirectory/Dir1/Dir2");
if (directory.exists() == false)
{
directory.mkdirs();
if (directory.exists() == false)
{
ExceptionHandler.fatal("failed to create " + directory + ", info : " + printRecursiveInfo(directory));
}
}
where printRecursiveInfo gives me the info I posted above with canWrite etc...