I am able to access pictures using photo picker without any permissions in the app. Is that allowed without asking for READ_MEDIA_IMAGES permission? I could not find any reference to documentation which clearly states that permission is not required. I would appreciate any help in confirming this is indeed the case.
I was expecting the photo picker to not work at all or throw an exception without READ_MEDIA_IMAGES or READ_MEDIA_VISUAL_USER_SELECTED permissions.
Code:
// Registers a photo picker activity launcher in single-select mode.
val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
// Callback is invoked after the user selects a media item or closes the
// photo picker.
if (uri != null) {
Log.d("PhotoPicker", "Selected URI: $uri")
} else {
Log.d("PhotoPicker", "No media selected")
}
uri?.let {
// Grant read URI permission to access the selected URI
val source = ImageDecoder.createSource(this.contentResolver, uri)
val bitmap = ImageDecoder.decodeBitmap(source)
}
}
pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
Nope. This is one of the benefits of Photo Picker. From the 34 SDK update docs:
[Selected Photos Access] is only enabled if your app targets Android 14 (API level 34) or higher. If you don't use the photo picker yet, we recommend implementing it in your app to provide a consistent experience for selecting images and videos that also enhances user privacy without having to request any storage permissions.
link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With