如何从COntentResolver获取媒体标题。我试过但它没用,我想在listView中显示媒体标题。
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
int ind = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
do {
String T = cursor.getString(ind);
abcl.add(T);
Log.i("SOngName", T);
} while (cursor.moveToNext());
}
但是这给了我IndexOutOfBondsExceptions的错误,我的错误logcat是
答案 0 :(得分:0)
首先,你应该去android 中的光标文档。它会告诉你使用游标后不是null检查;你必须将光标移动到传入结果集的第一行的开头。
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
if(cursor.MoveToFirst()){
int ind = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
do {
String T = cursor.getString(ind);
abcl.add(T);
Log.i("SOngName", T);
} while (cursor.moveToNext());
}
}