Hyndrix Hyndrix - 4 months ago 69
Android Question

Android: Intent.EXTRA_ALLOW_MULTIPLE allows only single picking

I want to open multiple images from the Android gallery using "Intent.EXTRA_ALLOW_MULTIPLE" intent filter:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, "Add images"), SELECT_MULTIPLE_IMAGES);
}


But whatever app I use (native gallery, QuickPic app), I can only select one single picture. The test device is running Android 5.1.

How can I pick multiple images?

Answer

This is currently working in one of my recent live application which covers selection of images using Gallary for 4.4 and above and below that using writing your own custom gallery.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    try {
                        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"), SELECT_IMAGE_REQUEST_GALLERY);
                    }catch(Exception e){
                        Intent photoPickerIntent = new Intent(this, XYZ.class);
                        startActivityForResult(photoPickerIntent, SELECT_IMAGE_REQUEST);
                    }
                }
    else{
      Intent photoPickerIntent = new Intent(this, XYZ.class);
                        startActivityForResult(photoPickerIntent, SELECT_IMAGE_REQUEST);
    }
Comments