我希望我的应用程序仅在我在首选项中指定的那些文件夹中扫描音乐文件。这样就不会包含有声读物等其他音乐文件。
目前,我已经编写了这段代码,用于扫描所有音乐文件:
private String[] getTrackList() {
String[] result = null;
String[] projection = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE };
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=" + 0;
cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection, selection, null, MediaStore.Audio.Media.TITLE
+ " ASC");
result = new String[cursor.getCount()];
int position = 0;
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
result[position] = cursor.getString(columnIndex);
position++;
}
return result;
}