Use the device's flash unit on Android SDK (Kotlin/Java)
Stay organized with collections
Save and categorize content based on your preferences.
Enabling the device's flash unit during an AR session can help improve
visibility.
Check that the current camera configuration supports flash
Not all camera configurations support enabling a flash unit.
Before enabling the flash or offering users the option to enable the flash,
ensure that the flash unit is available for the active camera
configuration:
[null,null,["Last updated 2025-07-14 UTC."],[[["\u003cp\u003eEnabling the device's flash during an AR session can enhance visibility in low-light environments.\u003c/p\u003e\n"],["\u003cp\u003eBefore enabling the flash, verify if the active camera configuration supports it using \u003ccode\u003eCameraCharacteristics.FLASH_INFO_AVAILABLE\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUse \u003ccode\u003eConfig.FlashMode.TORCH\u003c/code\u003e to enable the flash and \u003ccode\u003eConfig.FlashMode.OFF\u003c/code\u003e to disable it within the AR session configuration.\u003c/p\u003e\n"],["\u003cp\u003eAttempting to enable the flash on an unsupported camera configuration will have no adverse effect.\u003c/p\u003e\n"]]],["To use the device's flash in an AR session, first verify if the current camera configuration supports it using `CameraCharacteristics.FLASH_INFO_AVAILABLE`. If available, enable the flash by setting the AR session's configuration to `Config.FlashMode.TORCH`. This is done through a camera manager service. If not available setting it will have no effect. To disable the flash, set the session's configuration to `Config.FlashMode.OFF`. Code examples in both Java and Kotlin are provided.\n"],null,["# Use the device's flash unit on Android SDK (Kotlin/Java)\n\n\u003cbr /\u003e\n\nEnabling the device's flash unit during an AR session can help improve\nvisibility.\n\nCheck that the current camera configuration supports flash\n----------------------------------------------------------\n\nNot all camera configurations support enabling a flash unit.\nBefore enabling the flash or offering users the option to enable the flash,\nensure that the flash unit is available for the active camera\nconfiguration: \n\n### Java\n\n```java\nboolean flashAvailable;\ntry {\n CameraManager cameraManager =\n (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);\n\n CameraCharacteristics characteristics =\n cameraManager.getCameraCharacteristics(session.getCameraConfig().getCameraId());\n flashAvailable = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);\n} catch (Exception e) {\n flashAvailable = false;\n}\n```\n\n### Kotlin\n\n```kotlin\nval flashAvailable =\n runCatching {\n val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager\n val characteristics = cameraManager.getCameraCharacteristics(session.cameraConfig.cameraId)\n characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)\n }\n .getOrNull() ?: false\n```\n\nEnable the flash unit\n---------------------\n\nEnable the flash unit by configuring the AR session with\n[`Config.FlashMode.TORCH`](/ar/reference/java/com/google/ar/core/Config.FlashMode): \n\n### Java\n\n```java\nif (flashAvailable) {\n Config config = session.getConfig();\n config.setFlashMode(Config.FlashMode.TORCH);\n session.configure(config);\n}\n```\n\n### Kotlin\n\n```kotlin\nif (flashAvailable) {\n session.configure(session.config.apply { flashMode = Config.FlashMode.TORCH })\n}\n```\n| **Note:** Configuring [`Config.FlashMode.TORCH`](/ar/reference/java/com/google/ar/core/Config.FlashMode) with a camera configuration that does not support a flash unit will have no effect.\n\nDisable the flash unit\n----------------------\n\nDisable the flash unit by configuring the AR session with\n[`Config.FlashMode.OFF`](/ar/reference/java/com/google/ar/core/Config.FlashMode): \n\n### Java\n\n```java\nConfig config = session.getConfig();\nconfig.setFlashMode(Config.FlashMode.OFF);\nsession.configure(config);\n```\n\n### Kotlin\n\n```kotlin\nsession.configure(session.config.apply { flashMode = Config.FlashMode.OFF })\n```"]]