Reputation: 5895
I am trying to select images from android gallery. And here is my code. It works fine with single image. But when if select multiple image its giving me back null. Any idea whats going wrong
Button addNewCart = (Button) findViewById(R.id.imageSelect);
addNewCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent( );
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent,
"select multiple images"), 100);
}
});
And here is the code for activity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == Activity.RESULT_OK){
String[] all_path = data.getStringArrayExtra("all_path");
if(data != null)
{
Uri selectedImageUri = data.getData();
System.out.println(selectedImageUri);
}
}
}
Any ideas ?
Thanks
Upvotes: 2
Views: 605
Reputation: 3322
try like this,
private final int PICK_IMAGE_MULTIPLE =1;
addNewCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent( );
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent,
"select multiple images"), PICK_IMAGE_MULTIPLE);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == Activity.RESULT_OK){
if(requestCode == PICK_IMAGE_MULTIPLE){
String[] imagesPath = data.getStringExtra("data").split("\\|");
}
}
}
Upvotes: 1