开发者

Grabbing a picture from within an App?

I want my Android app to take a picture, as part of something larger it is doing.

Ideally, I would like to just开发者_运维问答 send out an Intent saying "snap a picture" and get back an image file.

Is there an Activity that can handle that, or do I need to do all the low level work with the Camera class myself?

Thanks,

Peter


You can invoke the default camera activity using an Intent and startActivityForResult(). You can also construct a Uri and file name for the image and pass that to the photo capture activity. When the user takes a photo it will be saved with that name at the location you've specified.

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputUri );
startActivityForResult( intent, 0 );

If the user cancels the capture then a result of 0 is returned, and if they take a photo and approve it, a result of -1 is returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜