自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
手電筒強度控制
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
對於搭載 Android 13 以上版本的裝置,Android 架構會提供多層控制項,用於調整手電筒的亮度。在 Android 12 以下版本中,架構只允許開啟或關閉手電筒模式。透過支援多層手電筒強度控制,裝置可啟用多種用途,例如根據光線條件控制手電筒的亮度,以及透過連續發送快速脈衝光線,使用閃爍效果傳送信號。這項功能的另一個好處是,它可以改善電池續航力和效能,因為手電筒模式不必一律以最大強度開啟,否則可能會導致熱力節流。
公用 API
應用程式可以透過下列公開 API 和相機特性鍵使用手電筒亮度控制功能。這些 API 不需要相機權限,因為系統不會存取相機。
CameraManager API
CameraCharacteristics 鍵
實作
如要在裝置上支援手電筒強度控制功能,請使用下列相機 AIDL HAL 介面:
位置:/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl
請確認 HAL 實作項目宣告下列相機特性鍵,以支援手電筒亮度控制功能:
如需支援手電筒強度控制功能的相機 HAL 參考實作方式,請參閱 EmulatedCameraDeviceHWLImpl.cpp
。
驗證
如要驗證手電筒強度控制功能的實作方式,請執行下列 VTS 和 CTS 測試:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Torch strength control\n\nFor devices running Android 13 or higher, the Android\nframework provides a multilevel control for torch strength. In\nAndroid 12 and lower, the framework allows only for\nturning the torch mode on or off. By supporting multilevel torch strength\ncontrol, devices can enable use cases such as controlling the brightness of the\nflashlight based on lighting conditions and sending signals for assistance\nusing a strobe effect by sending quick pulses of light in a row. Another\nbenefit of this feature is that it can improve battery life and performance as\nthe torch mode doesn't always need to be turned on at the maximum strength,\nwhich can lead to thermal throttling conditions.\n\nPublic APIs\n-----------\n\nApps can use the torch strength control feature through the following public\nAPIs and camera characteristics keys. No camera permissions are required for\nthese APIs because the camera isn't accessed.\n\n#### CameraManager APIs\n\n- [`public void turnOnTorchWithStrengthLevel (String cameraId, int torchStrength)`](https://developer.android.com/reference/android/hardware/camera2/CameraManager#turnOnTorchWithStrengthLevel(java.lang.String,%20int)): Sets the brightness level of the flashlight associated with the given `cameraId` value in torch mode. If torch mode is off and `torchStrength` is greater than or equal to `1`, the torch turns on with the strength level specified in `torchStrength`.\n- [`public int getTorchStrengthLevel (String cameraId)`](https://developer.android.com/reference/android/hardware/camera2/CameraManager#getTorchStrengthLevel(java.lang.String)): Returns the brightness level of the flash unit associated with `cameraId`.\n\n#### CameraCharacteristics keys\n\n- [`FLASH_INFO_STRENGTH_MAXIMUM_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_MAXIMUM_LEVEL): Maximum brightness level. The camera HAL advertises this feature by setting a value greater than `1`.\n- [`FLASH_INFO_STRENGTH_DEFAULT_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL): Default flashlight brightness level.\n\nImplementation\n--------------\n\nTo support the torch strength control feature on your device, use the following\ncamera AIDL HAL interfaces:\n\nLocation: `/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl`\n\n- [`void turnOnTorchWithStrengthLevel(int torchStrength)`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl?q=turnOnTorchWithStrengthLevel)\n- [`int getTorchStrengthLevel()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl?q=getTorchStrengthLevel)\n\nEnsure your HAL implementation advertises the following camera characteristics\nkeys to support the torch brightness control feature:\n\n- [`FLASH_INFO_STRENGTH_MAXIMUM_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_MAXIMUM_LEVEL)\n- [`FLASH_INFO_STRENGTH_DEFAULT_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL)\n\nFor a reference Camera HAL implementation supporting torch strength control,\nsee\n[`EmulatedCameraDeviceHWLImpl.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/google/camera/devices/EmulatedCamera/hwl/EmulatedCameraDeviceHWLImpl.cpp).\n\nValidation\n----------\n\nTo validate your implementation of the torch strength control feature, run the\nfollowing VTS and CTS tests:\n\n- VTS: [`/camera/provider/aidl/vts/VtsAidlHalCameraProvider\\_TargetTest.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp)\n- CTS: [`/platform/cts/tests/camera/src/android/hardware/camera2/cts/FlashlightTest.java`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/camera/src/android/hardware/camera2/cts/FlashlightTest.java)"]]