camera and gallery intent android code example
Example 1: select photo from camera android
private void pickFromGallery(){
Intent intent=new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
String[] mimeTypes = {"image/jpeg", "image/png"};
intent.putExtra(Intent.EXTRA_MIME_TYPES,mimeTypes);
startActivityForResult(intent,GALLERY_REQUEST_CODE);
}
public void onActivityResult(int requestCode,int resultCode,Intent data){
if (resultCode == Activity.RESULT_OK)
switch (requestCode){
case GALLERY_REQUEST_CODE:
Uri selectedImage = data.getData();
imageView.setImageURI(selectedImage);
break;
}
}
Example 2: open camera or gallery on button click android
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(intent);