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.
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.
-
+1, I already found the source of my problem; of course it wasn't related to this. Thanks! – Jeff Axelrod Aug 13 '12 at 21:22
-
40-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. – Chris Stratton May 7 '14 at 20:09
-
First time I have seen a comment have more use than the post. @ChrisStratton is 100% correct. – Mike Purcell Oct 6 '16 at 15:30
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'
-
3Why 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 Oct 6 '16 at 15:29
BitmapFactory.decodeStream()
onFileInputStream
– Shaiful Aug 13 '12 at 21:15