Mkdirs Returns False For Directory On Sd Card While The Parent Directory Is Writable
Solution 1:
It is common when you don't have a permission in your manifest.
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
As for me it was the only wrong thing.
Solution 2:
I had a simillar problem and spent several hours to realise what is wrong. It didn't work on Sumsung Mega, but for other phones it worked fine. I really had WRITE_EXTERNAL_STORAGE permission and getExternalStorageDirectory is mounted and available. But still the directory wasn't created. What helped ? I just restarted the divice! And it helped! It's a pity that nobody adviced this before. Hope this will help!
Solution 3:
First of all, technically mkdirs() returning false doesn't mean that it failed, it just meant that it didn't make the directories. If the directories already exist then mkdirs() will continue to return false.
Secondly, in Android 6, not only do you need:
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
You also need some equivalent of:
ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
For more info on checking permissions, see: https://github.com/googlesamples/android-RuntimePermissions
Solution 4:
I have had issues trying to create directories on the SDCard as well. I found what was happening is that my code would work fine on some phones, and also the emulator. However other phones would report errors.
I believe there is an issue with certain phones, the Atrix and the Bionic are two examples.
These phones when using the Environment.getExternalStorageDirectory() code actually return /mnt/sdcard.
However on these phones the SD card is actually /mnt/sdcard-ext.
So somewhere along the lines it looks like some manufactures have broken the getExternalStorageDirectory code, and somehow its returning a false location.
I had a heck of a time figuring this out because my code worked on many different devices, and still some users reported it failed.
Solution 5:
My problem was that I was using mkdir
for creating a multiple directories path and I got false
everytime. Once I used mkdirs
my problem got resolved
Post a Comment for "Mkdirs Returns False For Directory On Sd Card While The Parent Directory Is Writable"