I'm in the process of updating an Android app to scoped storage and the problem I'm facing now is that on my app users can select a set of images to be processed automatically (and they can choose to overwrite the original image).
The problem is, when I'm trying to overwrite the original image from its Uri, Android throws a RecoverableSecurityException
, which displays a dialog to the user asking consent to modify that photo.
What I want to know is if it's possible to instead show a permission dialog but for the whole set of, for example, 10 images at once, instead of having to show a dialog for each one.
I tried using the applyBatch
method of ContentResolver
(the code below simulates the issue), but the consent dialog only shows for the first updated image.
val values = ContentValues().apply {
put(MediaStore.Images.Media.DATE_MODIFIED, System.currentTimeMillis())
}
val ops = arrayListOf<ContentProviderOperation>()
for (image in galleryImages) {
ops.add(ContentProviderOperation.newUpdate(image.uri)
.withValues(values)
.build())
}
context.contentResolver.applyBatch(MediaStore.AUTHORITY, ops)
Any ideas on this? Thank you.