Reputation: 4124
How can I get the album art from MediaStore? I try something like:
String[] projectionImages = new String[]{MediaStore.Audio.Albums.ALBUM_ART, MediaStore.Audio.Albums.ALBUM_KEY};
Cursor c = contentResolver.query(MediaStore.Audio.Albums.INTERNAL_CONTENT_URI, projectionImages, null, null, null);
if(c != null){
c.moveToFirst();
Log.e(TAG, "am gasit " + c.getString(0) + " " + c.getString(1));
}
else{
Log.e(TAG, "No image");
}
but is not working.. I retrive just null for every entry!
Thank you!
Upvotes: 0
Views: 6725
Reputation: 21499
Does it iterate over the amount of entries you see in the directory or do the numbers not match up?
The following works for me when searching for images in teh MediaStore
if (cursor.moveToFirst()) {
do {
int col = cursor.getColumnIndex(Images.Media.DESCRIPTION);
String description = cursor.getString(col);
if (new Long(item).toString().equals(description)) {
imageId = cursor.getPosition();
int dataColumn = cursor.getColumnIndex(Images.Media.DATA);
filePath = cursor.getString(dataColumn);
return true;
}
} while (cursor.moveToNext());
Upvotes: 1
Reputation: 1873
Try this one
Cursor cursorAlbum = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},MediaStore.Audio.Albums._ID+ "=" + album_id, null, null);
if(cursorAlbum != null && cursorAlbum.moveToFirst())
{
String uri = cursorAlbum.getString(cursorAlbum.getColumnIndex("album_art"));
cursorAlbum.close();
if(uri != null ) image.setImageURI(Uri.parse(uri));
}
Upvotes: 1