Open In App

Scoped Storage in Android

Last Updated : 13 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Working with the file system is an essential element of creating an Android app. Until Android 10, an app could access any file on the device if you granted it storage permission. Most programs, however, do not require access to the whole storage system. They often work on a single file or a small collection of files. This posed a risk to user privacy. Google introduced the notion of scoped storage in Android 10, which improves user control and privacy while reducing the file clutter that uninstalled apps leave behind.

This storage partition is known as scoped storage. The plan was to divide the total storage space into multiple pieces. Access would be granted to a storage block application containing the app’s required information. Furthermore, the system associates storage with the owner’s apps, allowing the system to readily locate data that matches an app. This will also help to remove app-specific data when the app is uninstalled if the user does not want it to. Android 11 (API level 30) improves the platform by providing improved safety for app and user data stored on external storage. This version includes numerous improvements, including raw file path access, batch media edit operations, and an improved UI for the Storage Access Framework.

What Was the Issue With the Previous Storage?

Confined access: Most apps do not require full storage access since their use cases are limited to specific categories of data or assets that they control. A supermarket app or an e-commerce app that requires storage access just to ask the user to submit their profile image is an example of such a use case. Storage access allows an app to view documents as sensitive as your bank statement or personal data. How do you feel about that?

Data organization: Data/files linked to an app were dispersed around Shared Storage. If you need to remove the program and clear all of the associated data, it will be difficult.

Storage for Individuals

This storage is still the same as previously. It is the app’s own private directory (/app/data/Package Name>) to which the app has unrestricted read and write access.

Storage That is shared

This is subdivided further into Media and Download collections. Image, audio, and video files are stored in the Media collection. Non-media files would be handled via download collection.

Geek Tip: Please keep in mind that media location is now considered sensitive data and will not be exposed unless the app has ACCESS MEDIA LOCATION permission. It is not a run-time authorization and must be included in the manifest. However, if the app is heavily reliant on metadata or if it is an enterprise application where the permission can be removed, it is a good idea to double-check this. If you require the exact bytes of saved media, use ‘MediaStore.setRequireOriginal(photoUri).’

Apps may now access particular blocks of memory. 

What if Your Android App is a Backup App, and Needs Access to ALL DATA?

Users on Android 10 attempted to access the directories using the storage access mechanism. This was not the intention of the storage access framework. In addition, the user expressed dissatisfaction with the UX. In Android 11, a new permission is added for such apps. Apps must submit a declaration form to Google Play in order to request authorization. Once the user authorizes broad access, the user will get an unfiltered view of MediaStore that includes non-media files. Your app, however, will not have access to external app directories.

Great Avenues which Scoped Storage is opening To Android

  1. As long as the item is kept in an organized collection, the app will have full access to contribute files (both media and non-media).
  2. The app will have unrestricted access to both internal and external storage for reading and write operations.
  3. Using the ‘READ STORAGE PERMISSION‘ permission, you can access media collections supplied by other apps. The ‘WRITE STORAGE PERMISSION‘ permission will be deprecated in the future version and, if utilized, will function similarly to the ‘READ STORAGE PERMISSION‘ permission.
  4. Storage access framework API can be used to access non-media assets supplied by other apps. There is no requirement for express authorization.

How Does Android inculcates this huge Change?

  1. Scoped storage is the default behavior in Android 10 and 11. However, with Android 10, apps can request old external storage, which is not the case in 11. Furthermore, in Android 10, apps that want greater access attempted to utilize the Storage access framework to pick directories, which was not the original purpose of the storage framework. Special access permission is introduced in Android 11. Once the app has been whitelisted on Google Play, the user can be asked for special permission.
  2. The Media Store in Android 11 has been upgraded. The user may bulk delete/edit media files, which was not possible in Android 10. Furthermore, copying and editing files are available in 11 but are only suggested for one-time modifications and tiny-sized files because transferring files can clog the user’s hard storage.
  3. Android 10 does not allow native libraries or file paths. This is a use case for C and C++ applications. This feature was implemented in Android 11, and it is the sole use case where developers are expected to create new code. Under the hood, the file path API acts as a proxy for the media storage API. As a result, whenever feasible, use the media storage API directly.
  4. The UI for scoped storage permission in Android 10 looked the same as it did in previous Android versions. As a result, it would be difficult for the user to determine whether they are granting access to scoped storage or whole storage.

Conclusion

If your app has files in Shared storage or outside the app directory, you must relocate them to the app directory if you intend to target Android 10 or above. You will lose access to it beginning with Android 10. Scoped storage has arrived to address a long-standing privacy concern. Despite a number of contentious decisions and bad comments, Android 10 is here to stay. Apps must target Android 10 or later start from September 2020, thus unless you are an app that does not utilize storage, it is advised that you begin utilizing scoped storage.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads