Notification API 列表

本模块包含 22 个 API。

Events(事件)

API 说明 鸿蒙支持
show 在通知显示给用户时触发。注意,通过 show() 方法可多次显示同一通知,该事件也会多次触发。 支持
click 在用户点击通知时触发。 支持
close 在用户手动关闭通知时触发。 支持
reply 在用户点击带有 hasReply: true 的通知中的「回复」按钮时触发。 不支持
action 在通知的操作按钮被触发时触发。 不支持
failed 在创建或显示原生通知时发生错误时触发。 不支持

Methods(方法)

API 说明 鸿蒙支持
Notification.isSupported() 返回 boolean,表示当前系统是否支持桌面通知。 支持
new Notification([options]) 创建一个新的 Notification 实例。 支持
notification.show() 立即向用户显示通知。与 Web 通知 API 不同,实例化 Notification 对象并不会自动显示通知。 支持
notification.close() 关闭该通知。 支持

Properties(属性)

API 说明 鸿蒙支持
notification.title 字符串属性,表示通知的标题。 支持
notification.subtitle 字符串属性,表示通知的副标题。 支持
notification.body 字符串属性,表示通知的正文内容。 支持
notification.replyPlaceholder 字符串属性,表示通知回复输入框的占位文本。 支持
notification.sound 字符串属性,表示通知的提示音。 支持
notification.closeButtonText 字符串属性,表示通知关闭按钮的文本。 支持
notification.silent 布尔属性,表示通知是否静默(无声)。 支持
notification.hasReply 布尔属性,表示通知是否带有回复操作。 支持
notification.urgency 字符串属性,表示通知的紧急级别,可为 'normal'、'critical' 或 'low'。 不支持
notification.timeoutType 字符串属性,表示通知的超时类型,可为 'default' 或 'never'。 不支持
notification.actions NotificationAction[] 属性,表示通知所包含的操作按钮列表。 支持
notification.toastXml 字符串属性,表示通知自定义的 Toast XML 内容。 不支持