get First Back Facing Camera ID - Android android.hardware

Android examples for android.hardware:Back Camera

Description

get First Back Facing Camera ID

Demo Code

import android.hardware.Camera;

public class Main {

  /**//  w w w  .ja v a2  s .c om
   *
   * @return the id of the first BackFacing camera
   */
  public static int getFirstBackFacingCameraID() {
    int lCamId = 0;

    for (lCamId = 0; lCamId < Camera.getNumberOfCameras(); lCamId++) {
      Camera.CameraInfo lCameraInfo = new Camera.CameraInfo();
      Camera.getCameraInfo(lCamId, lCameraInfo);
      if (lCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
        return lCamId;

    }
    return 0;
  }

}

Related Tutorials