Retrieving multiple images from a gallery in the onActivityResult method

I am trying to get multiple images from a gallery in my onActivity Result application, but I cannot create a cursor for the same. And if I do not use the cursor, than I can not get Uris of all the images. If I need to select a single image, the code is pretty simple:

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);

 if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
     Uri selectedImage = data.getData();
     String[] filePathColumn = { MediaStore.Images.Media.DATA };

     Cursor cursor = getContentResolver().query(selectedImage,
             filePathColumn, null, null, null);
     cursor.moveToFirst();

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     String picturePath = cursor.getString(columnIndex);
     cursor.close();

     // String picturePath contains the path of selected Image
     }

Can someone help me with this.

+4
source share
2 answers

, , , , , (, Samsung Galaxy). Uris, getClipData(), - :

ClipData clip = data.getClipData();

for(int i = 0; i < clip.getItemCount(); i++) {
    ClipData.Item item = clip.getItemAt(i);
    Uri uri = item.getUri();

    // Process the uri...
}

, data.getData(), , ...

+6

, SDK . , Image Picker.

github , : https://github.com/luminousman/MultipleImagePick

0

Source: https://habr.com/ru/post/1538038/


All Articles