0

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
  • As atomicrat implies you should not be making assumptions as to what the path of a storage volume is - instead use the appropriate API to determine it at runtime. Oct 29, 2014 at 16:31

1 Answer 1

4

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!

1
  • I found my error, I mistakenly assumed the folder "../com.foo.Example" is the one I can write in and did not realize it is "../com.foo.Example/files". So getExternalFilesDir() returns indeed the correct path, cheers for that. Oct 31, 2014 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.