简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM