The method is to use mediastore to call the system's native camera.
12345678 |
Intent intent =
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra( "camerasensortype" ,
2 ); // Call the front camera
intent.putExtra( "autofocus" ,
true ); // Auto focus
intent.putExtra( "fullScreen" ,
false );
// Full screen intent.putExtra( "showActionIcons" ,
false ); 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:
12345678910111213141516 |
int
cameraCount = 0 ;
Camera cam =
null ; Camera.CameraInfo 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 ) {
// Represents the camera's position, // Currently, the two defined values are camera_facing_front and camera_facing_back.
try
{ cam = Camera.open( camIdx );
}
catch (RuntimeExceptione) {
e.printStackTrace();
}
} |
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: