1

如何将照片限制在前 50 位?另外,我可以在这里获得最新的记录吗?

final String[] projection = { MediaStore.Images.Media.DATA };
       final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
       final String[] selectionArgs = { CAMERA_IMAGE_BUCKET_ID };
       final Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, 
               projection, 
               selection, 
               selectionArgs, 
               null);
       List<Image> result = new ArrayList<Image>(cursor.getCount());
       if (cursor.moveToFirst()) {
           final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
           do {
               final String data = cursor.getString(dataColumn);
               result.add(new Image(data));
           } while (cursor.moveToNext());
       }
       cursor.close();

先感谢您

4

1 回答 1

1
  String sortOrder = String.format("%s limit 50 ", Images.ImageColumns.DATE_TAKEN + " DESC");

  final Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, 
                projection, 
                selection, 
                selectionArgs, 
                sortOrder);

按最近创建的日期对图像进行排序,并将它们限制为最近的 50 个。

于 2011-07-06T21:05:27.963 回答