Pass a photo to another layout?

0

What I want is that at the moment of taking a picture I am shown in an imgview but from another layout, what I have now is that I press the botton of the camera asks me permission to take the photo after I accept that photo and I the sample in an imgview of the same layout. What I want to do is that once the photo has been taken and I have already given it to accept the photo, send me directly to another layout with the photo shown in an imgview.

 private void showOptions() {
    final CharSequence[] option = {"Tomar foto", "Cancelar"};
    final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle("Elige una opción");
    builder.setItems(option, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if(option[which] == "Tomar foto"){
                openCamera();
            }else if(option[which] == "Elegir de galeria"){
                Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(intent.createChooser(intent, "Selecciona app de imagen"), SELECT_PICTURE);
            }else {
                dialog.dismiss();
            }
        }
    });
  private void openCamera() {
    File file = new File(Environment.getExternalStorageDirectory(), MEDIA_DIRECTORY);
    boolean isDirectoryCreated = file.exists();

    if(!isDirectoryCreated)
        isDirectoryCreated = file.mkdirs();

    if(isDirectoryCreated){
        Long timestamp = System.currentTimeMillis() / 1000;
        String imageName = timestamp.toString() + ".jpg";

        mPath = Environment.getExternalStorageDirectory() + File.separator + MEDIA_DIRECTORY
                + File.separator + imageName;

        File newFile = new File(mPath);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(newFile));
        startActivityForResult(intent, PHOTO_CODE);
    }
}

I put it in an imgview

 mSetImage = (ImageView) findViewById(R.id.set_picture);
    
asked by Esteban 16.06.2017 в 11:14
source

1 answer

0

I did something similar, on the button to take the photo:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
           startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }

Then you have to collect the result in the method onActivityResult of your Activity , it is already a Bitmap that you can load in the ImageView :

 if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {

            Bundle extras = intent.getExtras();
            last_picture = (Bitmap) extras.get("data");
            ((ImageView) findViewById(R.id.taidImageEdit)).setImageBitmap(last_picture); 
}
    
answered by 16.06.2017 в 12:13