问题
I have retrieved some cover art for an album (I have the id and a Bitmap) and now I want to set it into the MediaStore.
I tried a bunch of stuff:
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);
}
}
This gives java.lang.UnsupportedOperationException: Invalid URI content://media/external/audio/albumart/5
Also I tried:
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);
But this gives FileNotFoundException.
来源:https://stackoverflow.com/questions/3450076/android-set-album-thumbnail