Android Code Snippet Torch in CamEx2

For some reason there is no support for the torch feature in CamEx2. Add this Sub to CamEx2 (v1.31) to have a torch:

B4X:
Public Sub setTorch(pbolOn As Boolean, pbolVideoRecording As Boolean)
    SetBothMaps("FLASH_MODE", FLASH_MODE.IndexOf(IIf(pbolOn, "TORCH", "OFF")))
    StartPreview(TaskIndex, pbolVideoRecording)
End Sub
 

b4x-de

Active Member
Licensed User
Longtime User
My code above works on old Samsung and Huawei devices but not on modern devices like VIVO with Android 14. The following problem occurs:

The torch is turned off immediately before the photo is taken and does not turn on again.

I found the Camera.AbortCaptures in the Sub TakePictureNow() responsible for this behavior, but I do not understand why. Can someone please provide more insight into this? Thanks!

Btw: It does not help to set the AE Mode to "ON" before setting the Flash to "TORCH" although this can be found in some posts in Stackoverflow as a solution.
 
Last edited:

Markos

Active Member
Licensed User
Longtime User
My code above works on old Samsung and Huawei devices but not on modern devices like VIVO with Android 14. The following problem occurs:

The torch is turned off immediately before the photo is taken and does not turn on again.

I found the Camera.AbortCaptures in the Sub TakePictureNow() responsible for this behavior, but I do not understand why. Can someone please provide more insight into this? Thanks!

Btw: It does not help to set the AE Mode to "ON" before setting the Flash to "TORCH" although this can be found in some posts in Stackoverflow as a solution.
I dunno if you still have this issue but I found a way to get the flash to work setting the following :

Setting flash to work when taking a snapshot:
setSceneMode("ACTION")
SetBothMaps("CONTROL_AE_MODE", AE_MODE.IndexOf("ON"))

And to disable flash from always flashing after taking a snapshot
Disable flash from being active:
    setSceneMode("PORTRAIT")
    SetBothMaps("CONTROL_AE_MODE", AE_MODE.IndexOf("ON_AUTO_FLASH"))

The disabling of flash may only need the 1st line but havent had the desire to verify
 
Top