I have the following button in my activity, that opens the gallery to select single or multiple images, and below this, the OnActivityResult
function, that is returning result as RESULT_CANCELLED
for multiple images, and RESULT_OK
for a single image. Not sure why it's happening. Can someone please help.
buttonGallery.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent,"Select Picture"), choose_picture);
//startActivity(intent);
}
});
//OnActivityResult for the above
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == choose_picture) {
Uri imageUri = (Uri)data.getParcelableExtra(Intent.EXTRA_STREAM);
//Do something
}
I'm getting data.getData()
as null
, data.getExtras()
as null
.
Can someone guide me how to get the required results from the above code. I want the URIs
of all images that the user selects from the gallery.
PS : It's working fine for a single image, not sure why.