I have to make a button that will provide to choose image from gallery or take from camera.
private void showFileChooser() {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
imageView.setImageURI(selectedImage);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
imageView.setImageURI(selectedImage);
}
break;
}
}
The result is working. If i choose from gallery, the imageviewer will view that, it also working if i choose taking photo from camera. The problem is, in my showFileChooser() method, all of my intent are runing in same time, so when i choos from gallery, the camera still running also. I choose camera, the gallery is opening too. I think i should implement my code in switch case mode but i dont understand how to do that. Please kindly help to solve my beginner problem.