Fetching only first 100 rows of image from mediastore

筅森魡賤 提交于 2019-12-22 07:46:29

问题


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


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/5950420/fetching-only-first-100-rows-of-image-from-mediastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!