is Facing Back Camera Available - Android android.hardware

Android examples for android.hardware:Back Camera

Description

is Facing Back Camera Available

Demo Code

import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;

public class Main {

  private static Boolean available;

  static public boolean isAvailable() {
    if (available == null) {
      try {//w w  w. j av a 2 s  .  co m
        getBackId();
        available = true;
      } catch (Exception e) {
        available = false;
      }
    }
    return available;
  }

  static public int getBackId() throws Exception {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
      Camera.getCameraInfo(i, cameraInfo);
      if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
        return i;
      }
    }
    throw new Exception();
  }

}

Related Tutorials