Basically, I need to select multiple images. My code is working fine when I select multiple images but it's not working when I select a single image.
I am using this code to select the images
public void getPhotoFromGallery(){
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"), 1);
}
My onActivityResult() is
super.onActivityResult(requestCode, resultCode, data);
Log.i("onActivityResult: ", "STARTED");
if(requestCode == 1 && resultCode == RESULT_OK && data!=null){
try {
Log.i("Error: ", String.valueOf(data));
ClipData mClipData = data.getClipData();
Log.i("Error: ", String.valueOf(mClipData));
.....
.....
}
catch (Exception e){
e.printStackTrace();
}
}
}
When I select multiple images, My code is working fine. But when I select a single image, data.getClipData() is returning null. I basically need a list of URI of all the select images. I don't understand the problem. Also, String.valueof(data) shows there is URI present when one image is selected but data.getClipData() still returning null.
Also, String.valueof(data) shows there is URI present when one image is selected but data.getClipData() still returning null
You will get that Uri from calling data.getData(), where data is the Uri delivered to onActivityResult().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With