Flash-Einheit des Geräts unter Android NDK (C) verwenden
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Wenn Sie den Blitz des Geräts während einer AR-Sitzung aktivieren, kann das die Sichtbarkeit verbessern.
Prüfen, ob die aktuelle Kamerakonfiguration den Blitz unterstützt
Nicht alle Kamerakonfigurationen unterstützen die Aktivierung eines Blitzes.
Bevor Sie den Blitz aktivieren oder Nutzern die Möglichkeit dazu geben, prüfen Sie, ob der Blitz für die aktive Kamerakonfiguration verfügbar ist:
// Get the camera ID from the current session.ArCameraConfig*ar_camera_config=NULL;ArCameraConfig_create(ar_session,&ar_camera_config);ArSession_getCameraConfig(ar_session,ar_camera_config);char*camera_id=NULL;ArCameraConfig_getCameraId(ar_session,ar_camera_config,&camera_id);ArCameraConfig_destroy(ar_camera_config);// Get the camera characteristics.ACameraManager*camera_manager=ACameraManager_create();CHECK(camera_manager!=NULL);ACameraMetadata*characteristics=NULL;camera_status_tstatus=ACameraManager_getCameraCharacteristics(camera_manager,camera_id,&characteristics);ArString_release(camera_id);CHECK(status==ACAMERA_OK);CHECK(characteristics!=NULL);// Check if flash is supported.ACameraMetadata_const_entryentry;status=ACameraMetadata_getConstEntry(characteristics,ACAMERA_FLASH_INFO_AVAILABLE,&entry);CHECK(status==ACAMERA_OK);uint32_tis_flash_supported=false;if(entry.count==1 && entry.data.u8[0]==ACAMERA_FLASH_INFO_AVAILABLE_TRUE){is_flash_supported=true;}ACameraManager_delete(camera_manager);
Blitz aktivieren
Aktivieren Sie den Blitz, indem Sie die AR-Sitzung mit AR_FLASH_MODE_TORCH konfigurieren:
[null,null,["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[[["\u003cp\u003eUsing 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 provided code snippets to check for flash availability.\u003c/p\u003e\n"],["\u003cp\u003eEnable the flash by configuring the AR session with \u003ccode\u003eAR_FLASH_MODE_TORCH\u003c/code\u003e and disable it using \u003ccode\u003eAR_FLASH_MODE_OFF\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAlthough attempting to enable flash on unsupported devices won't cause errors, it also won't have any effect on the session.\u003c/p\u003e\n"]]],["To use a flash unit during an AR session, first verify if the current camera configuration supports it. Retrieve the camera's characteristics and check for `ACAMERA_FLASH_INFO_AVAILABLE_TRUE`. If supported, use `ArConfig_setFlashMode` with `AR_FLASH_MODE_TORCH` to enable it and configure the session. To disable, use `AR_FLASH_MODE_OFF` instead. Note that setting the flash mode on an unsupported camera will have no effect.\n"],null,["# Use the device's flash unit on Android NDK (C)\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```c\n// Get the camera ID from the current session.\nArCameraConfig* ar_camera_config = NULL;\nArCameraConfig_create(ar_session, &ar_camera_config);\nArSession_getCameraConfig(ar_session, ar_camera_config);\nchar* camera_id = NULL;\nArCameraConfig_getCameraId(ar_session, ar_camera_config, &camera_id);\nArCameraConfig_destroy(ar_camera_config);\n\n// Get the camera characteristics.\nACameraManager* camera_manager = ACameraManager_create();\nCHECK(camera_manager != NULL);\nACameraMetadata* characteristics = NULL;\ncamera_status_t status = ACameraManager_getCameraCharacteristics(camera_manager, camera_id, &characteristics);\nArString_release(camera_id);\nCHECK(status == ACAMERA_OK);\nCHECK(characteristics != NULL);\n\n// Check if flash is supported.\nACameraMetadata_const_entry entry;\nstatus = ACameraMetadata_getConstEntry(characteristics, ACAMERA_FLASH_INFO_AVAILABLE, &entry);\nCHECK(status == ACAMERA_OK);\nuint32_t is_flash_supported = false;\nif (entry.count == 1 && entry.data.u8[0] == ACAMERA_FLASH_INFO_AVAILABLE_TRUE) {\n is_flash_supported = true;\n}\n\nACameraManager_delete(camera_manager);\n```\n\nEnable the flash unit\n---------------------\n\nEnable the flash unit by configuring the AR session with\n[`AR_FLASH_MODE_TORCH`](/ar/reference/c/group/ar-config#arflashmode): \n\n```c\nArConfig* ar_config = NULL;\nArConfig_create(ar_session, &ar_config);\nArSession_getConfig(ar_session, ar_config);\nif (is_flash_supported) {\n ArConfig_setFlashMode(ar_session, ar_config, AR_FLASH_MODE_TORCH);\n}\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\nArConfig_destroy(ar_config);\n```\n| **Note:** Configuring [`AR_FLASH_MODE_TORCH`](/ar/reference/c/group/ar-config#arflashmode) 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[`AR_FLASH_MODE_OFF`](/ar/reference/c/group/ar-config#arflashmode): \n\n```c\nArConfig* ar_config = NULL;\nArConfig_create(ar_session, &ar_config);\nArSession_getConfig(ar_session, ar_config);\nif (is_flash_supported) {\n ArConfig_setFlashMode(ar_session, ar_config, AR_FLASH_MODE_OFF);\n}\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\nArConfig_destroy(ar_config);\n```"]]