简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM