Get ID of currently open camera

There isn't a way to get the id of the currently open android camera. I ended up storing the id when I opened it.


It is just a number of the camera, so you loop through looking for the camera you want.

Here is a snippet to find the front-facing camera:

int cameraId = -1;
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
  CameraInfo info = new CameraInfo();
  Camera.getCameraInfo(i, info);
  if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
    Log.d(DEBUG_TAG, "Camera found");
    cameraId = i;
    break;
  }
}

Tags:

Android

Camera