I am trying to allow a user to select an image, either from the gallery or by taking a picture with the camera. I tried this:
Intent imageIntent = n
You should do this logic within your app. Picking image from gallery and taking picture using camera are using different intent.
I suggest you use button (or whatever UI it is to make a user select an action) and creates two separate method for both actions. Let's say, you've created two buttons named btnPickGallery and btnTakePicture.
Both buttons fire their own action, say onBtnPickGallery and onBtnTakePicture.
public void onBtnPickGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST_CODE);
}
public void onBtnTakePicture() {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photo = new File(Environment.getExternalStorageDirectory(), "dir/pic.jpg");
Uri outputFileUri = Uri.fromFile(photo);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
}
And then you can grab the result using onActivityResult() method.