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

后端 未结 4 1983
眼角桃花
眼角桃花 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:56

    Kalpit, I don't know how you managed to get the code working. I tried to edit your answer, but the full answer needs to be changed. Here's what I got.

    @SuppressLint("NewApi" )
    int getFrontCameraId() {
        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 {
                CameraManager cManager = (CameraManager) getApplicationContext()
                   .getSystemService(Context.CAMERA_SERVICE);
                String[] cameraId = cManager.getCameraIdList();
                for ( int j = 0;j

提交回复
热议问题