该应用提供了使用以下方法更改专辑封面的功能:
Uri albumArtUri = Uri.parse("content://media/external/audio/albumart");
Uri idAlbumArtUdi = ContentUris.withAppendedId(albumArtUri, albumId);
{
// First set _data to null
ContentValues values = new ContentValues();
values.putNull("_data");
final String selection = "album_id=?";
final String[] selectionArgs = new String[]{String.valueOf(albumId)};
final int updatedCount = resolver.update(
idAlbumArtUdi,
values,
selection,
selectionArgs);
if (updatedCount == 0) {
ContentValues newValues = new ContentValues(values);
newValues.put("album_id", albumId);
Uri uri = resolver.insert(albumArtUri, newValues);
}
}
if (filepath != null) {
// then insert filepath into _data if it's notl null
ContentValues insertionValues = new ContentValues();
insertionValues.put("_data", filepath);
final String selection = "album_id=?";
final String[] selectionArgs = new String[] {String.valueOf(albumId)};
resolver.update(idAlbumArtUdi, insertionValues, selection, selectionArgs);
} else {
// It was a deletion so we don't insert anything here
}
resolver.notifyChange(idAlbumArtUdi, null);
它在 API 29 之前的所有 Android 版本上都能完美运行。 在 SDK API 29 上,它会在这行代码中抛出 NullPointerException:
final int updatedCount = resolver.update(
idAlbumArtUdi,
values,
selection,
selectionArgs);
我知道 Android Q 有变化,专辑封面应该使用 ContentResolver.loadThumbnail 方法加载。但我想更改专辑封面,但没有找到任何方法。请帮忙。
提前致谢。
最佳答案
content://media/external/audio/albumart 东西可以正常工作,但它确实是一个肮脏的 hack。
也许 google 只是不想让您从最底层开始更改它,所以他们弃用了该列并禁止我们访问相应的数据库部分。
我认为改变嵌入的专辑封面是可行的(但很讨厌)
关于android - 在 Android Q 上更改专辑封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58889676/