该应用程序提供了使用以下方法更改专辑的专辑画面的功能:
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);
它在所有Android版本上都能完美工作,直到API29。在SDKAPI29上,它在下面的代码行中抛出一个NullPointerException:
final int updatedCount = resolver.update(
idAlbumArtUdi,
values,
selection,
selectionArgs);
我知道Android Q和专辑中的图片有一些变化,应该使用ContentResolver.loadThumbnail方法加载。但我想要更改专辑画面,但没有找到任何方法。请帮帮忙。
提前谢谢。
发布于 2020-10-19 02:52:12
content://media/external/audio/albumart的东西可以正常工作,但它确实是一个肮脏的黑客攻击。
也许google只是不想让你从最底层改变它,所以他们弃用了这一列,并禁止我们访问相应的DB部分。
我认为改变嵌入的专辑封面将是要做的事情(但令人讨厌)
https://stackoverflow.com/questions/58889676
复制相似问题