I am Accessing media files using cursor in a array. But i need to print the array i descending order (Meaning Latest Media File in System First)
Cursor cursor = getApplicationContext()
.getContentResolver()
.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, " DESC");
I Have Tried this but it does not work and application crashes.
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);
}