创建状态栏通知代码如下:
let notificationRequest: notificationManager.NotificationRequest = {
id: 1,
notificationSlotType: notificationManager.SlotType.CONTENT_INFORMATION,
content: {
notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知
normal: {
title: 'xxx',
text: getuiPushEntity.newsTitle,
}
}
};
notificationManager.publish(notificationRequest, (err:Base.BusinessError) => {
if (err) {
console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in publishing notification.');
});
场景一:创建拉起UIAbility的WantAgent的WantAgentInfo信息。这里主要是点击通知后进入对应app的功能,用于拉起应用的场景。
场景二:创建发布公共事件的WantAgent的WantAgentInfo信息。这里主要是发送事件通知的场景,如果该应用订阅了对应的通知事件,则会执行订阅事件的回调。