java.lang.UnsupportedOperationException Albums cannot be directly modified
Asked Answered
B

0

1

How to update album metadata of audio file in Android Q media store?

I tried the answer suggested, https://mcmap.net/q/1408208/-how-to-update-metadata-of-audio-file-in-android-q-media-store, it worked. But this works for individual tracks.

If I use the same logic and form the uri for albums,

val uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
albumId)

and try to edit. I get this exception.
java.lang.UnsupportedOperationException Albums cannot be directly modified

This is the closest link that I could find for the error. https://android.googlesource.com/platform/packages/providers/MediaProvider/+/refs/heads/master/src/com/android/providers/media/MediaProvider.java

Searching for the above exception I found that, for the above uri [album type uri] , other than TYPE_QUERY, i.e TYPE_UPDATE, TYPE_DELETE is not allowed and the exception gets thrown.

So how do I update album metadata in Android Q ? (OR) Is this the expected behaviour going forward from Android Q, that editing metadata of album, artist would not be allowed ?

Bight answered 9/6, 2020 at 8:14 Comment(3)
OK, I just remembered something I read a while ago. You cannot change album data directly. You modify the data for the tracks belonging to an album using projection MediaStore.Audio.Media.ALBUM_ID + "= ?" and album id as selection. This works fine with pre Q. Though, on Q it does not support that approach. So, the only way I think of is to modify each track individually until you modified them all. If you find a solution where you could modify them in batch, let me know. Regards.Madrigalist
@JohnAnderson, The one you had suggested is what I had one as well. Even I read same somewhere and based on the link I shared above, editing album as a whole is not supported in from Android Q. Thanks.Bight
You are welcome. I believe renaming the album directly is not even supported on earlier versions. If I remember right, I have tried that in the past and failed. So, I resorted to tracks renaming.Madrigalist

© 2022 - 2024 — McMap. All rights reserved.