android - 在 Android 11 (R) 上获取专辑封面

标签 android android-mediaplayer android-music-player

在 Android R 上更新后,我的应用程序无法加载专辑封面。
以下代码适用于 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);

下面的代码也适用于 Android P 及更早版本

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);
    }
}

问题是文档中没有关于提取专辑封面的信息。 更新文件存储访问策略后,这不起作用。

最佳答案

似乎它已被弃用。看there

关于android - 在 Android 11 (R) 上获取专辑封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63844472/

相关文章:

android - 以编程方式访问库中的音乐文件 (Android)

java - 从 SD 卡中选择文件并通过 HTTP Post 发送

android - Google Play 警告 : Your app contains a Cross-App Scripting Vulnerability

Android:在recyclerview中使用mediaplayer

Android:尝试使用输入播放列表从我的应用启动音乐播放器

java - 如何在Onitemclicklistener函数接口(interface)上实现多个按钮?

android - 带有BottomSheet的windowSoftInputMode不起作用

android - 丢失了我的 keystore ,其中只有 SHA1

android - 如何从android URI获取绝对音频路径

android - 调用 stopForeground 导致重启当前服务