Android permission READ_EXTERNAL_STORAGE

Recently I noticed some bug reports about a failing permission for my Android applications regarding read activities on external USB storage. Every try of the application to read items from the USB storage failed with the following error message.

java.lang.RuntimeException: 
Unable to resume activity {de.jml_port.ospfree/de.jml_port.ospfree.OSPActivity}: 
java.lang.SecurityException: External path: /mnt/sdcard/background.png: 
Neither user 14091 nor current process has android.permission.READ_EXTERNAL_STORAGE

To read contents from the USB storage the permission READ_EXTERNAL_STORAGE has been introduced in API level 16 to avoid applications to access the USB storage of your device without any authorization control, which is considered a security issue.

Although the permission is introduced in API level 16 the usage is enforced starting with newest API level 19 (kitkat 4.4). So in earlier releases, this permission won’t affect the behaviour of the applications, meaning that read access to the external USB storage is still granted for all those applications running on Android release 4.3 and older. Also applications which have been granted the WRITE_EXTERNAL_STORAGE permission will have the READ_EXTERNAL_STORAGE granted as well.

Setting developer options to enforce external storage protection

To enforce the system to check the permission also in an earlier release than 4.4 the developer option ‚protect SD card‘ or ‚protect USB storage‘ should be enabled as shown in the figure.

developer option to enforce READ_EXTERNAL_STORAGE

With this option enabled, all applications have to request this permission to gain read access to the USB storage, which is might helful to test your application on earlier releases regarding this permission or to prevent read access to your external storage without explicit permission. You will find this option on devices running release 4.1 and newer, as this is the release where the permission has been first added. In this manner it might happen that applications running on devices with the mentioned releases are not allowed to read from external USB storage, although the usage of the permission is not enforced in that specific release. Actually this was the reason why I was receiving bug reports about this issue, from devices with Android release less than 4.4.

How to grant the necessary permission for your application

To grant permission READ_EXTERNAL_STORAGE (or any other permission) to the application you have to declare it in the AndroidManifest as follows:


Backward compatibility behaviour

Setting the attributes minSdkVersion and targetSdkVersion to 3 or lower in the Android Manifest, will be sufficient as well to gain read access to the USB storage for backward compatibilty purposes.