get Cameras Count - Android Camera

Android examples for Camera:Camera Attribute

Description

get Cameras Count

Demo Code


import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.os.Build;

public class Main {
  @SuppressLint("NewApi")
  public static int getCamerasCount(Context ctx) {
    int count = 0;

    if (Build.VERSION.SDK_INT >= 21) {
      CameraManager manager = (CameraManager) ctx.getSystemService(Context.CAMERA_SERVICE);
      try {//from  w w w  . ja  v a 2s  .  co  m
        count = manager.getCameraIdList().length;

      } catch (CameraAccessException e) {

      }

    } else {
      count = Camera.getNumberOfCameras();
    }

    return count;
  }
}

Related Tutorials