1
votes

I want to open camera and set torch mode at the same time in android using camera2 api. But because of higher priority of open camera, torch mode is switched off. How can I use both at the same time?

private void openCamera() throws CameraAccessException { CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); cameraId = cameraManager.getCameraIdList()[0];

    CameraCharacteristics cc = cameraManager.getCameraCharacteristics(cameraId);

    StreamConfigurationMap map = cc.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    imageDimensions = map.getOutputSizes(SurfaceTexture.class)[0];


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

       return;
    }
    cameraManager.openCamera(cameraId, stateCallback, null);
    cameraManager.setTorchMode(cameraId, true);


}

using both at same time is not possible in camera2 api

1

1 Answers

0
votes

Once the camera is open, you can use FLASH_MODE and set it to TORCH in your preview capture request.

This means you need to keep AE_MODE to either ON or OFF, not one of the FLASH modes, so that auto-exposure isn't controlling the flash.