Reputation: 57
I am new to android and I have written code to select multiple images from gallery and for achieving this i have written 2 ways of doing this.
On onActivityResult
I am using data.getClipdata
to recieve
each image.
This is the first way of selecting multiple images.
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"), RESULT_LOAD_IMAGE);
This is the second way of selecting multiple images.
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent,RESULT_LOAD_IMAGE);
I went with the second way of selecting multiple images, because on implementing this it looked better for my app and I could select multiple images on just click and stopped using first way as I have to select multiple images using long press. Thing were going fine as on android studio emulator and Nokia device USB debugging. But on one Samsung device I was not able to select images at all and here the first method worked. So my question is how to achieve multiple images in this scenario using second way if possible and will this issue on some other device too?
Upvotes: 3
Views: 1579
Reputation: 992
I tried the below code and it works. Instead of checking the device "model", check for the Manufacturer. This will redirect the app to open the document chooser (instead of the default gallery app), from there you can navigate to "Photos" from the menu.
public void captureImageFromGallery() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
String deviceName = "Samsung";
if(deviceName.equalsIgnoreCase(Build.MANUFACTURER)) {
intent.setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
}
startActivityForResult(intent, REQ_CODE_GALLERY);
}
Upvotes: 1
Reputation: 1558
As you mention in question for Samsung option 1 and for other device option 2 work. so just put condition and check which device is use at that time
String deviceName = "Samsung";
if(deviceName.e(android.os.Build.MODEL)){
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"), RESULT_LOAD_IMAGE);
}else{
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
Upvotes: 1