我基本上不能在两周内完成这项工作。
我已经在几个问题上发布了大量代码,但大多数问题都被忽略了,所以我不会用更多我自己的代码来解决这个问题,甚至不会被阅读。
如何使用String?
使用“LIKE”属性搜索MediaStoreE.G。我输入Shoot To Thrill,我收到了这段代码的歌曲ID:
if(cursor.moveToFirst()){
while(cursor.moveToNext()){
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
test.setText(title +" " + artist + " " + id);
}
}
以下是开始的事情:
String[] projection = {
BaseColumns._ID,
MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.Media.TITLE
}
Cursor cursor = this.managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, //uri
projection, //projection
//i dont know what to enter,
//i dont know what to enter,
MediaStore.Audio.Media.TITLE);
答案 0 :(得分:3)
这只是隐藏在幕后的普通SQL。正常的LIKE操作应该可以正常工作。您可以像使用任何其他SQL查询一样使用MediaStore.Audio.Media.TITLE + " LIKE \"%thrill%\""
。
String[] projection = { BaseColumns._ID,
MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Media.TITLE };
String where = MediaStore.Audio.Media.TITLE + " LIKE ?";
String[] params = new String[] { "%life%" };
Cursor q = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection, where, params, MediaStore.Audio.Media.TITLE);
try {
while (q.moveToNext()) {
Log.e("song", q.getString(1) + " " + q.getString(2));
}
} finally {
q.close();
}