I had to implement a functionality to save a local file on the download folder recently. This challenge came with some questions that I don't have found the answers yet.
What is the difference between MANAGE_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE with READ_EXTERNAL_STORAGE ?
Here is the description of google for MANAGE_EXTERNAL_STORAGE
Google Play restricts the use of high risk or sensitive permissions, including a special app access called All files access. This is only applicable to apps that target Android 11 (API level 30) and declare the MANAGE_EXTERNAL_STORAGE permission...
And the definition of WRITE_EXTERNAL_STORAGE
Allows an application to write to external storage. Starting in API level 19, this permission is not required to read/write files in your application-specific directories...
So, what's the difference? When should I use each one? Why Google need 3 permissions to handle external storage? What should I ask to save a file on Downloads folder?
MANAGE_EXTERNAL_STORAGE:
WRITE_EXTERNAL_STORAGE:
android:requestLegacyExternalStorage="true"), allows for write access to all of what the SDK refers to as external storageWhy Google need 3 permissions to handle external storage?
Because things have changed over time. Approaches that were deemed appropriate for Android 2.x (WRITE_EXTERNAL_STORAGE having complete write access to external storage) have had problems.
What should I ask to save a file on Downloads folder?
Most likely, the answer is "do not write to Downloads/". Bear in mind that you do not have read access to Downloads/ on Android 11+ to files that your app did not create. This means that if you try to write a file there, and there is already a file by that name created by something else, you fail with an error — you do not have the ability to overwrite files created by other apps.
Generally, the better answer is to use ACTION_CREATE_DOCUMENT / ActivityResultContracts.CreateDocument and allow the user to tell you where on the user's local or cloud storage where the user would like you to put this content.
However, if you insist on using Downloads/, WRITE_EXTERNAL_STORAGE should be sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With