Getting Album cover on Android 11 (R)

Viewed 689

After updating on Android R, my app can't loading albums' art.
Code below working on Android Q

Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumId);
Size size = new Size(700, 700);

return contentResolver.loadThumbnail(uri, size, null);

And also code below working on Android P and earlier

private Bitmap getAlbumArt(int albumId) {
    try (Cursor cursor = contentResolver.query(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Audio.AlbumColumns.ALBUM_ART},
            _ID + "=?",
            new String[]{String.valueOf(albumId)},
            null)) {

        if (cursor == null || !cursor.moveToFirst()) {
            return null;
        }
        String artLink = cursor.getString(0);
        return BitmapFactory.decodeFile(artLink);
    }
}

The problem is that there is no information in documentation about extracting album art. After updates file storage access policy this is not working.

1 Answers
Related