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?

Templerschaf
  • 142
  • 1
  • 8
  • 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. – Chris Stratton Oct 29 '14 at 16:31

1 Answers1

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!

berwyn
  • 986
  • 7
  • 23
  • 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. – Templerschaf Oct 31 '14 at 12:29