Starting from Android 2.3 Gingerbread, native supports front cameras. Next we will look at how to call the front camera in the program.
The first method is to use mediastore to call the system's native camera.
Intent intent = new intent (mediastore. action_image_capture); </P> <p> intent. putextra ("camerasensortype", 2); // call the front camera <br/> intent. putextra ("autofocus", true); // auto focus <br/> intent. putextra ("fullscreen", false); // full screen <br/> intent. putextra ("showactionicons", false); </P> <p> startactivityforresult (intent, pick_from_camera );
Another method is to use the camera framework. In earlier versions, only camera is used in the SDK. the open () method calls the rear camera. Now this method accepts a parameter to determine whether it is a front camera or a rear camera. We also use the new camerainfo class and getcamerainfo method to obtain the detailed camera information on the Android device, and getnumberofcameras () to obtain the number of cameras. The typical Call method is as follows:
Int cameracount = 0; <br/> camera cam = NULL; </P> <p> camera. camerainfo = new camera. camerainfo (); <br/> cameracount = camera. getnumberofcameras (); // get cameras number </P> <p> for (INT camidx = 0; camidx <cameracount; camidx ++) {<br/> camera. getcamerainfo (camidx, camerainfo); // get camerainfo <br/> If (camerainfo. facing = camera. camerainfo. camera_facing_front) {// specifies the orientation of the camera. Currently, the two defined values are camera_facing_front front and camera_facing_back. <br/> try {<br/> cam = camera. open (camidx); <br/>} catch (runtime1_tione) {<br/> E. printstacktrace (); <br/>}< br/>}
The advantage of using the camera framework is that it provides a large number of APIS, such as setdisplayorientation and camera. parameters is used to implement powerful functions, and urfaceholder is also used. after interfaces such as Callback, shuttercallback, and picturecallback, you can customize interfaces and functions to freely implement the required interface layout and image processing effects. For example: