My android application works fine till Android 9 but is failing to show thumbnails for music files in Android 11.
In the logs I'm receiving UnsupportedOperationException: Unknown or unsupported URL error message with the value of thumbnail uri as content://media/external/audio/albumart/-1850834839
& content://media/external/audio/albumart/1937535873
.
Code Pointer :
Glide.with(mContext).load(audioData.getAlbumArtUri()).asBitmap()
.placeholder(R.drawable.ic_tile_music_browse)
.transform(new BlurTransformation(mContext)).into(viewHolder.blurredImage);
Glide.with(mContext).load(audioData.getAlbumArtUri()).into(viewHolder.image);
I checked & found there have been multiple changes introduced between Android 9 & 11. Some of them are :
- Introduction of Scoped Storage from Android 10 : Now App's can't directly access external files without having necessary permissions like
MANAGE_EXTERNAL_STORAGE
mentioned here. Although developers can exempt from this by settingpreserveLegacyExternalStorage
to true in manifest file album_art
has been depreciated from Android 29 & one should useloadThumbnail
api instead- I was using Glide & found there were some issue seen with Glide itself
I tried above resolutions but none of them worked for me.
I finally found the reason for the strange behaviour seen for my application in Android 11.
So, I tried printing the values of music albums stored in the database/MediaStore using
And I found the value of album_id field is too small (like 2,4,18) on Android 9 but while printing same data on android 11 the value was too large & could be stored by a int data type. Hence, the value was getting overflown resulting in negative values of album_id (-1850834839) as mentioned in the question. So, I modified the variable data type from int to long & it resolved the issue for me.