我已检索到专辑的一些封面(我有 id 和位图),现在我想将其设置到 MediaStore。
我尝试了一堆东西:
private static final Uri ARTWORK_URI = Uri.parse("content://media/external/audio/albumart");
public static void writeArtwork(Context context, Bitmap bmp, int albumId) {
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(ARTWORK_URI, albumId);
LogUtil.i(TAG, "uri= " + uri);
if (uri != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] bytes = baos.toByteArray();
LogUtil.i(TAG, "Bytes: " + bytes.length);
ContentValues values = new ContentValues();
values.put("album_id", albumId);
values.put("_data", bytes);
res.insert(uri, values);
}
}
这给出了 java.lang.UnsupportedOperationException: Invalid URI content://media/external/audio/albumart/5
我也试过:
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(artworkUri, album.getId());
OutputStream outStream = getContentResolver().openOutputStream(uri);
bmp.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
但这给出了 FileNotFoundException。