Reputation: 1724
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...
}
Upvotes: 1
Views: 47
Reputation: 23498
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)
}
}
Upvotes: 1
Reputation: 691
Let try this on your Activity Result,
ClipData clipdata = resultData.getClipData();
ArrayList<Uri> mUriList = new ArrayList<>(clipdata.getItemCount());
Upvotes: 0