Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pick multiple images from gallery

How to read/retrieve paths or Uri[] when I select multiple images from gallery?

I want to call this:

Uri[] originalUri = data.getData();

But in reality I'm getting this only, fetching only one Uri:

 Uri originalUri = data.getData();
like image 828
VVB Avatar asked Jun 01 '26 21:06

VVB


1 Answers

@RIT as said by you that you want to get multiples images in andorid kitkat .

I have try below code which work for me for Xperia M2 4.4.4

For start image selection activity

private void startImageSelection(){

        Intent intent = new Intent();
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_IMAGES);
    } 

But user need to select images by long press

Now to read selected images Uri use below code for onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub

        if(requestCode==PICK_IMAGES){

            if(resultCode==RESULT_OK){
                //data.getParcelableArrayExtra(name);
                //If Single image selected then it will fetch from Gallery
                if(data.getData()!=null){

                    Uri mImageUri=data.getData();

                }else{
                    if(data.getClipData()!=null){
                        ClipData mClipData=data.getClipData();
                        ArrayList<Uri> mArrayUri=new ArrayList<Uri>();
                        for(int i=0;i<mClipData.getItemCount();i++){

                            ClipData.Item item = mClipData.getItemAt(i);
                            Uri uri = item.getUri();
                            mArrayUri.add(uri);

                        }
                        Log.v("LOG_TAG", "Selected Images"+ mArrayUri.size());
                    }

                }

            }

        }

        super.onActivityResult(requestCode, resultCode, data);
    }
like image 93
Herry Avatar answered Jun 04 '26 17:06

Herry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!