2011-07-01 62 views
1

如何將照片限制在最高50?我還會在這裏得到最近的記錄嗎?android - 光標限制照片

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

照片不得不被視爲「前50名」的標準是什麼? –

回答

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最近。