I would like to let the user select some images from the phone's gallery and then load them into the application. That seems to be a straightforward task with Intent.ACTION_PICK and startActivityForResult(intent, SELECT_PHOTO).
However, I am required to filter the results in the gallery by date range. I need to set an initial date and an end date and only photos taken between these two dates should be shown (or be selectable). Does anybody know how to achieve this? I cannot seem to filter the gallery results anyhow.
Thank you!
I too came across the task, after a try of few hours finally solved it :). You need to use Media store and query it passing from date and to date as long, which returns an array of bitmap Below is the code that worked for me.
final String[] columns = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.DATE_ADDED };
final String orderBy = MediaStore.Images.Media._ID;
Cursor imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
MediaStore.Images.Media.DATE_TAKEN + ">? and "
+ MediaStore.Images.Media.DATE_TAKEN + "<?",
new String[] { "" + from, "" + to }, orderBy + " DESC");
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
this.count = imagecursor.getCount();
Log.w("", "count is :" + count);
this.thumbnails = new Bitmap[this.count];
for (int i = 0; i < this.count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(ctx
.getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
}
imagecursor.close();