java游标。moveToFirst永远不会返回true
我正在尝试搜索MediaStore,但到目前为止,我还没有成功
以下是我当前的代码:
Cursor cursor = this.managedQuery(uri,
null,
MediaStore.Audio.Media.TITLE + "=?",
new String[]{songToPlay},
MediaStore.Audio.Media.TITLE + " ASC");
if(cursor.moveToFirst()){
do{ String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
test.setText(path);
}
while (cursor.moveToNext());
}
songToPlay、uri都已正确设置
if语句永远不会执行
这是什么原因造成的
# 1 楼答案
这可能意味着the cursor is empty。试试^{} ,然后仔细检查你的查询是否正确。您确定媒体商店已被填充吗?你有权限访问它吗
顺便说一句,看起来您正在构建搜索功能。如果这是真的,请确保使用LIKE运算符,或者更好的是使用use full text search