自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
通知历史记录
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通知历史记录是一个设备界面,用户可以在该界面中查看延后的通知、近期关闭的一些通知,以及关于前一天通知的历史记录。OEM 可以选择实现此功能,这不会对 SoC 或运营商产生任何影响。
通知历史记录界面旨在解决以下用例:
- 意外关闭:您不小心关闭了通知,但想要快速查看通知内容。
- 延后的通知:您延后了通知,但希望在延后期限结束前查看通知。
- 问题排查:您认为自己遗漏了某条通知。您可以查看通知历史记录界面,以确定是否有通知,以及是否漏掉了通知。如果未找到通知,请查看通知是否被屏蔽。您可以在通知历史记录界面中更改通知设置。
- 通知管理:如果您希望更改通知的干扰程度,可以使用通知历史记录界面,因为其中会显示每日通知负载的实际细分,便于您轻松了解对警报、屏蔽等的更改范围。
以下是这些通知历史记录界面组件的可用参考实现:
- 设置:
packages/apps/Settings/src/com/android/settings/notification/history
- 系统服务器:
com.android.server.notification.NotificationHistory.*.java
以下是实现通知历史记录界面的主要步骤:
- 将通知事件写入日志。
- 将入口点添加到日志中,并添加开启/关闭该日志的设置。
- 实现通知历史记录界面。
用户可以关闭通知历史记录界面。关闭后,所有历史记录项都会被删除,并且不会写入日志。
您可以使用 NotificationHistoryDatabase
类中的 HISTORY_RETENTION_DAYS
常量设置通知在通知历史记录界面中显示的天数。此外,您还可以修改通知历史记录界面中显示的内容区以及数据的呈现方式。
默认的通知历史记录保留期限为 24 小时。
针对代码的每个组件提供以下单元测试:
- 系统服务器单元测试:
FrameworksUiServicesTests
- 设置单元测试:
make -j64 RunSettingsRoboTests
ROBOTEST_FILTER="com.android.settings.notification"
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-04。
[null,null,["最后更新时间 (UTC):2025-04-04。"],[],[],null,["# Notification history is a device screen where users can see snoozed\nnotifications, a handful of recently dismissed notifications, and a history of\nthe last day of notifications. It is an optional feature for OEMs to implement.\nThere's no impact on SoCs or carriers.\n\nNotification history is meant to address these use cases:\n\n- **Accidental dismissal**: You accidentally dismissed a notification and want to get a quick look at what it was.\n- **Snoozed notifications**: You snoozed a notification but want to see it before the snooze period is over.\n- **Troubleshooting**: You think you missed a notification. You check the notification history to see whether there was a notification and whether it buzzed. If you don't find it, you check whether a notification was blocked. You can change notification settings in notification history.\n- **Notification management**: You want to change how interruptive notifications are, so you use notification history because it offers a realistic slice of daily notification load, which makes it easy to understand the scope of your changes to alerting, blocking. etc.\n\nReference implementations of these components of Notification History are\navailable:\n\n- **Settings** : `packages/apps/Settings/src/com/android/settings/notification/history`\n- **System server** : `com.android.server.notification.NotificationHistory.*.java`\n\nThese are the major steps to implement Notification History:\n\n- Write notification events to the log.\n- Add entry points to the log and the setting to turn it on and off.\n- Implement the Notification History screen.\n\nUsers can turn Notification History off. When it's off, all history items are\ndeleted and no items are written to the log.\n\nYou can set the number of days notifications appear in the Notification\nHistory using the `HISTORY_RETENTION_DAYS` constant in the\n`NotificationHistoryDatabase` class. You can also modify which\nsections appear in the Notification History screen and how the data is\npresented.\n\nThe default notification history retention period is 24 hours.\n\nThese unit tests are provided for each component of the code:\n\n- **System server unit tests** : `FrameworksUiServicesTests`\n- **Settings unit tests** : `make -j64 RunSettingsRoboTests\n ROBOTEST_FILTER=\"com.android.settings.notification\"`"]]