Get image Uri in onActivityResult after taking photo?

后端 未结 4 730
逝去的感伤
逝去的感伤 2021-02-07 00:48

I have this code:

startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE);

That allows that user to take a photo. Now

4条回答
  •  梦谈多话
    2021-02-07 01:20

    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.

提交回复
热议问题