How to launch the camera and take a picture

后端 未结 3 961
粉色の甜心
粉色の甜心 2020-12-18 17:07

I\'m trying to make an Android demo. In the demo, I have to show the camera in an activity and take a picture before advancing to another activity where I can see the camera

3条回答
  •  悲哀的现实
    2020-12-18 17:59

    Here is the code sample.

    Uri mOutputFileUri;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutputFileUri); // URI of the file where pic will be stored
    
    startActivityForResult(intent, TAKE_PICTURE_FROM_CAMERA);
    

    Then in your onActivityResult just check the resultCode and get your image from mOutputFileUri.

    You would also want to check for the external media presence and handle the issues with the camera application behavior for HTC devices.

提交回复
热议问题