get Camera facing Back Id - Android android.hardware

Android examples for android.hardware:Back Camera

Description

get Camera facing Back Id

Demo Code

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

public class Main {

  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;
      }// w w  w  .  ja v  a 2 s.c om
    }
    throw new Exception();
  }

}

Related Tutorials