HarmonyOS 创建的状态栏通知点击事件两种场景如何区分创建?

创建状态栏通知代码如下:

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.');
       });
阅读 558
1 个回答

场景一:创建拉起UIAbility的WantAgent的WantAgentInfo信息。这里主要是点击通知后进入对应app的功能,用于拉起应用的场景。

场景二:创建发布公共事件的WantAgent的WantAgentInfo信息。这里主要是发送事件通知的场景,如果该应用订阅了对应的通知事件,则会执行订阅事件的回调。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进