I have created a chooser for either picking an image from file or for making a picture.
The code I use works fine on a Nexus 5, however when I try it on a Samsung S5, the chooser does not display the camera icons.
public Intent makePhotoIntent(String title, Context ctx, String uniqueImageId){
//Build galleryIntent
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
//Create chooser
Intent chooser = Intent.createChooser(galleryIntent,title);
if (checkexCameraHardware()){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mTempImage = null;
try {
mTempImage = createImageFile(uniqueImageId);
} catch (IOException e) {
e.printStackTrace();
}
if (mTempImage != null){
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempImage)); //add file ure (photo is saved here)
Intent[] extraIntents = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
}
}
return chooser;
}
When I change the order in which the intents are added to the chooser the Samsung device does show the camera but only shows android-system as the file option.
public Intent makePhotoIntent(String title, Context ctx, String uniqueImageId){
//Build galleryIntent
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
//Create chooser
Intent chooser = Intent.createChooser(galleryIntent,title);
if (checkexCameraHardware()){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mTempImage = null;
try {
mTempImage = createImageFile(uniqueImageId);
} catch (IOException e) {
e.printStackTrace();
}
if (mTempImage != null){
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempImage)); //add file ure (photo is saved here)
//I have to re-create the chooser here or the Samsung will not show the 'camera' icons.
//I have to add the cameraIntent first.
chooser = Intent.createChooser(cameraIntent,title);
Intent[] extraIntents = {galleryIntent};
//Intent[] extraIntents = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
}
}
return chooser;
}
Ideally I would like the Samsung device to show the same as the Nexus one when I add the gallery intent first. I can however not get this to work.