About Target SDK 30, Storage Permissions, and requestLegacyExternalStorage
About what most application developers see in the Google Play Console:
We’ve detected that your app contains the
requestLegacyExternalStorageflag in the manifest file of 1 or more of your app bundles or APKs.
Developers with apps on devices running Android 11+ must use Scoped Storage to give users better access control over their device storage. To release your app on Android 11 or newer after May 5th, you must either:
- Update your app to use more privacy friendly best practices, such as the Storage Access Framework or Media Store API
- Update your app to declare the All files access (
MANAGE_EXTERNAL_STORAGE) permission in the manifest file, and complete the All files access permission declaration in Play Console from May 5th
- Remove the All files access permission from your app entirely
For apps targeting Android 11, the
requestLegacyExternalStorageflag will be ignored. You must use the All files access permission to retain broad access.
Apps requesting access to the All files access permission without a permitted use will be removed from Google Play, and you won’t be able to publish updates.
Let me briefly summarize the main points:
- It notifies those apps which set
requestLegacyExternalStorage=true, but it didn’t verify those apps go against Scoped Storage.
- After May 5th, for the app with targetSDKVersion of API 30, it must be modified to use Storage Access Framework or Media Store API, declare why they need
MANAGE_EXTERNAL_STORAGE, or remove
WRITE_MEDIA_STORAGE, etc, they will be ignored and apps cannot grant those permissions. If our apps with targetSDKVersion of API 30 still declare
WRITE_EXTERNAL_STORAGE, there is no punishment, just that our apps get no permissions.
There is only one case that app will be removed from Google Play: your app declares
MANAGE_EXTERNAL_STORAGE, but you forget to complete the All files access permission declaration in Play Console
How do our teams prepare before upgrading target SDK 30:
- for those features of creating files or getting images … etc, we refer https://developer.android.com/guide/topics/data and change using Storage Access Framework or Media Store API.
requestLegacyExternalStorage=true. Though it will be ignored for those apps with targetSDKVersion of API 30 running on devices of Android 11, this flag guarantees our apps work as previously behaviors under Android 10.
- Except for file managers, etc, other apps shouldn’t include
MANAGE_EXTERNAL_STORAGE, so remove it.
WRITE_EXTERNAL_STORAGEis also ignored on Android 11, and we prefer keeping
requestLegacyExternalStorage=true, so we modify our permission declaration to
If you prefer removing
requestLegacyExternalStorage or set it to false, just change maxSDKVersion to 28
By the way, if you found your app needn’t
WRITE_EXTERNAL_STORAGE anymore, just more this permission declaration. But if you think it’s troublesome to find a mobile phone to test your apps’ behaviors below API 10, the step 4 is useful.
Explain more in details why I suggest to set
According to Scoped storage unavailable, https://developer.android.com/training/data-storage/shared/media#scoped_storage_unavailable
which points out there are 2 situations that we need to request the WRITE_EXTERNAL_STORAGE or READ_EXTERNAL_STORAGE permission,
- runs Android 9 or lower,
- temporarily opted out of scoped storage (this means
<application android:requestLegacyExternalStorage="true" ... >