Receive multiple Images from gallery in the onActivityResult method
Asked Answered
A

2

5

I am trying to get multiple images from gallery in my app's onActivity Result method but I am not able to create a cursor for the same . And if I do not use cursor than I am unable to get the Uris of all the images. If I have 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 anybody help me with this.

Astraea answered 25/4, 2014 at 10:6 Comment(0)
R
8

Gallery doesn't seem to allow multiple items, but other apps that may respond to the chooser intent can (e.g. Photos on my Samsung Galaxy tablet). You can get the multiple Uris by using getClipData(), something like:

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...
}

Note you might also get a response as data.getData(), as in your question, so it's necessary to check both...

Rafa answered 10/4, 2015 at 4:0 Comment(0)
L
0

I am not sure the SDK allows you to use an intent to select multiple images. You may have to develop your own Image Picker.

You can explore this github repo and see how it works: https://github.com/luminousman/MultipleImagePick

Lenni answered 25/4, 2014 at 10:12 Comment(2)
are you sure that we cant select multiple images from the vanilla gallery?Astraea
I am not hundred percent sure, but I never heard of it. Have a look at the doc.Lenni

© 2022 - 2024 — McMap. All rights reserved.