Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 694
LittleFunny Avatar asked May 10 '11 13:05

LittleFunny


2 Answers

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);
like image 177
hoot Avatar answered Oct 19 '22 22:10

hoot


You can limit the result using the sortOrder parameter in query method. Something like this

ContentResolver contentResolver = getContentResolver();
Cursor androidCursor = null;
String sortOrder = String.format("%s limit 100",BaseColumns._ID);
androidCursor = contentResolver.query(IMAGE_URI,PROJECTION, null, null, sortOrder);

This will order the result set by id and limit the result.

like image 43
Mojo Risin Avatar answered Oct 19 '22 22:10

Mojo Risin