How to detect if there is front camera and if there is how to reach and use front camera?

后端 未结 4 1958
眼角桃花
眼角桃花 2021-01-06 04:03

How to detect if there is a front camera and if there is how to reach and use front camera ?

4条回答
  •  广开言路
    2021-01-06 04:45

    Oak your code will not support sdk above 21 so i have added these lines to make it useable :)

        int getFrontCameraId(CameraManager cManager) {
        if (Build.VERSION.SDK_INT < 22) {
            Camera.CameraInfo ci = new Camera.CameraInfo();
            for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
                Camera.getCameraInfo(i, ci);
                if (ci.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) return i;
            }
        } else {
            try {
                for ( int j = 0;j

    I have updated the code of Oak which now supports new camera2 library also.

提交回复
热议问题