2010-02-16 58 views
0

如何從MediaStore獲取專輯封面?我嘗試這樣的:我如何從MediaStore獲取專輯封面?

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"); 
} 

但沒有工作..我只檢索每個條目爲空!

謝謝!

+1

對您有幫助,在以下所有對我的作品? – Steve

回答

1

它迭代了在目錄中看到的條目數量還是數字不匹配?

的,在格蘭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()); 
1

搜索圖像時,試試這一個

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)); 

     }   
+0

你如何獲得albumid? –

+0

album_id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID))。這會給你光標指向的當前項目的albumId。希望這有助於:) – maximus

+0

我怎樣才能使用它作爲一個位圖? –