open Selected Camera - Android android.hardware

Android examples for android.hardware:Open Camera

Description

open Selected Camera

Demo Code

import android.annotation.SuppressLint;
import android.hardware.Camera;

public class Main {

  private static int mCameraId;

  @SuppressLint("NewApi")
  public static Camera openSelectedCamera(int type) {
    int cameraCount = 0;
    Camera cam = null;// w  w  w  . j a  v a  2  s. c om
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
    for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
      Camera.getCameraInfo(camIdx, cameraInfo);
      if (cameraInfo.facing == type) {
        try {
          cam = Camera.open(camIdx);
          mCameraId = camIdx;
        } catch (RuntimeException e) {
        }
      }
    }

    return cam;
  }

}

Related Tutorials