Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

EXTRA_ALLOW_MULTIPLE is a request, not a command, as with any Intent extras. There is no requirement that the activity you are starting honor them. – CommonsWare Jun 23, 2015 at 12:13 Do you know by chance an gallery app which supports multi-image picking using the EXTRA_ALLOW_MULTIPLE parameter? – Hyndrix Jun 23, 2015 at 14:29 Adding EXTRA_ALLOW_MULTIPLE works for me and allows me to select multiple images, however I have no idea how to get the Urls in onActivityResult. – Tom Kincaid Aug 26, 2015 at 19:46

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);
                What app are you (for instance) using to pick the images? I have tried QuickPic and the Samsung Gallery app but both seem only to support single picking. Your code looks very similar to mine.
– Hyndrix
                Jun 23, 2015 at 14:27
                YES using the System Gallery application recently published this app.play.google.com/store/apps/…
– strike
                Jun 23, 2015 at 16:46
 * Extra used to indicate that an intent can allow the user to select and
 * return multiple items. This is a boolean extra; the default is false. If
 * true, an implementation is allowed to present the user with a UI where
 * they can pick multiple items that are all returned to the caller. When
 * this happens, they should be returned as the {@link #getClipData()} part
 * of the result Intent.
 * @see #ACTION_GET_CONTENT
 * @see #ACTION_OPEN_DOCUMENT
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data.getData() != null) {
            try {
                files.clear();
                Uri uri = data.getData();
                String url = FileUtils2.getPath(this, uri);
                assert url != null;
                File file = new File(url);
                files.add(file);
                mPresenter.postAnnexData(files);
            } catch (Exception e) {
                e.printStackTrace();
        } else {
            //If uploaded with the new Android Photos gallery
            ClipData clipData = data.getClipData();
            files.clear();
            if (clipData != null) {
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    Uri uri = item.getUri();
                    String url = FileUtils2.getPath(this, uri);
                    assert url != null;
                    File file = new File(url);
                    files.add(file);
            mPresenter.postAnnexData(files);
                when I pick 2 or 3 images I can read only the first one because data.getData is always not a null
– shurrok
                May 24, 2019 at 11:54

Instead of

startActivityForResult(Intent.createChooser(intent, "Add images"), SELECT_MULTIPLE_IMAGES);
startActivityForResult(intent, SELECT_MULTIPLE_IMAGES); (Deprecated)
someActivityResultLauncher.launch(intent);

Avoid Using

Intent.createChooser
                Thanks for the link. There are plenty of other custom solutions out there as well. But I want to use the EXTRA_ALLOW_MULTIPLE.
– Hyndrix
                Jun 23, 2015 at 14:29
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.