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