Touch the photo and open the gallery and camera

4

I have a sign-up screen where a user's default photo is stored. I would like to put both options. From when the user touches the photo open an option for him to take a photo of the crew and replace the current one and still an option if he wants to take a photo in time. I do not know if it's too complicated. I already researched here in the forum and other websites and found only to take the photo.

    
asked by anonymous 08.07.2016 / 13:54

1 answer

5

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);
  }
}
    
08.07.2016 / 14:24