自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
實作觸覺回饋
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
裝置製造商通常會被視為為每部裝置建立的私人資產擁有者。因此,他們的工程工作通常著重於個別裝置,對生態系統中其他裝置的一致性則幾乎不做任何努力。
相反地,開發人員會盡力建構可在生態系統中所有 Android 手機上運作的應用程式,無論每部裝置的技術規格為何都沒問題。這種方法上的差異可能會導致分散化問題,例如某些手機的硬體功能不符合應用程式開發人員設定的預期。因此,如果觸覺回饋 API 在某些 Android 手機上運作,但在其他手機上無法運作,就會導致生態系統不一致。因此,硬體設定在確保製造商可在每部裝置上實作 Android 觸覺回饋 API 方面,扮演著至關重要的角色。
本頁面提供逐步檢查清單,協助您設定硬體相容性,以便充分運用 Android 觸覺回饋 API。
下圖說明如何在裝置製造商和開發人員之間建立共同知識,這是建立完整生態系統的重要步驟:
圖 1. 協助裝置製造商和開發人員建立知識
觸覺回饋實作檢查清單
實作常數
實作原始物件
在 HAL 和 API 之間對應常數
- 建議您在公開 API 常數 (在架構中稱為「預留位置」) 和 HAL 常數之間建立對應關係,以便實作預留位置。
- 如要進一步瞭解這項程序,請參閱「設計原則,可用於引導建議的對應方式」。
實作區塊線性包絡 (PWLE) 效果
評估硬體
- 指定觸覺回饋效果的操作說明。請按照以下操作說明快速檢查硬體。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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-27 (世界標準時間)。"],[],[],null,["# Implement haptics\n\nDevice manufacturers are generally considered the owners of the private assets\ncreated for each device. As such, their engineering efforts are often focused on\na *per-device basis*; little to no effort goes to the consistency of other\ndevices in the ecosystem.\n\nIn direct contrast, developers strive to build apps that work on *all* Android\nphones in the ecosystem, regardless of each device's technical specifications.\nThis difference in approach can cause a fragmentation problem, for example, the\nhardware capabilities of certain phones don't match expectations set by the app\ndevelopers. So if the haptics APIs work on some Android phones but not others,\nthe result is an inconsistent ecosystem. This is why hardware configuration\nplays a critical role in ensuring that manufacturers can implement Android\nhaptics APIs on *every* device.\n\nThis page provides a step-by-step checklist to set up hardware compliance for\nthe best use of the Android haptics APIs.\n\nThe following figure illustrates building common knowledge between device\nmanufacturers and developers, which is a critical step in creating a cohesive\necosystem:\n\n**Figure 1.** Building knowledge between device manufacturers and developers\n\nHaptics implementation checklist\n--------------------------------\n\n1. [Implement constants](/docs/core/interaction/haptics/haptics-constants-primitives#implement-constants)\n\n - List of constants to implement haptics.\n2. [Implement primitives](/docs/core/interaction/haptics/haptics-constants-primitives#implement-primitives)\n\n - Implementation guidance for HAL composition primitives.\n3. [Map constants between HAL and API](/docs/core/interaction/haptics/haptics-map-constants)\n\n - Mapping recommendations between public API constants (named *placeholders* in the framework) and HAL constants, which implement the placeholders.\n - See [Design principles to guide the recommended mapping](/docs/core/interaction/haptics/haptics-ux-design) to learn more about this process.\n4. [Implement piecewise linear envelope (PWLE) effects](/docs/core/interaction/haptics/haptics-pwle)\n\n - Implementation guidance for amplitude and frequency envelopes.\n5. [Assess the hardware](/docs/core/interaction/haptics/haptics-assess-hardware)\n\n - Instructions on target haptic effects. Use these instructions to perform quick checks on your hardware.\n\n| **Note:** You can learn more about building common knowledge between device manufacturers and developers in [Advanced Haptics: The When, What, and How of\n| Haptic APIs](https://www.youtube.com/watch?v=00jRoEFnpk8)."]]