Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
通知用户
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用扩展程序 Notifications API 将消息发布到用户的系统托盘。
首先,在 manifest.json 中声明 "notifications" 权限。
{
"name" : "Drink Water Event Popup" ,
...
"permissions" : [
"notifications" ,
],
...
}
声明权限后,通过调用 notifications.create() 显示通知。以下示例摘自“喝水”事件弹出式窗口 示例。它会使用闹钟来设置喝一杯水的提醒。此代码显示了闹钟的触发。点击上一个链接,了解如何设置此功能。
chrome . alarms . onAlarm . addListener (() = > {
chrome . action . setBadgeText ({ text : '' });
chrome . notifications . create ({
type : 'basic' ,
iconUrl : 'stay_hydrated.png' ,
title : 'Time to Hydrate' ,
message : "Everyday I'm Guzzlin'!" ,
buttons : [{ title : 'Keep it Flowing.' }],
priority : 0
});
});
此代码会在 macOS 上创建如下所示的通知。
macOS 上的一条通知。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-02-15。
[[["易于理解","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):2024-02-15。"],[],[]]