自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
節流和抑制通知
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為了減少駕駛時的干擾,抬頭通知 (HUN) 會為駕駛人提供重要且相關的資訊,不必將注意力轉移到螢幕或行動裝置。不過,由於 HUN 可能會干擾駕駛工作,因此務必考量 HUN 的優缺點,確保駕駛人不會分心。
請使用下列 Android 通知專屬安全功能,減少駕駛人分心的情況:
本文將說明與 platform/packages/apps/Car/Notification
相關的設定和資源。
排隊和優先處理
收到多個 HUN 時,排隊和優先順序機制會向駕駛人顯示最重要的相關資訊。
如要啟用或停用佇列機制,請為 config_suppressAndThrottleHeadsUp config
設定布林值。
排入佇列的 HUN 會依據通知的類別決定的優先順序排序。依優先順序倒序指定 headsup_category_priority
陣列。
部分具時效性的通知 (例如 CATEGORY_CALL
和 CATEGORY_CAR_EMERGENCY
) 應立即顯示,而非排入佇列。
如要立即顯示這些類型的 HUN,請將這些類別新增至 headsup_category_immediate_show
陣列。
節流和速度
當使用者執行某些動作時,如果顯示 HUN 會造成危險或干擾,例如與 Google 助理或撥號應用程式互動,您可以調節 HUN。
如要採用節流功能,請將需要注意的應用程式套件名稱加入許可清單 (headsup_throttled_foreground_packages
)。這樣一來,當指定應用程式在前景執行時,佇列就不會顯示新的 HUN。
為讓駕駛人能專注於駕駛,請在每個 HUN 顯示畫面之間加入時間間隔。此時間間隔 (headsup_delay_duration
) 會在 headsup_throttled_foreground_packages
的套件移至背景後套用。
抑制
長期處於佇列中的 HUN 可能會遭到抑制。如果 HUN 與駕駛者無關,可能會造成分心。請將過期通知直接傳送至通知中心,而非觸發 HUN。您可以為行駛和停車狀態指定不同的值,以便調整 HUN 管理方式。
針對「雲端硬碟」狀態:
- 將
config_expireHeadsUpWhenDriving
設為 true
,並將 headsup_queue_expire_driving_duration_ms
設為通知到期時間後的持續時間 (以毫秒為單位)。
針對「Park」狀態:
- 將
config_expireHeadsUpWhenParked
設為 true
,並將 headsup_queue_expire_parked_duration_ms
設為通知到期時間後的時間長度 (以毫秒為單位)。
在發生抑制事件時,請傳送尾隨系統 HUN 通知驅動程式。更新 hun_suppression_notification_title_drive
和 hun_suppression_notification_title_park
的值,修改此通知的標題
如要在開啟通知中心時自動關閉 HUN 待播清單,請按照下列步驟操作:
- 將
config_dismissHeadsUpWhenNotificationCenterOpens
布林值設為 true
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-03-25 (世界標準時間)。
[[["容易理解","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-03-25 (世界標準時間)。"],[],[],null,["# Throttle and suppress notifications\n\nTo reduce distraction while driving,\n[heads-up notifications](/docs/automotive/hmi/notifications/hun)\n(HUN) provide drivers with essential and relevant information **without**\ndiverting their attention to a display or mobile device. However, since HUNs\n*can* interfere with the task of driving, it's crucial to consider\nthe advantages and disadvantages of HUNs to ensure drivers are **not**\ndistracted.\n\nUse these Android notification-specific safety features to reduce driver\ndistraction:\n\n- [Queue and prioritize](#queue)\n- [Throttle and pace](#pace)\n- [Suppression](#suppress)\n\nThis content describes configurations and resources that pertain to\n`platform/packages/apps/Car/Notification`.\n\nQueue and prioritize\n--------------------\n\nWhen multiple incoming HUNs are received, the *queue and prioritize* mechanism\ndisplays the most important and relevant information to the driver.\n\nTo enable or disable the queue mechanism, set the boolean value for the\n`config_suppressAndThrottleHeadsUp config`.\n\nQueued HUNs are sorted based on priority determined by the\n[category](https://developer.android.com/reference/android/app/Notification#category)\nof the notification. Specify the `headsup_category_priority` array in a\ndescending order of priority.\n\nSome time-sensitive notifications, such as `CATEGORY_CALL` and\n`CATEGORY_CAR_EMERGENCY`, should be displayed immediately instead of queued.\n\nTo immediately display these types of HUNs, add these categories to the\n`headsup_category_immediate_show` array.\n\nThrottle and pace\n-----------------\n\nWhen a user performs an action during which it would be unsafe or distracting to\nshow HUNs, such as interacting with Assistant or Dialer, you can *throttle*\nHUNs.\n\nTo employ throttling, add the package names of apps that require attention to\nthe allowlist (`headsup_throttled_foreground_packages`). This stops the queue\nfrom displaying new HUNs while the specified apps run in the foreground.\n\nTo give drivers time to focus on driving, add a time interval between the\ndisplay of each HUN. This time interval (`headsup_delay_duration`)\napplies after packages from `headsup_throttled_foreground_packages` are\nmoved to the background.\n\nSuppression\n-----------\n\nHUNs that remain in the queue for an extended period can be *suppressed.*\nWhen HUNs become irrelevant to the driver, they can cause distraction.\nInstead of triggering a HUN, direct expired notifications to the\nNotification center.\nYou can tailor your management of HUNs by prescribing different values for the\n**Drive** and **Park** states.\n\nFor the **Drive** state:\n\n1. Set `config_expireHeadsUpWhenDriving` to `true` and specify the `headsup_queue_expire_driving_duration_ms` as the duration (in milliseconds) after the post time when the notification is to expire.\n\nFor the **Park** state:\n\n1. Set `config_expireHeadsUpWhenParked` to `true` and specify the `headsup_queue_expire_parked_duration_ms`as the duration (in milliseconds) after the post time when the notification is to expire.\n\nIn the event of a suppression, send a trailing system HUN to notify the\ndriver. Modify the title of this notification by updating the values of\n`hun_suppression_notification_title_drive` and\n`hun_suppression_notification_title_park`\n\nTo automatically dismiss the HUN queue when the Notification center is opened:\n\n1. Set the `config_dismissHeadsUpWhenNotificationCenterOpens` boolean to `true`."]]