views:

218

answers:

2

I'm trying to use a standard Intent that will take a picture, then allow approval or retake. Then I want to save the picture into a file.

Here's the Intent I am using:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );

startActivityForResult( intent, 22 );

The documentation says:

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

I don't pass extra output, I hope to get a Bitmap object in the extra field of the Intent passed into onActivityResult() (for this request). So where/how do you extract it? Intent has a getExtras(), but that returns a Bundle, and Bundle wants a key string to give you something back.

What do you invoke on the Intent to extract the bitmap?

+1  A: 

Try calling getExtras().get("data") and casting the result to a Bitmap.

See here for an example.

CommonsWare
Thank you - your answer, and your sample code work perfectly.May I ask what steps you went through to put those pieces together? Were you lucky enough to find some good material, or were you in a class, or are you one of the implementers, etc?
Peter vdL
"May I ask what steps you went through to put those pieces together?" I searched on Google to find that blog post. While I have written three books on Android development, I have not used the camera `Intent` for thumbnails.
CommonsWare
A: 

On a related note, if you have the "crop" activity come up after taking the picture using intent.putExtra("crop", "true"), you'll get the cropped URI from getExtras().get("action").

I realize you've got this all fixed by now, just want to make sure no one tries to use this with crop and gets confused.

Reference: the apps-for-android LolCat activity.

Josh