Question

When having WRITE_EXTERNAL_STORAGE permission, I'd expect to have right to write all over the filesystem (eg. /sdcard,/storage/emulated/0,/storage/sdcard0,/mnt/sdcard,...)

But because of different internal FS structure, I'm not really able to tell what are allowed folders on target device.

Currently I use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) to get downloads folder, but this is in my opinion not the only folder I'm allowed to use.

So two questions follow:

  1. Is there way to find out what folders I can write wih such permission?
  2. When using DownloadManager, are possible target folders sae as for the first question?
Was it helpful?

Solution

Use Environment.getExternalStorageDirectory() to get available external storage directory.

You will get the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

OTHER TIPS

For android, there's only one external storage, the one it returns via getExternalStorageDirectory(), so you should use that by default.

But, the public mount points usually have a rw permission for user processes, where your app is running, so you can write there as well. Get root permissions and you can write pretty much anywhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top