如何将照片限制在前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();
提前谢谢
答案 0 :(得分: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个。