Android SDK (Kotlin/Java)에서 기기의 플래시 장치 사용
AR 세션 중에 기기의 플래시 장치를 사용 설정하면 가시성을 개선하는 데 도움이 될 수 있습니다.
현재 카메라 구성이 플래시를 지원하는지 확인
일부 카메라 구성에서는 플래시 장치 사용 설정을 지원하지 않습니다.
플래시를 사용 설정하거나 사용자에게 플래시를 사용 설정하는 옵션을 제공하기 전에 활성 카메라 구성에서 플래시 장치를 사용할 수 있는지 확인합니다.
boolean flashAvailable;
try {
CameraManager cameraManager =
(CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics =
cameraManager.getCameraCharacteristics(session.getCameraConfig().getCameraId());
flashAvailable = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
} catch (Exception e) {
flashAvailable = false;
}
val flashAvailable =
runCatching {
val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristics = cameraManager.getCameraCharacteristics(session.cameraConfig.cameraId)
characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)
}
.getOrNull() ?: false
플래시 유닛 사용 설정
Config.FlashMode.TORCH
로 AR 세션을 구성하여 플래시 장치를 사용 설정합니다.
if (flashAvailable) {
Config config = session.getConfig();
config.setFlashMode(Config.FlashMode.TORCH);
session.configure(config);
}
if (flashAvailable) {
session.configure(session.config.apply { flashMode = Config.FlashMode.TORCH })
}
플래시 장치 사용 중지
Config.FlashMode.OFF
로 AR 세션을 구성하여 플래시 장치를 사용 중지합니다.
Config config = session.getConfig();
config.setFlashMode(Config.FlashMode.OFF);
session.configure(config);
session.configure(session.config.apply { flashMode = Config.FlashMode.OFF })
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-02-28(UTC)
[null,null,["최종 업데이트: 2025-02-28(UTC)"],[[["Enabling the device's flash during an AR session can enhance visibility in low-light environments."],["Before enabling the flash, verify if the active camera configuration supports it using `CameraCharacteristics.FLASH_INFO_AVAILABLE`."],["Use `Config.FlashMode.TORCH` to enable the flash and `Config.FlashMode.OFF` to disable it within the AR session configuration."],["Attempting to enable the flash on an unsupported camera configuration will have no adverse effect."]]],["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"]]