Wednesday 15 January 2020

What is the alternative for setTorchMode in API 21 and 22

I'm trying run flashlight on API 21 and 22 but not working

Code

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                isFlashlightOn();
                if (camera == null && parameters == null) {
                    camera = Camera.open();
                    parameters = camera.getParameters();
                    parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                    camera.setParameters(parameters);
                }
                if (getFlashlightState) {
                    Objects.requireNonNull(camera).startPreview();
                } else {
                    Objects.requireNonNull(camera).stopPreview();
                }
            } else {
                isFlashlightOn();
                if (cameraManager == null) {
                    cameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE);
                }
                try {
                    String cameraId = Objects.requireNonNull(cameraManager).getCameraIdList()[0];
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        cameraManager.setTorchMode(cameraId, getFlashlightState);
                    }else{
                        //the problem is here because I don't know what can I put in else
                    }
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

What is the alternative for setTorchMode in API 21 and 22



from What is the alternative for setTorchMode in API 21 and 22

No comments:

Post a Comment