Fetch all Images from Android Photo Gallery

后端 未结 2 792
Happy的楠姐
Happy的楠姐 2021-01-07 12:13

I want to fetch all images in my application from android photo gallery .because I want to load an image into my application again after saving it into android gallery . For

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-07 13:18

    I used this code and got image, maybe it works for you

    final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
    final String orderBy = MediaStore.Images.Media._ID;
    imagecursor = getActivity().managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
    
    int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
    
    this.count = imagecursor.getCount();
    this.arrPath = new String[this.count];
    ids = new int[count];
    for (int i = 0; i < this.count; i++) {
            imagecursor.moveToPosition(i);
            ids[i] = imagecursor.getInt(image_column_index);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            arrPath[i] = imagecursor.getString(dataColumnIndex);
        }
    

    You can find adapter code gridview and setadapter from below URL source code for adapter and gridview

提交回复
热议问题