如何在特定时间段内访问图像?

时间:2014-07-02 04:01:49

标签: android gallery

让我们说时间段从中午开始到下午2点结束。如何在图库中找到介于这两次之间的图像?

1 个答案:

答案 0 :(得分:1)

String[] projection = {
    MediaStore.Files.FileColumns._ID, 
    MediaStore.Files.FileColumns.DATA,
    MediaStore.Files.FileColumns.DATE_ADDED,
    MediaStore.Files.FileColumns.MEDIA_TYPE,
    MediaStore.Files.FileColumns.MIME_TYPE,
    MediaStore.Files.FileColumns.TITLE
};

// Return only video and image metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
         + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE 
         + " OR "
         + MediaStore.Files.FileColumns.MEDIA_TYPE + "="
         + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;

Uri queryUri = MediaStore.Files.getContentUri("external");

CursorLoader cursorLoader = new CursorLoader(
    this,
    queryUri,
    projection,
    selection,
   MediaStore.Files.FileColumns.DATE_ADDED >= + "HERE START DATE" + "&" + MediaStore.Files.FileColumns.DATE_ADDED <= + "HERE END DATE"  ,
    MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
  );

Cursor cursor = cursorLoader.loadInBackground();