Tap the photo and open the gallery and camera

Asked

Viewed 1,246 times

4

I have a registration screen where you have a default photo of a user. I would like to put both options. When the user touches the photo open an option for him to take a photo of the crowd and replace the current and still an option if he wants to take a photo on time. I don’t know if it’s too complicated. I’ve researched here on the forum and other site and found only to take the photo.

  • What user action that will trigger the camera open event ?

  • This will help you.. http://stackoverflow.com/questions/5309190/android-pick-images-from-gallery

1 answer

6

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);
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.