How to get id of front facing camera using Camera2?

后端 未结 2 520
春和景丽
春和景丽 2021-02-07 13:06

How can I get id of front facing camera using new Camera2 library? I can\'t find it anywhere in documentation.

2条回答
  •  佛祖请我去吃肉
    2021-02-07 14:08

    I have found solution, i could get camera characteristics by calling getCameraCharacteristics(cameraId); on CameraManager object.

    String getFrontFacingCameraId(CameraManager cManager){
        for(final String cameraId : cManager.getCameraIdList()){
            CameraCharacteristics characteristics = cManager.getCameraCharacteristics(cameraId);
            int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
            if(cOrientation == CameraCharacteristics.LENS_FACING_FRONT) return cameraId;
        }
        return null;
    }
    

提交回复
热议问题