[英]How to setup “where” statement in android content provider query for media store
我可以查询Android MediaStore,但无法设置“ where”语句。 因此,我放弃了尝试获取它的机会,并尝试破解它,但是我的破解也无法正常工作。
我的技巧是在光标的每一行中移动,查看我感兴趣的列的字符串值是否等于我的搜索关键字……我的代码如下。 我想做的是找到专辑(或艺术家,播放列表)中的所有歌曲。
希望对设置“ where”的查询有任何帮助,或者为什么我的字符串比较不起作用...
private void loadList() {
String selection = ((HashMap<String, String>) selectedAlbumData.get(0))
.get("Album").toString();
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.DURATION };
// managed query doesn't need startManagingCursor called on the
Cursor c = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
if (c.getCount() < 1) {
Log.d("AFA", "Cursor query is empty.. :( ...");
} else {
// do stuff with our content...
while (c.moveToNext()) {
HashMap<String, String> temp = new HashMap<String, String>();
if (c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)) == selection) {
//do stuff with this data
}
Log.d("SongChoosing", "C str is: " + c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
}
//debug stuff
c.moveToPosition(5);
Log.d("SongChoosing", "Selection is: " + selection);
Log.d("SongChoosing", "C str is: " + c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
}
}
我在“专辑”列中寻找的字符串值是有效的字符串,它不是null或为空。.我尝试将歌曲的每一行都打印在日志猫上,并且这些字符串看起来等效于肉眼,但我的if语句不是没有工作...
非常感谢任何可以帮助我的人。
您必须对字符串使用equals或equalsIgnoreCase而不是==。
尝试这个
if (c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)).equalsIgnoreCase(selection)) {
//do stuff with this data
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.