Storage updates in Android11Android11 (API level30) further enhances the platform, giving better protection to app and user data on external storage. This release introduces several enhancements, such as raw file path access, batch edit operations for media, and an updated UI for the Storage Access Framework. Show
The release also offers improvements to scoped storage, which makes it easier for developers to fulfill their storage use cases after they migrate to using this storage model. Scoped storage enforcementApps that run on Android11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android11, the system ignores the requestLegacyExternalStorage flag. Maintain compatibility with Android 10If your app opts out of scoped storage when running on Android 10 devices, it's recommended that you continue to set requestLegacyExternalStorage to true in your app's manifest file. That way, your app can continue to behave as expected on devices that run Android 10. Migrate data to directories that are visible when using scoped storageIf your app uses the legacy storage model and previously targeted Android 10 or lower, you might be storing data in a directory that your app cannot access when the scoped storage model is enabled. Before you target Android11, migrate data to a directory that's compatible with scoped storage. Test scoped storageTo enable scoped storage in your app, regardless of your app's target SDK version and manifest flag values, enable the following app compatibility flags:
To disable scoped storage and use the legacy storage model instead, unset both flags. Manage device storageStarting in Android11, apps that use the scoped storage model can access only their own app-specific cache files. If your app needs to manage device storage, follow the instructions on how to query free space.
App-specific directory on external storageStarting in Android11, apps cannot create their own app-specific directory on external storage. To access the directory that the system provides for your app, call getExternalFilesDirs(). Media file accessTo make it easier to access media while retaining user privacy, Android11 adds the following capabilities. Perform batch operationsFor consistency across devices and added user convenience, Android11 adds several methods that make it easier to manage groups of media files. Access files using direct file paths and native librariesTo help your app work more smoothly with third-party media libraries, Android11 allows you to use APIs other than the MediaStore API to access media files from shared storage using direct file paths. These APIs include the following:
Access to data from other appsTo protect user privacy, on devices that run Android11 or higher, the system further restricts your app's access to other apps' private directories. Access to data directories on internal storageAndroid 9 (API level 28) started to restrict which apps could make the files in their data directories on internal storage world-accessible to other apps. Apps that target Android 9 or higher cannot make the files in their data directories world-accessible. Android11 expands upon this restriction. If your app targets Android11, it cannot access the files in any other app's data directory, even if the other app targets Android 8.1 (API level 27) or lower and has made the files in its data directory world-readable. Access to app-specific directories on external storageOn Android11, apps can no longer access files in any other app's dedicated, app-specific directory within external storage. Document access restrictionsTo give developers time for testing, the following changes related to the Storage Access Framework (SAF) take effect only if your app targets Android11 or higher. Access to directoriesYou can no longer use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:
Access to filesYou can no longer use the ACTION_OPEN_DOCUMENT_TREE or the ACTION_OPEN_DOCUMENT intent action to request that the user select individual files from the following directories:
Test the changeTo test this behavior change, do the following:
PermissionsAndroid11 introduces the following changes related to storage permissions. Target any versionThe following changes take effect in Android11, regardless of your app's target SDK version:
Target Android11If your app targets Android11, both the WRITE_EXTERNAL_STORAGE permission and the WRITE_MEDIA_STORAGE privileged permission no longer provide any additional access. Keep in mind that, on devices that run Android 10 (API level 29) or higher, your app can contribute to well-defined media collections such as MediaStore.Downloads without requesting any storage-related permissions. Learn more about how to request only the necessary permissions when working with media files in your app. All files accessThe majority of apps that require shared storage access can follow the best practices for sharing media files and sharing non-media files. However, some apps have a core use case that requires broad access of files on a device, but cannot do so efficiently using the privacy-friendly storage best practices. Android provides a special app access called All files access for these situations. To learn more, see the guide on how to manage all files on a storage device. Note: If you publish your app to Google Play, carefully read the notice. If you target Android11 and declare All files access, it can affect your ability to publish and update your app on Google Play.Additional resourcesFor more information about changes to storage in Android 11, view the following materials: Blog posts
Videos
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2022-02-09 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
|