How To List Images On Sd Card Sorted According To Time
I can get the list of images in sd card using fololowing` but these are not sorted how can I get them sorted either by name or time thanks in advance String ExternalStorageDirect
Solution 1:
Maybe it will be easier if you use the built-in content provider
MediaStore.Images.Media.query(cr, uri, projection, where, orderBy)
something like this:
String[] projection = {MediaColumns._ID, MediaColumns.DISPLAY_NAME, MediaColumns.DATE_ADDED};
Cursorc= MediaStore.Images.Media.query(getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, MediaColumns.DATE_ADDED);
then you can loop the cursor to do whatever you need.
Solution 2:
- Use lastModified()
method of File to get the time the file was modified.
- Store them in Collection
like ArrayList<File>
.
- Use java.util.Comparator<T>
to compare and sort them according to time and name.
Post a Comment for "How To List Images On Sd Card Sorted According To Time"