Android's 10 and 11 Scoped Storage
In Android 10 and 11, Google introduced the concept of Scoped Storage, which gives better protection to the app and user data on external storage. Let's review!
Join the DZone community and get the full member experience.Join For Free
What Is Scoped Storage?
Working with the file system is an important part of developing any Android app. As discussed below, with Android 10, when you gave an app storage permission, it could access any file on the device.
In Android 10 and 11(API level 29/30), Google introduced the concept of Scoped Storage, which enhances the platform, giving better protection to the app and user data on external storage. Apps that run on Android 11 but target Android 10 (API level 29) can still request the
requestLegacyExternalStorage attribute. After updating in Android 11 (API level 30), the system ignores the
- MediaStore will need either one of two permissions which are the Read_External_Storage and Write_External_Storage permissions, you should request these permissions in the app Manifest.xml file.
- If you target Android 10 or higher, set the value of
truein your app's manifest file.
- If your app target Android 10 or higher, set the value of
truein your app's manifest file for capturing an image from the camera:
Now, I’m going to explain scoped storage using the example of a captured image from the Gallery.
Pick image: Download Folder:
Pick image: Google Drive:
| getDriveFilePath(context, uri)
Pick image: Recent Folder/MediaDocument:
Pick image: MediaStore (and general):
Pick image: External Storage:
Here is all the providers for storage:
Here is the final code for pickup image from any location:
If you have any questions or feedback regarding this post, please comment or reach out. Thanks. Happy coding!
Published at DZone with permission of Nishi Thakkar. See the original article here.
Opinions expressed by DZone contributors are their own.