Usually we do camera operations, such as scanning two-dimensional code needs to determine whether there is a rear-mounted camera (rear camera), such as the Nexus 71 generation has no rear-mounted camera, so in the attempt to use, we need to make a judgment for some hints or processing.
The following code is a series of methods used to determine whether a front-facing camera (Front Camera) is available, and the rear camera.
Copy Code code as follows:
private static Boolean checkcamerafacing (final int facing) {
if (Getsdkversion () < Build.version_codes. Gingerbread) {
return false;
}
Final int cameracount = Camera.getnumberofcameras ();
Camerainfo info = new Camerainfo ();
for (int i = 0; i < Cameracount; i++) {
Camera.getcamerainfo (i, info);
if (facing = = info.facing) {
return true;
}
}
return false;
}
public static Boolean Hasbackfacingcamera () {
Final int camera_facing_back = 0;
Return checkcamerafacing (Camera_facing_back);
}
public static Boolean Hasfrontfacingcamera () {
final int camera_facing_back = 1;
Return checkcamerafacing (Camera_facing_back);
}
public static int getsdkversion () {
return Android.os.Build.VERSION.SDK_INT;
}
Note: Since both Getnumberofcameras and Getcamerainfo are introduced as API 9, the method applies only to 2.3 and above.
Extended reading: http://developer.android.com/reference/android/hardware/Camera.html http://developer.android.com/reference /android/hardware/camera.camerainfo.html