Android calls the camera function

Source: Internet
Author: User

See examples of Android photo taking, video recording, and Recording Code

 

Public class mycameraactivity extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); button btncamera = (button) findviewbyid (R. id. btncamera); btncamera. setonclicklistener (New onclicklistener () {@ override public void onclick (view v) {// todo auto-generated m Ethod stub letcamera () ;}}) ;}protected void onactivityresult (INT requestcode, int resultcode, intent data) {super. onactivityresult (requestcode, resultcode, data); Switch (requestcode) {Case 1: // If (resultcode = result_ OK) {toast. maketext (this, "Shooting successful", toast. length_short ). show ();} break; default: break;} protected void letcamera () {// todo auto-generated method stub intent imagecapt Ureintent = new intent (mediastore. action_image_capture); string strimgpath = environment. getexternalstoragedirectory (). tostring () + "/dlion/"; // string filename = new simpledateformat ("yyyymmddhhmmss "). format (new date () + ". jpg "; // name of the photo file out = new file (strimgpath); If (! Out. exists () {out. mkdirs ();} Out = new file (strimgpath, filename); strimgpath = strimgpath + filename; // The absolute URI of the photo = Uri. fromfile (out); imagecaptureintent. putextra (mediastore. extra_output, Uri); imagecaptureintent. putextra (mediastore. extra_video_quality, 1); startactivityforresult (imagecaptureintent, 1 );}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.