Enabling/disabling torch while in session

I have been trying to figure out a way to turn on the torch for the rear camera while in a session.
I failed to find a way specific to the SDK, so I used the usual method via the CameraManager as follows:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val manager = requireContext().getSystemService(Context.CAMERA_SERVICE) as CameraManager
            manager.setTorchMode(camID, enable)
        } else {
            // todo: Handle for lower API levels

however, expectedly, this results in an error with the following message:

Torch for camera “0” is not available due to an existing camera user

is there a safe way to turn on the torch while in session?

Which Android Video SDK version?
v1.1.1 (8665.0812)

Hi @wbaroudi, thanks for the post.

The SDK should not be doing anything that would prevent you from programmatically turning on the torch. I have tested this and can properly turn it on 100% of the time. Are you certain that you are using the correct ID of the camera? Is this issue specific to any device makes/models?


Hi Jon,
Are you using the same native way I mentioned in the post?
I’m pretty sure this doesn’t work when you use the same device for preview, which will always be the case for phones with a single back camera.
My phone has multiple back cameras, I looped over them and turned the flash on for all of them, this worked. it turned the torch on for the camera with ID 2, while the camera the Zoom SDK is using has ID 0. this is alright as long as the phone has multiple back cameras.
Also, getting the camera device list from the VideoHelper in the SDK only gives 2 devices with IDs 0 and 1. However, getting it from the CameraManager gives more devices, which I assume are the separate back cameras. So, technically the zoom SDK does not recognize the other back camera devices, which means that, by design, it should not allow enabling torch using the native method, or am I wrong?

Thank you!

Hey @wbaroudi,

@jon.lieblich is currently out, but will be back this week to follow up with you :slight_smile:


Hi @wbaroudi,

After doing some more investigation on this, it does appear that camera access is restricted only when attempting to use the same camera that the SDK is currently using. Since the SDK only swaps between front and back instead of individual cameras, the only workaround available at this time would be to temporarily switch cameras whenever you need to change the torch mode.

We’ll investigate adding better support for this in the future and keep you updated.


Hi @jon.lieblich, welcome back :smiley:
Yup, that’s what I was trying to point out.
Great, I’ll be looking forward to hearing back from you.


Hi @wbaroudi,

I just wanted to let you know that we have added this feature to our long term backlog. We don’t have an exact idea of when this will be included, but it should be added at some point in the future.

If you aren’t already aware, the best place to keep track of new releases is our release notes page. :slightly_smiling_face:


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.