Sai
Sai

Reputation: 15718

How to pick multiple image from gallery Android

private static final int PICK_FROM_GALLERY = 2;    
    private void fireGallerypick() {
        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_FROM_GALLERY);
    }

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case PICK_FROM_GALLERY:
            if (resultCode == -1) {
                System.out.println("Gallery pick success");
                String[] all_path = data.getStringArrayExtra("all_path"); //But it returns null
                break;
            }
    }
}

I can able to select multiple images and when i done selection. I need the path of all selected files in String[]. thanks in advance.

Upvotes: 1

Views: 844

Answers (1)

Narendra Singh
Narendra Singh

Reputation: 4001

Intent i = new Intent(Action.ACTION_MULTIPLE_PICK);
startActivityForResult(i, 200);

And to get the image-paths in onActivityResult, do like this -

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
       if (requestCode == 200 && resultCode == Activity.RESULT_OK) {

            String[] all_path = data.getStringArrayExtra("all_path");



        for (String string : all_path) {

            String sdcardPath = string;


        }

Note: the EXTRA_ALLOW_MULTIPLE option is only available in Android API 18 and higher.

Upvotes: 1

Related Questions