get Camera Id by facing - Android android.hardware

Android examples for android.hardware:Camera ID

Description

get Camera Id by facing

Demo Code

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

public class Main {

  public static int getCameraId(int facing) {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);//from w ww.  j  a  v a  2 s .  c  o m
      if (info.facing == facing) {
        cameraId = i;
        break;
      }
    }
    return cameraId;
  }

}

Related Tutorials