我正在尝试在Android Media存储中查询音频文件,并按文件路径对结果进行排序。我该怎么做?
我的代码是:
mQueryHandler = new AsyncQueryHandler(getContentResolver(), this);
mQueryHandler.startQuery(
-1,
null,
Media.EXTERNAL_CONTENT_URI,
AudioFilesQuery.PROJECTION,
null,
null,
AudioFilesQuery.SORT_ORDER);
AudioFilesQuery看起来像这样:
private interface AudioFilesQuery {
// if i delete Media.EXTERNAL_CONTENT_URI.toString(), it works.
String[] PROJECTION = {
Media._ID, Media.TITLE, Media.ALBUM, Media.ARTIST
};
int TITLE = 1;
int ALBUM = 2;
int ARTIST = 3;
// This is wrong, because it sorts by the path, that includes the filename.
String SORT_ORDER = Media.DATA + " ASC";
}
或者使用SQL查询这是不可能/无效的?我应该更好地获取整个数据库,并在JAVA中手动排序吗?