自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
节流和抑制通知
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
为了减少驾车时分心的情况,浮动通知 (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
数组中。
节流和节奏
如果当用户执行某项操作时(例如与 Google 助理或拨号器互动),显示 HUN 会造成不安全或分心的情况,您可以限制 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
指定为从通知发布到通知过期的时间长度(以毫秒为单位)。
对于停车状态:
- 将
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 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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`."]]