Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating an entry on MediaStore does not work on Android Q / API29

I am trying (without luck) to update entries for MediaStore for both audio tracks and images. I am using something like this:

ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Media.TITLE, title);
values.put(MediaStore.Audio.Media.YEAR, year);

resolver.update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Media._ID + "= ?", new String[] { String.valueOf(id) })

The above snippet works on API16->API28 without problems.

Though, on API29 it does not work. No errors are displayed on logs or messages. I am trying the above code on the API29 emulator. I am not sure if this issue is related to using an emulator or not.

I would really appreciate any information that points me in the right direction.

like image 998
Sami Avatar asked Nov 07 '22 16:11

Sami


1 Answers

https://stackoverflow.com/a/60152702/786656 worked for me.

You need to call update once with the flag IS_PENDING set to 1. Then you call update again with the modified values you want and the flag IS_PENDING set to 0.

like image 134
Thibault Avatar answered Nov 14 '22 23:11

Thibault