Get image Uri in onActivityResult after taking photo?
54,904
Solution 1
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
Uri u = intent.getData();
}
By the way... there's a bug with that intent in some devices. Take a look at this answer to know how to workaround it.
Solution 2
Instead of just launching the intent, also make sure to tell the intent where you want the photo.
Uri uri = Uri.parse("file://somewhere_that_you_choose");
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(photoIntent, CAMERA_IMAGE);
Then when you get your onActivityResult() method called, if it was a success just open a stream to the URI and it should all be set.
Solution 3
Uri uri = null;
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
uri = data.getData();
}
Author by
Mohit Deshpande
I am a researcher at The Ohio State University in the field of computer vision and machine learning. I have worked as a mobile apps instructor for Zenva and current work as a writer for Zenva in machine learning.
Updated on August 09, 2022Comments
-
Mohit Deshpande over 1 year
I have this code:
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE);
That allows that user to take a photo. Now how would I get the
Uri
of that photo inonActivityResult
? Is it anIntent
extra? Is it throughIntent.getData()
?