This is a weird issue . I don't know whether it is a bug or something in the library .So the issue is with flash of the camerax .
I assign a global variable flashMode
private var flashMode: Int = ImageCapture.FLASH_MODE_OFF
then set it to the ImageCaptureBuilder
imageCapture = ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetAspectRatio(screenAspectRatio)
.setFlashMode(flashMode)
.setTargetRotation(rotation)
.build()
And before taking the picture I turn the flash On
if (camera?.cameraInfo?.hasFlashUnit() == true) {
flashMode = ImageCapture.FLASH_MODE_ON
}
But this does Not turn the camera flash On , but it sets the flashMode value to 1 ,i.e.,ImageCapture.FLASH_MODE_ON (I checked via logging ).Before capturing the image , i again logged and checked the value of flashMode and it was 1 , but then too the flash was not turning on.But if I set the global variable as
private var flashMode: Int = ImageCapture.FLASH_MODE_ON
Then it works and the flash get's turned on . I have tried this above method of setting the Flash On post setting it to FlashModeOff in my previous projects and it had worked well . But this time I am not able to understand what is wrong . Thanks in advance
Try changing the flash mode with
imageCapture.flashMode = ImageCapture.FLASH_MODE_ON
instead of
flashMode = ImageCapture.FLASH_MODE_ON