What I'm trying to do seems very simple, but after a few days of searching I can't quite figure it out.
I have an application that allows the user to select multiple(up to 5) images. I'm using an ImageView
. When the user clicks on the ImageView
, I'd like to allow them the option to
- Select the image from the gallery, or
- Use the camera to capture an image.
I started by using the ACTION_GET_CONTENT
intent, and that works well for getting to the gallery. So then I tried using the ACTION_PICK_ACTIVITY
intent to allow the user to choose camera or gallery:
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
pickIntent.putExtra(Intent.EXTRA_INTENT, camIntent);
pickIntent.putExtra(Intent.EXTRA_INTENT, gallIntent)
pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
startActivityForResult(pickIntent, IMAGE_SELECTOR);
But it appears I can only add one EXTRA_INTENT
. The menu show up as expected, but the only options are Gallery and Files....no Camera).
Is there a better/easier way to do this that I'm missing? Thanks for any help.
This should take care of Tina's null outputFileUri issue:
Note: I'm using this code inside android.support.v4.app.Fragment your overridden methods might change depending on what Fragment/Activity version you're using.
I had worked hard on Camera or gallery Image Selection, and created some util class for this work. With the use of these class 'Selecting image camera or gallery is too easy' it just took 5-10 mints of your development.
ImagePickerUtils :- http://www.codesend.com/view/f8f7c637716bf1c693d1490635ed49b3/
BitmapUtils :- http://www.codesend.com/view/81c1c2a3f39f1f7e627f01f67be282cf/
ConvertUriToFilePath :- http://www.codesend.com/view/f4668a29860235dd1b66eb419c5a58b5/
MediaUtils :- https://codeshare.io/5vKEMl
We need to Add these Permission in menifest :
This class function (checkAndRequestPermissions) auto check the permission in Android-Marshmallow and Android - Nougat.
I hope it helps you, If any one having any suggestion to improve these class please add your review in comments.
this code will help you, in that there is two button one for Camera and another for Gallery, and Image will be displayed in ImageView
https://github.com/siddhpuraamitr/Choose-Image-From-Gallery-Or-Camera
I also had this issue and what I did was create an AlertDialog and use the setItems() method along with the DialogInterface listener:
How to launch a single Intent to select images from either the Gallery or the Camera, or any application registered to browse the filesystem.
Rather than creating a Dialog with a list of Intent options, it is much better to use Intent.createChooser in order to get access to the graphical icons and short names of the various 'Camera', 'Gallery' and even Third Party filesystem browser apps such as 'Astro', etc.
This describes how to use the standard chooser-intent and add additional intents to that.