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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…