How to get the URL of the captured image?

2020-03-30 03:57发布

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 ?

标签: java android
2条回答
何必那么认真
2楼-- · 2020-03-30 04:21

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.

查看更多
够拽才男人
3楼-- · 2020-03-30 04:24

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);
    }
}
查看更多
登录 后发表回答