Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open gallery to select multiple image?

I want to open gallery with multiple image selection functionality and i am using following code.

        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"), 1);

It opens gallery app but doesn't let me choose multiple images.

like image 526
Prashant Sharma Avatar asked Aug 30 '16 11:08

Prashant Sharma


People also ask

How do I select multiple photos in gallery?

To grab several at once, you can enter selection mode by long-pressing on one photo, and then tapping on other pictures or on a date. Doing the latter will automatically select all the images taken on a specific day.


1 Answers

This worked for me from api22 to api29.

Intent intent = new Intent();
                intent.setType("image/*");
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 105);

then in activity result overmethod add this code.

if (resultCode == RESULT_OK && requestCode == 105) {
            ClipData clipData = data.getClipData();
            if (clipData != null) {
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    Uri imageUri = clipData.getItemAt(i).getUri();
                    // your code for multiple image selection
                }
            } else {
              Uri uri = data.getData();
                // your codefor single image selection
            }

Note: after you got the gallery screen hold the image little longer. then in top right click "open". it will allow you to select multiple images.

like image 139
Deepak Maurya Avatar answered Oct 13 '22 13:10

Deepak Maurya