在 android X 中更改闪光灯模式时如何避免刷新屏幕

how to avoid refreshing of screen while changing flash mode in android X

我正在尝试改变闪光灯模式,如下所示

when {
    ImageCapture.FLASH_MODE_AUTO == imageCapture!!.flashMode -> {
        imageCaptureFlashMode = ImageCapture.FLASH_MODE_ON
        idFlashControl.setImageResource(R.drawable.ic_flash_on)
        startCamera()
    }
...
...

在 startCamera() 中,我正在绑定如下用例

cameraProvider?.unbindAll()
val cameraX = cameraProvider?.bindToLifecycle(
            this, cameraSelector, preview, imageCapture
        )

解除绑定正在重新创建表面。因此,当我更改闪光灯模式时,屏幕变黑并恢复生机,就像创建了一个新的 activity。

如何避免这种情况?

在更改图像捕获用例的闪光灯模式时,您不必 unbind/rebind 用例。当您将flash模式设置为FLASH_MODE_ON时,后续的抓取请求将使用flash(假设设备支持flash)。

// Assuming the image capture has already been bound
imageCapture.flashMode = ImageCapture.FLASH_MODE_ON

// Assuming the flash unit is available, this capture request will use the flash
imageCapture.takePicture(...)