Android 16 Photo Picker: Fixing Inaccessible Pre-Selected Media After App Reinstall
Understanding the Android 16 Photo Picker Edge Case
With Android 16 (API 36) continuing to refine user privacy and media permissions, developers relying on Limited Photo Access (READ_MEDIA_VISUAL_USER_SELECTED) may encounter an unexpected behavior after reinstalling their applications. Specifically, photos previously created by an older installation of the app appear pre-selected in the system Photo Picker, yet querying MediaStore after confirming the selection yields no accessible results.
This discrepancy creates an inconsistent UI state where the system dialog signals that access is granted, but security restrictions prevent the reinstalled app from reading the files.
Why Does This Inconsistency Happen?
To understand why this issue occurs, it helps to look at how Android handles app uninstalls and media permission grants:
- Permission Lifecycles: When an app is uninstalled, Android revokes all granted runtime permissions, including
READ_MEDIA_VISUAL_USER_SELECTEDand temporary URI access rights granted by system pickers. - MediaStore Ownership: Files saved to
MediaStoreby an app persist after uninstallation, but the system clears the internal association linking that specific app UID to the created media. - Photo Picker State Caching: The system Photo Picker or
MediaProviderappears to retain historical UI selection metadata based on the package name rather than the active app UID or current permission table. As a result, the UI displays previously selected or created media as checked by default. - Grant Refresh Failure: Tapping OK without toggling the pre-selected image off and on again fails to trigger a fresh URI grant creation for the newly installed app's UID.
How to Handle the Issue in Your App
While this issue resides within the system-level MediaProvider implementation and is expected to be addressed in future maintenance releases of Android 16, developers can protect their apps from crashes or unexpected silent failures using the following strategies.
1. Gracefully Validate URI Access
Never assume a URI returned or implied by a Photo Picker result is readable. Always validate read privileges before executing database queries or trying to open input streams.