Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to declare both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE?

Is it enough to declare <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> or do I also have to declare <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />? The Javadocs omit this important information.

like image 653
Jeff Axelrod Avatar asked Aug 13 '12 21:08

Jeff Axelrod


People also ask

Do I need Read_external_storage?

READ_EXTERNAL_STORAGE is necessary when you only need to read from external storage. The WRITE_EXTERNAL_STORAGE permission is necessary when your application requires the ability to write directly to external storage. It should be noted that WRITE_EXTERNAL_STORAGE implicitly includes READ_EXTERNAL_STORAGE ...

What does android permission WRITE_EXTERNAL_STORAGE do?

WRITE_EXTERNAL_STORAGE does not give any privileges in Android 11 (API 30), it does nothing at all, therefore in API 11 you need to set the maxSdkVersion to 29. If in Android 10 (API 29) you are also not using requestLegacyExternalStorage then set maxSdkVersion to 28 instead of 29.

What is the use of WRITE_EXTERNAL_STORAGE?

To read and write data to external storage, the app required WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE system permission. These permissions are added to the AndroidManifest.


1 Answers

It's best to be explicit and declare both permissions, but declaring only android.permission.WRITE_EXTERNAL_STORAGE will automatically add android.permission.READ_EXTERNAL_STORAGE to your APK at build time.

You can use the command aapt dump badging on an APK to see that Android considers usage of the write permission to imply that you also want read permission.

Here's some output from aapt for an APK of mine where I declared only WRITE_EXTERNAL_STORAGE in my manifest:

uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE' uses-permission:'android.permission.READ_EXTERNAL_STORAGE' uses-implied-permission:'android.permission.READ_EXTERNAL_STORAGE',   'requested WRITE_EXTERNAL_STORAGE' 
like image 196
Christopher Orr Avatar answered Sep 20 '22 18:09

Christopher Orr