I made a little file explorer in my app and I want to support creating new folders.
When navigating to a location in the device's built in memory, everything works as expected but when I navigate to my sd card and try to create a new folder, the line new File(path + File.separator + newFolderName).mkdirs()
returns false.
I've made the following debug tests:
String path = "/storage/external_SD"; // Not hard coded - user navigates here
new File(path).isDirectory(); --> true
new File(path).canRead(); --> true
new File(path).canWrite(); --> true
String newFolderPath = path + File.separator + newFolderName;
new File(newFolderPath).isDirectory(); --> false
new File(newFolderPath).mkdir(); --> false
new File(newFolderPath).mkdirs(); --> false
Something odd I've noticed: I put a breakpoint in the File class on the first line of mkdirs()
but the application didn't stop on the line and immediately returned false. This made me think that's a permissions issue even though I have the correct permission in the right location:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application ...>
...
</application>
</manifest>
What am I missing?