Check if device has a camera?

前端 未结 14 1229
粉色の甜心
粉色の甜心 2020-11-30 21:59

In my app, I\'d like to use the camera, if the device has one. Are there any devices running android that do not have a camera? By including the following into my m

14条回答
  •  孤城傲影
    2020-11-30 22:29

    Camera.getNumberOfCameras() is deprecated. You can use:

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public int getNumberOfCameras() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            try {
                return ((CameraManager) getSystemService(Context.CAMERA_SERVICE)).getCameraIdList().length;
            } catch (CameraAccessException e) {
                Log.e("", "", e);
            }
        }
        return Camera.getNumberOfCameras();
    }
    

提交回复
热议问题