Search code examples
androidandroid-intentandroid-imageandroid-galleryonactivityresult

How to create an Intent to open multiple photos without having to first navigate to "Photos"


So I'm trying to get the Uris of multiple images from the photo gallery. It works okay, but when the Intent is started, it directs to the "Open from" window, and I then have to click "Photos" in the bottom left. Then I have the opportunity to hit "Pictures" and make my selections.

It would be much nicer if the user didn't have to know ahead of time to do this sequence of steps. I would love it if there was an Intent that allowed them to just immediately select their images.

I've dug through the Intent API a little, but it seems like everyone uses the Intent.ACTION_GET_CONTENT with the extra Intent.EXTRA_ALLOW_MULTIPLE. I want to know if there's a tweak to this Intent that can bypass those annoying extra steps.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURES);
public void onActivityResult (int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SELECT_PICTURES)
        {
            if (resultCode == Activity.RESULT_OK)
            {
                if (data.getClipData() != null)
                {
                    int count = data.getClipData().getItemCount();

                    for (int i = 0; i < count; i++)
                    {
                        Uri uri = data.getClipData().getItemAt(i).getUri();
                        uriList.add(i, uri);
                    }
                }
            }
        }

        // Some other stuff...
    }

Solution

  • When you create a global intent that said: "I want some image", and there is some app as an option for handle this action, the OS can't make the decision to complete this task with which app.

    this code maybe help you:

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    startActivityForResult(intent, SELECT_PICTURES);