2

I'm using a 3-rd party library (boofCV) to work with a camera in Android . And they open the camera without a visible way of holding it:

CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
manager.openCamera(cameraId, mStateCallback, null);

I need to add a flashlight with the camera but when I use this code:

cameraManager.setTorchMode(cameraId, true)

I got the error:

CameraAccessException: android.hardware.camera2.CameraAccessException: CAMERA_IN_USE (4): setTorchMode:2122: Torch for camera "0" is not available due to an existing camera user.

And if I try to use this API < M code:

    val camera = Camera.open()
    val params = camera.parameters
    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH)
    camera.setParameters(params)
    camera.startPreview()

I also get an error because of the camera is already opened:

E/CameraCaptureSession: Session 0: Exception while stopping repeating: 
    android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): checkPidStatus:2193: The camera device has been disconnected

So, how can I get the camera source to turn on/off the flashlight in this case?

UPDATE: Hm, I even tried to rewrite the library's code and added

manager.setTorchMode(cameraId, true);

before

manager.openCamera(cameraId, mStateCallback, null);

But got only a short flash.

Psijic
  • 743
  • 7
  • 20

0 Answers0