Skip to content Skip to sidebar Skip to footer

Import Gallery Images Which Are Stored In Phone/memory Card Into Recyclerview

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 th

Solution 1:

you can use Android media store to pick pictures,Videos and Audios

example code for images:

privatevoidimageMediaQuery() {
    String[] projection = newString[]{
            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;
    StringBUCKET_GROUP_BY =
            "1) GROUP BY 1,(1";
    StringBUCKET_ORDER_BY = MediaStore.Images.Media.DATE_TAKEN + " DESC";

    Cursor cur = this.getContentResolver().query(images,
            projection, // Which columns to returnBUCKET_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.

Post a Comment for "Import Gallery Images Which Are Stored In Phone/memory Card Into Recyclerview"