I\'ve been updating meta data in the MediaStore through a ContentResolver, but this no longer works with Android Q (API 29). The following code gives me a warning, and the d
OK, with the help of joakimk, I found the problem.
To update an individual piece of content, you need to use a Uri
that points to that individual piece of content:
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DESCRIPTION, text);
Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imgId);
int res = getContentResolver().update(uri, values, null, null);
This form of update()
will throw a RecoverableSecurityException
. You can catch that and raise a system dialog that should give you the permission to successfully update this content.
Basically, the logic that decides whether to throw a RecoverableSecurityException
depends on the Uri
itself having the ID of the content, rather than it being in a WHERE
clause. A side effect of this is that you cannot modify more than one piece of content at a time, though the new Android R APIs for that may help.
I tested this on Android 10 and Android R DP1.