I created an activity, which takes a photo using the default camera app. I used the code from this tutorial: https://developer.android.com/training/camera/photobasics#TaskPath
I create the intent like this:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
And then I set the path of the output:
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, currentPhotoPath);
In the tutorial, they save currentPhotoPath
to a private variable in the activity. I would like to avoid that, and get the path from the intent in the onActivityResult
function, here:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
// How to access the path here?
}
}
I tried intent.getStringExtra(MediaStore.EXTRA_OUTPUT)
, but it returns null.
I would like to avoid storing the path in a class member, because the activity might be destroyed and recreated by the android system, and then that variable will be null.
I was able to find a similar question, but the answers are for Android 2, and they use deprecated apis, like managedQuery
.