-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
Is there any possibility to toggle the flashlight via code?
Maybe expose a function in QRActivity class that can allow us to toggle the flashlight programmatically instead of clicking in the camera preview? 😅
I've tried to switch on the flashlight using a utility flashlight class before launching the QRActivity (camera preview), however it always turns off the flashlight.
My flashlight util class:
class FlashlightUtil(private val context: Context) {
fun toggleFlashlight(isOn: Boolean){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val camManager: CameraManager? = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager?
var cameraId: String? = null
try {
cameraId = camManager?.cameraIdList?.get(0)
camManager?.setTorchMode(cameraId!!, isOn)
} catch (e: CameraAccessException) {
e.printStackTrace()
}
}
}
}Metadata
Metadata
Assignees
Labels
No labels