Reputation: 81
There are many questions about this topic, but I cannot find any answers for my corrective example.
I'm using Samsung galaxy S5 run android 4.4, which is limited for storage
The official document said:
The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled.
My application need to write files to Sdcard (Absolute path is /storage/extSdCard
), so I write my app data to my app directory: /storage/extSdCard/Android/com.myapp.example/files
but got permission denied exception. So I suspect the above statement:
except in their package-specific directories as allowed by synthesized permissions
I think I cannot write to root directory /storage/extSdCard
but still able to write my app data to my app package directory. Did I misunderstand something here?
p/s: I still able to write my app data to built-in storage: /storage/emulated/0/Android/data/com.myapp.example/files
. I don't want to use getExternalFileDirs()
because it always return built-in, not my sdcard directory.
Upvotes: 0
Views: 2018
Reputation: 2579
Your app specific directory should be /storage/extSdCard/Android/data/com.myapp.example/files
and not /storage/extSdCard/Android/com.myapp.example/files
Upvotes: 1
Reputation: 310
If getExternalFilesDir(null) is returning somewhere different to /storage/extSdCard/Android/com.myapp.example/files, then I would think that is why it is giving you access permission errors. The only place on the SD card you can write to without permissions is the directory returned by getExternalFilesDir()
Since you say the directory returned by getExternalFilesDir(null) is not acceptable, I would suggest adding the WRITE_EXTERNAL_STORAGE permission to your manifest.
Upvotes: 3