问题
I have trouble creating the "com.foo.Example" folder of my app in "/storage/extSdCard/Android/data" from inside the app. If created manually with a file manager there is no trouble, just creating the first one with a simple mkdir returns false. I used the package name declared in the manifest and used throughout and I do have the appropriate WRITE_EXTERNAL_STORAGE-permission in there aswell. Where is this folder suposed to come from, if the app is unable to create it?
回答1:
I'm assuming you're using getExternalFilesDir()
, if not, you'll want to convert to it. getExternalFilesDir()
, when passed null, will create a private directory for your application to write to if it doesn't already exist and return the handle for that.
You'll want to check out this guide, which has all the info you need on how to write to external storage.
As for why you're having this issue on KitKat, Google changed the permission model for external storage to prevent apps from writing to arbitrary folders on the SD card, which provides better security, as well as keeping things better organised. However, the cool part is that getExternalFilesDir()
doesn't even require a permission to use! It's always available to your application.
Hope that helps!
来源:https://stackoverflow.com/questions/26634991/create-package-directory-in-android-data-denied-on-sd-cards-on-android-4-4