How to make sort gallery thumbnails image by date

大憨熊 提交于 2019-11-30 23:11:05

Update columns and orderBy like this:

  String[] columns = {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.DATE_TAKEN};

  String orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"; 

and see if that helps.

You could also fetch real images instead of thumbnails and use image loading library that will take care of proper re-sizing. In this case replace your Thumbnails references with ImageColumns

this code will save the first 100 thumbs (SORTED by date)

      Cursor cursor = this.getContentResolver().query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                projection, // Which columns to return
                null,       // Return all rows
                null,
                "image_id DESC");

// Get the column index of the Thumbnails Image ID
        int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
        for(int i =0;i<cursor.getCount();i++){
            if (i==100) break;
            cursor.moveToPosition(i);
            mImagesFromGallery[i] = cursor.getString(columnIndex);
        }
        cursor.close();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!