tags:

views:

879

answers:

2

I launch an activity to capture a picture from camera:

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE, null);
i.putExtra("return-data", true);

startActivityForResult(i, PICK_FROM_CAMERA);

Can you please tell me how to get the URI of the capture picture?

Thank you.

A: 

I'm new to Android, but I believe you have to add some extra information to the Intent. The ACTION_IMAGE_CAPTURE 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. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

So, I think you should be able to add in this line:

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File ("MyImageCapture")));

And then you should be able to get it from the URI in the onActivityResult.

But I haven't tested this. Hope I haven't lead you astray.

Marc
I have tried this: i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File ("MyImageCapture")) );i.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name()); startActivityForResult(i, PICK_ICON_FROM_CAMERA_ID);But my onActivityResult() was never get called. Can you please tell me any idea for that happened?
n179911
+1  A: 

To get the image that was just taken from the camera you would do the following

// Call to take the picture
startActivityForResult(new Intent("android.media.action.IMAGE_CAPTURE"), PICK_FROM_CAMERA);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == PICK_FROM_CAMERA)
    {
     Uri uri = data.getData();
      // set the imageview image via uri 
      _previewImage.setImageURI(uri);
    }
}
Bob.T.Terminal