如何按降序打印媒体文件

时间:2019-05-16 06:04:39

标签: java android cursor android-mediaplayer android-contentresolver

我正在使用数组中的游标访问媒体文件。但是我需要按降序打印数组(“系统优先”中的“最新媒体文件”)

Cursor cursor = getApplicationContext()
                .getContentResolver()
                .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, " DESC");

我已经尝试过了,但是它不起作用并且应用程序崩溃了。

public ArrayList < String > getAllMedia() {
    HashSet < String > videoItemHashSet = new HashSet < > ();
    String[] projection = {
        MediaStore.Video.VideoColumns.DATA,
        MediaStore.Video.Media.DISPLAY_NAME
    };
    Cursor cursor = getApplicationContext().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, " DESC");
    try {
        Objects.requireNonNull(cursor).moveToFirst();
        do {
            videoItemHashSet.add((cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))));
        } while (cursor.moveToNext());

        cursor.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return new ArrayList < > (videoItemHashSet);
}

0 个答案:

没有答案