I am trying to populate recyclerview from gallery images as instagram imports gallery images while you select images from the list to upload. I want to implement similar type of thing. Any suggestions on how to access the gallery images on phone/memory card and populate the recyclerview. Also please do suggest any way to implement instagram like interface for selecting images to upload.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
you can use Android media store to pick pictures,Videos and Audios
example code for images:
private void imageMediaQuery() {
String[] projection = new String[]{
MediaStore.MediaColumns.DATA,
//MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String BUCKET_GROUP_BY =
"1) GROUP BY 1,(1";
String BUCKET_ORDER_BY = MediaStore.Images.Media.DATE_TAKEN + " DESC";
Cursor cur = this.getContentResolver().query(images,
projection, // Which columns to return
BUCKET_GROUP_BY, // Which rows to return (all rows)
null, // Selection arguments (none)
BUCKET_ORDER_BY // Ordering
);
if(cur!=null){
Log.i("ListingImages", " query count=" + cur.getCount());
}
if (cur!=null&&cur.moveToFirst()) {
String bucket;
String path;
int bucketColumn = cur.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
int pathColumn = cur.getColumnIndex(
MediaStore.MediaColumns.DATA);
do {
bucket = cur.getString(bucketColumn);
path = cur.getString(pathColumn);
} while (cur.moveToNext());
cur.close();
}
}
In the above code you get path for each image and simply use that path in your onBindViewHolder of recyclerview adapter to display images.hope this helps.