我使用游标返回基于媒体的Listview的项目。我只想返回特定文件夹中的项目。
这适用于我的歌曲列表,因为此光标基于MediaStore.Audio.Media.DATA,我可以检查光标中的文件夹:
final String folder = "'" + (new MyPrefs(this.PREF_PATH)).getString("music_folder",null) + "%'";
audioCursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols,
MediaStore.Audio.Media.DATA + " LIKE " + folder, null,MediaColumns.TITLE + " COLLATE LOCALIZED ASC");
startManagingCursor(audioCursor);
但是,在我的艺术家列表视图中,数据结果无法检查:
audioCursor = getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, cols,
null, null,AudioColumns.ARTIST + " COLLATE LOCALIZED ASC");
startManagingCursor(audioCursor);
任何人都可以与我分享一个查询MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI的好方法,只返回我的特定文件夹吗?我需要使用Artist URI,因为我使用的是NUMBER_OF_TRACKS列,这在常规媒体URI中不可用。
答案 0 :(得分:4)
您可以在选择中填写您想要的任何内容,例如此子选项 - 这应该可以解决您的问题:
// The folder needs to end with the % wildcard or stuff doesn't work properly.
String folder = "/mnt/sdcard/Music/Some Folder/";
folder = folder + "%";
String where = Artists._ID + " IN (SELECT " + Media.ARTIST_ID + " FROM audio WHERE " +
Media.DATA + " LIKE ?)";
String[] whereArgs = new String[]{folder};
audioCursor = getContentResolver().query(MediaStore.Audio.Artist.EXTERNAL_CONTENT_URI,
cols, where, whereArgs, AudioColumns.ARTIST + " COLLATE LOCALIZED ASC");