Do I have to declare both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE?

30,544

Solution 1

READ_EXTERNAL_STORAGE only exists as of Jelly Bean (Level 16). According to the docs, all applications as of Jelly Bean have that permission, even without declaring it:

Provides protected read access to external storage. In Android 4.1 by default all applications still have read access. This will be changed in a future release to require that applications explicitly request read access using this permission. If your application already requests write access, it will automatically get read access as well. There is a new developer option to turn on read access restriction, for developers to test their applications against how Android will behave in the future.

So, you should declare it for future compatibility, but this might not be the source of your problem, unless you're using a Jelly Bean phone and set the developer option "Protect USB storage" option.

Solution 2

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'
Share:
30,544
Jeff Axelrod
Author by

Jeff Axelrod

I'm an independent Android developer currently working on an educational application. It's important to me to continuously improve development techniques so I can maximize the "ilities" of software I write (reliability, maintainability, testability, understandability, etc.) Here's a mind map of tools and technologies I am presently using or investigating. You can click on hyperinks to bring you to related sites. I'm particularly interested in using Model-Driven Software Development to keep my architecture consistent and well documented. I am not yet using Scala on Android for anything other than testing, but plan to eventually migrate to Scala for the application code. Some of my favorite books: Effective Java (Bloch) Programming in Scala (Ordesky) Refactoring - Improving the Design of Existing Code (Fowler et al) Some favorite tools: Eclipse Guice + RoboGuice for dependency injection, though plan to replace this soon as startup is much too slow on Android OrmLite (ORM that works well on Android) Robotium for Android integration testing Eclispe EMF for MDSD Powermock + Mockito for mocking I learned a lot from Software Engineering Radio in its heyday.

Updated on November 18, 2020

Comments

  • Jeff Axelrod
    Jeff Axelrod over 3 years

    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.

  • Jeff Axelrod
    Jeff Axelrod almost 12 years
    +1, I already found the source of my problem; of course it wasn't related to this. Thanks!
  • Chris Stratton
    Chris Stratton about 10 years
    -1 This is not an answer to the question actually asked. The documentation clearly states that the write permission implicitly brings the read permission as well. So there is no need to declare this to "future proof" apps which write; is is only needed for apps which desire read-only access.
  • Mike Purcell
    Mike Purcell over 7 years
    Why would it be best to declare both? As of Marsh, you have to request run-time perms, and having to do it for both read and write makes no sense, especially when write gives read implicitly.
  • Mike Purcell
    Mike Purcell over 7 years
    First time I have seen a comment have more use than the post. @ChrisStratton is 100% correct.