The TL;DR question summary: My Android app tries to write to the app\'s external storage directory on an SD card. It fails with a permi
I've learned more about this issue, and it's different enough from CommonsWare's answer that I think it's worth a new answer.
/Android/data/com.example.myapp
folder on it that was not created on this phone, then the app might have trouble getting permission to write to that folder. Whereas if the folder did not exist, the app could create it, and write to it. At least in KitKat and later.
... starting with API Level 19 [KitKat], READ_EXTERNAL_STORAGE was no longer required to access files located on external storage – provided the data folder created by the FUSE daemon matches the app’s package name. FUSE would handle synthesizing the owner, group, and modes of files on external storage when an application is installed [emphasis added].
context.getExternalFilesDirs(null)
in order for the /Android/data/com.example.myapp
folder to be created on the SD card. (At least, on Android 5.1 Lollipop and later. Need to test that on KitKat.)Since one app worked and another didn't, the difference was between the apps, not with the device or card. The directory in question does not require any Android permissions (e.g., WRITE_EXTERNAL_STORAGE
). The only reason why you would not be able to write to it would be if the Android system had not set up the filesystem permissions properly.
I may have created that directory myself, and failed to set up permissions somewhere?
I am not certain that you can create that directory yourself from outside the app and have it work. Ideally that would be fine, but I have not tried it and I can see where that might pose problems.
Is there another reason not to trust it?
Given the filesystem shenanigans that are going on, I get very nervous when developers make assumptions regarding the nature of paths, that's all.