給你:
{
int genreId = 2; // << Set Your Genre ID Here
Uri uri = MediaStore.Audio.Albums.getContentUri("external");
Log.i("XXX", "uri = " + uri.toString());
Cursor cursor = null;
try {
String selection = "album_info._id IN "
+ "(SELECT (audio_meta.album_id) album_id FROM audio_meta, audio_genres_map "
+ "WHERE audio_genres_map.audio_id=audio_meta._id AND audio_genres_map.genre_id=?)";
String[] selectionArgs = new String[] { String.valueOf(genreId) };
String[] proj = { AlbumColumns.ALBUM };
cursor = getContentResolver().query(uri, proj, selection,
selectionArgs, null);
if (null != cursor) {
Log.i("XXX", "cursor rows count = " + cursor.getCount());
while (cursor.moveToNext()) {
Log.i("XXX", " Album: " + cursor.getString(0));
}
cursor.close();
Log.i("XXX", "cursor closed");
}
} catch (Exception ex) {
Log.e("XXX", "Error Querying Database");
} finally {
if (cursor != null) {
cursor.close();
}
}
}
編輯
查詢固定指定類型ID
謝謝,RA獲得的所有專輯。我很好奇你是如何得到答案的。你剛熟悉'MediaStore'和SQL嗎?你看過任何文檔嗎? – adneal
這是我與mediastore的第一筆交易,怎麼樣?看看http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/providers/media/MediaProvider.java,其餘的很容易。 –
啊,好吧,我明白了。再次感謝。 – adneal