Camera
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, 1);
Gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Selecione uma imagem"), 2);
Treatment of choice
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 2 && resultCode == RESULT_OK){
//imagem veio da galeria
Uri uriImagemGaleria = data.getData();
String caminho = "";
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if( cursor != null ){
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
caminho = uri.getPath();
caminho = getPath(uriImagemGaleria);
Bitmap bitmap = BitmapFactory.decodeFile(caminho);
iv.setImageBitmap(bitmap);
}
else if(requestCode == 1 && resultCode == RESULT_OK){
//imagem veio da camera
Bundle extras = data.getExtras();
Bitmap imagem = (Bitmap) extras.get("data");
iv.setImageBitmap(imagem);
}
}
What user action that will trigger the camera open event ?
– Victor Tadashi
This will help you.. http://stackoverflow.com/questions/5309190/android-pick-images-from-gallery
– Paulo Gustavo