Search code examples
androidlimitandroid-sdcard

Fetching only first 100 rows of image from mediastore


Is there a way to limit the result retrieved from mediastore using managedQuery function on Android. Since I currently have a grid that displaying all photos found on the sd card but it is too intensive of fetching it so I decide to limit the result retrieved from the media store but could not find a limit function that can reduce the resulting set of data.

Please help


Solution

  • use order in contentresolver's query method to implement your function, such as 'columnname asc limit number'

    in my case:

    cursor = resolver.query(STORAGE_URI, projection,
                            Media.BUCKET_DISPLAY_NAME + "=?",
                            new String[] { folderName },
                            " _id asc limit " + num);