I\'m trying to write a photo on the SD card without success.
I\'ve got the permissions to write in the removable storage and the sd card is mounted.
Also
On API Level 18 and below, your getStorageDirectories()
will go through its else
block. That block assumes:
SECONDARY_STORAGE
environment variable exists... which is not requiredSECONDARY_STORAGE
contains a delimited list of directories... which is not requiredOn API Level 19+, your getStorageDirectories()
code will go through its if
block. There, you start off fine, calling getExternalFilesDirs()
. If that method returns 2+ items, the second and subsequent ones point to removable storage, and specifically point to places on removable storage where you can read and write. Then, your code assumes:
/Android
path segment... which is not required/Android
represents a location in which you can create files and directories... which is never trueYou do not have filesystem-level access to removable storage, except in the specific directories returned by methods like getExternalFilesDirs()
.
So, either:
Stick to the specific locations returned by getExternalFilesDirs()
, or
Switch to using the Storage Access Framework, allowing the user to choose where to store content (which may or may not be removable storage)