Android 14 media permission changes

Allow partial access to photos and videos

Users interacting with your app on Android 14 devices can now grant their visual media library (Photos/ video).

The new dialog contains the following options:

Select photos and videos: New in Android 14. Users select specific photos and videos that they want to make available to your app.

Always Allow All: The user grants full library access to all photos and videos on the device.

Do Not Allow: The user is denied all access.

If the user chooses Select photos and videos, and your application later requests READ_MEDIA_IMAGES or READ_MEDIA-VIDEO again, the system displays a different dialog, giving the user the opportunity to access additional photos and videos.

To help applications support the new changes, the system introduces a new permission READ_MEDIA_VISUAL_USER_SELECTED.

Note: If your application already uses a photo picker, no action is required to support this change. Otherwise, consider using the photo picker instead of this change.

Effects of declaring new permissions

If you declare the READ_MEDIA_VISUAL_USER_SELECTED permission, and the user chooses to select photos and videos in the system permissions dialog, the following behavior occurs:

Both READ_MEDIA_IMAGES and READ_MEDIA-VIDEO permissions are denied.

Grants the READ_MEDIA_VISUAL_USER_SELECTED permission, providing partial and temporary access to user photos and videos.

If your application needs to access other photos and videos, you must again manually request the READ_MEDIA_IMAGES permission or the READ_MEDIA-VIDEO permission (or both).

NOTE: Create a UI element in your application that the user must press before re-requesting READ_MEDIA_IMAGES or READ_MEDIA-VIDEO permissions. Users should not be surprised to see system dialogs again.

Remember that READ_MEDIA_IMAGES and READ_MEDIA-VIDEO are the only other permissions required to access the user's photo and video photo gallery. Declaring READ_MEDIA_VISUAL_USER_SELECTED lets the permission controller know that your application supports manual re-requests to select more photos and videos.

Impact of undeclared new permissions

If the READ_MEDIA_VISUAL_USER_SELECTED permission is not declared, the following behavior will occur:

Grants READ_MEDIA_IMAGES and READ_MEDIA-VIDEO permissions during an application session, providing temporary permission grants and temporary access to user-selected photos and videos. The system eventually denies these permissions when your app moves to the background, or when the user actively closes your app. This behaves like other one-time permissions.

If your application later needs to access other photos and videos, you must manually request the READ_MEDIA_IMAGES permission or the READ_MEDIA-VIDEO permission again. The system follows the same flow as the initial permission request, prompting the user to select photos and videos.

Note: If your application follows permissions best practices, this change will not affect your application. In particular, your application should not assume that URI access is preserved, and you should refresh the displayed image set after a permission change.

Preserve photo and video access when device is upgraded

If your app is installed on a device upgraded to Android 14 from an earlier Android version, the system will maintain full access to user photos and videos and automatically grant some permissions to your app. The exact behavior depends on the set of permissions granted to the app before the device was upgraded to Android 14.

Note: Permission grants may still be denied manually by user, device company policy, or automatic permission resets. Always check permissions instead of assuming a previously granted state.

Permissions for Android 13

Consider the following situation:

Your app is installed on a device running Android 13.

The user has granted your application the READ_MEDIA_IMAGES permission and the READ_MEDIA-VIDEO permission.

Then, while your apps are still installed, the device upgrades to Android 14.

In this case, your application still has full access to the user's photos and videos. The system also automatically preserves the READ_MEDIA_IMAGES and READ_MEDIA-VIDEO permissions granted to the app.

Permissions for Android 12 and lower

Consider the following situation:

Your app is installed on a device running Android 13.

A user has granted your application the READ_EXTERNAL_STORAGE permission or the WRITE_EEXTERNAL_STRAGE permission.

Then, while your apps are still installed, the device upgrades to Android 14.

In this case, your application still has full access to the user's photos and videos. The system also automatically grants the READ_MEDIA_IMAGES permission and READ_MEDIA-VIDEO permission to your application.

Based on changes introduced in Android 14, your app may only have partial access to the device's photo library. If the application is caching MediaStore data when queried using the ContentResolver, the cache may not be up to date.

Always use a ContentResolver to query the MediaStore instead of relying on the store's cache.

Keep the result in memory while the app is in the foreground.

Treat URI access as temporary

If the user selects "Select photos and videos" in the system permissions dialog, your app's access to the selected photos and videos will eventually expire. Your application should always handle the inability to access any Uri, regardless of its permissions.

Guess you like

Origin blog.csdn.net/ziyunLLL/article/details/129495566