Get URI of a full size photo by Camera on Onactivityresult

Asked

Viewed 160 times

2

I’m using the Android camera to take picture and save it from a Webservice. I managed to do this, but using the method of taking a thumbnail. My intention is to take the image in full size.

I searched a lot and got to the official Android site. http://developer.android.com/intl/pt-br/training/camera/photobasics.html#TaskPath

So, on my button to take the photo I called the method dispatchTakePictureIntent, as has on the official website and also created the method createImageFile(), as will be shown below.

static final int REQUEST_TAKE_PHOTO = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

String mCurrentPhotoPath;

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

Tranquil. However my intention now is to get the result in Onactivityresult and, following the official google tutorial, it was not clear to me what code I put in Onactivityresult (the code you have there activityresult is for thumbnail.

I saw some codes on the internet, but many take the thumbnail of the URI. I want to take the full Onactivityresult.

I saw the methods setPic and galleryAddPic on the site, but I do not know where I will apply.

Can anyone help which code I insert into Onactivityresult?

  • I don’t understand your question why URI for the photo taken is the one you passed here takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));

No answers

Browser other questions tagged

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