Enable front camera and rear camera for Android

Source: Internet
Author: User

Enable front camera and rear camera for Android
Preface:
My Android device is the original N70 dual tablet. This tablet does not have a rear camera and only has a front camera. When I install someProgramThen the program exits. After thinking about it, I found that the general application is installed on the mobile phone, and the default camera of the program is the rear camera. Because my pad does not have a rear camera, an error occurred while calling the rear camera! How can this problem be solved?
Solve the problem
During programming, before calling the OPEN function of the camera function, we must find whether a camera is available. Then pass the detected camera serial number to the open function of the camera class.

@ Targetapi (9) Private int findfrontcamera () {int cameracount = 0; camera. camerainfo = new camera. camerainfo (); cameracount = camera. getnumberofcameras (); // get cameras number for (INT camidx = 0; camidx <cameracount; camidx ++) {Camera. getcamerainfo (camidx, camerainfo); // get camerainfo if (camerainfo. facing = camera. camerainfo. camera_facing_front) {// specifies the camera orientation. Currently, two defined values are camera_facing_front front and camera_facing_back rear return camidx ;}} return-1 ;}@ targetapi (9) private int findbackcamera () {int cameracount = 0; camera. camerainfo = new camera. camerainfo (); cameracount = camera. getnumberofcameras (); // get cameras number for (INT camidx = 0; camidx <cameracount; camidx ++) {Camera. getcamerainfo (camidx, camerainfo); // get camerainfo if (camerainfo. facing = camera. camerainfo. camera_facing_back) {// specifies the camera orientation. Currently, two defined values are camera_facing_front front and camera_facing_back rear return camidx; }}return-1;} public void surfacecreated (surfaceholder holder) {int cammeraindex = findbackcamera (); If (cammeraindex =-1) {cammeraindex = findfrontcamera ();} mcamera = camera. open (cammeraindex );}

Note: It is only available on platforms above android2.3! Otherwise, compilation fails.

Reprinted please declare: http://write.blog.csdn.net/postedit/7980720

Android call front and rear cameras and video and image processing example: http://download.csdn.net/detail/nuptboyzhb/4573084

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.