How to capture an image and set it as attachment f

2019-04-16 18:07发布

问题:

I want to launch the camera from my application and want to use the captured image as an attachment in my application. The use case is as below:

Press the capture button in the application->Opens camera application -> capture an image->the image is shown as thumbnail in my application.

Any suggestions, ideas, would be very helpful.

回答1:

Image capture step description:

Get Path of image from ACTION_IMAGE_CAPTURE Intent

After that, you have path of the fetched image. Then you can use it for your purpose. Show it as small Bitmap, and attach the original to further processing.

To view captured image, send the intent

Intent viewImageIntent = new Intent();   
viewImageIntent.setAction(android.content.Intent.ACTION_VIEW);   
File file = new File(imageFilePath);   
viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*");   
viewImageIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(viewImageIntent);