Search code examples
androidandroid-contentresolver

Filter contentresolver query by date and time - Android


I'm using the "MediaStore.Images.Media.EXTERNAL_CONTENT_URI" to query for photos stored on the sd-card. Now I only want photos that were added after some specific date. I'm using the "contentResolver.query()" method to query but I don't understand how to filter by Date_ADDED or DATE_MODIFIED. Can this be done?

Thanks for help!


Solution

  • You should be able to do something like this:

    Date date = ...;
    contentResolver.query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
            null, MediaStore.MediaColumns.DATE_ADDED + ">?", 
            new String[]{"" + date},
            MediaStore.MediaColumns.DATE_ADDED + " DESC");
    

    That will find all images with DATE_ADDED after the specified date, sorted by DATE_ADDED from most recent to oldest.