Skip to content Skip to sidebar Skip to footer

Getting The Recent Images From Gallery From Cursor Using Contentresolver

I'm using Cursor to get the images from gallery and getting all the images from gallery, is there any way to get only few recent images, such as last 20 image captured. One more p

Solution 1:

The order by argument to query(), per documentation, is formatted as a SQL order by statement. If you want the values in descending order as opposed to the default ascending order, do this:

finalStringorderBy= MediaStore.Images.Media._ID + " DESC";

But you specifically asked about using the date as the ordering, so you probably want this instead:

finalStringorderBy= MediaStore.Images.Media.DATE_ADDED + " DESC";

Solution 2:

In addition to Doug's answer, if you only want the 20 most recent with the orderBy, you can do that:

final String orderBy = MediaStore.Images.Media.DATE_ADDED + " DESC LIMIT 20";

Post a Comment for "Getting The Recent Images From Gallery From Cursor Using Contentresolver"