1
 Intent intent = new Intent(Intent.ACTION_PICK);
                            intent.setType("*/*");
                            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                            intent.setAction(Intent.ACTION_GET_CONTENT);
                            startActivityForResult(intent, READ_REQUEST_CODE);

On activity result, I keep getting only one file selected. despite i selected multiple files. why ?

List<Uri> files = Utils.getSelectedFilesFromResult(resultData);
              //  resultData.putExtra(EXTRA_ALLOW_MULTIPLE, true);
                System.out.println(resultData.getBooleanExtra(EXTRA_ALLOW_MULTIPLE,false)+"read request code"+files.size());
                for (Uri uris : files) {
                    uri = uris;//Uri.parse(uris.getPath().toString().replaceFirst("files", Environment.getExternalStorageDirectory().getPath()));
                    // file2 = Utils.getFileForUri(uri);
                    // Do something with the result...
                }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user3278732
  • 1,694
  • 10
  • 31
  • 67

2 Answers2

1

You may try this in onActivityResult() :

    if(resultCode == Activity.RESULT_OK) {
        if(data.getClipData() != null) {
            int count = data.getClipData().getItemCount();
            for(int i = 0; i < count; i++)  
                Uri imageUri = data.getClipData().getItemAt(i).getUri();
                //do something with the image (save it to some directory or whatever you need to do with it here) 
            }
        } else if(data.getData() != null) {
            String imagePath = data.getData().getPath();
            //do something with the image (save it to some directory or whatever you need to do with it here)
        }
    }
lenik
  • 23,228
  • 4
  • 34
  • 43
0

Let try this on your Activity Result,

 ClipData clipdata = resultData.getClipData();
 ArrayList<Uri> mUriList = new ArrayList<>(clipdata.getItemCount());
Gobu CSG
  • 653
  • 5
  • 7
  • Intent.EXTRA_ALLOW_MULTIPLE it's working above Sdk18 and print your result data here... And one more thing if u pick single image u need to call resultData.getData() if multiple files use resultData.getClipData(); – Gobu CSG Jul 03 '18 at 08:10