Can't enable flash on an android device

While i’ve been using OpenCV to get images from my android device’s camera and doing some processing with them for a research, I couldn’t get it to turn on the flash for an important task.

I am currently using for the camera:

        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(;

And the only way I got the flash to actually turn on is using Camera manager, outside of OpenCV, however it turns off as soon as OpenCV starts to use the camera:

private void turnFlashlightOn() {
        CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        try {
            String cameraId = cameraManager.getCameraIdList()[0];
            if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
                cameraManager.setTorchMode(cameraId, true);
        } catch (CameraAccessException e) {

So I’d like some advice on how to get the flash to turn on via OpenCV that actually works, or if I should move the entire part of getting the frames to another library?

so you’re saying Android will not let you affect the flash at all, while OpenCV APIs hold the camera?

maybe there is a way but I don’t know it.

in your place, I’d use Android APIs to use the camera, including getting frames from it. you can then convert the data to OpenCV Mat objects (wrapping, no copy).

Yes, i got the flash to work using the camera2 package, however as soon as OpenCV takes control of the camera it turns off. So I figured that maybe OpenCV had a way of turning the flash on Built-in but apparently, as of now, there is none.

I’ll try to switch all the frame capturing to camera2 and see if it works.

I mean, you could perhaps look into the android-specific videoio backend of OpenCV.

maybe extending it to give you control over the flash could be simple.

the set(CAP_PROP_*) mechanism would be the most appropriate place for this.