HarmonyOS 点击推送通知显示无法打开此链接

如题 是缺少什么配置吗

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

参考此demo:

import Notification from '@ohos.notificationManager';
import wantAgent from '@ohos.app.ability.wantAgent';
import { WantAgent } from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct InputPage {
  @State message: string = 'Hello World';


  notification(message:string) {

    let wantAgentObj:WantAgent | undefined = undefined// 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。

    // 通过WantAgentInfo的operationType设置动作类型
    let wantAgentInfo:wantAgent.WantAgentInfo = {
      wants: [
        {
          deviceId: '',
          bundleName: 'com.example.application',
          abilityName: 'EntryAbility',
          action: '',
          entities: [],
          uri: '',
          parameters: {}
        }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
    };

    // 创建WantAgent
    wantAgent.getWantAgent(wantAgentInfo, (err:BusinessError, data:WantAgent) => {
      if (err) {
        console.error(`Failed to get want agent. Code is ${err.code}, message is ${err.message}`);
        return;
      }
      console.info('Succeeded in getting want agent.');
      wantAgentObj = data;
      let notificationRequest: Notification.NotificationRequest  = {
        id: 1,
        content: {
          notificationContentType:Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
          normal: {
            title: "通知测试",
            text: message,
          }
        },
        notificationSlotType:Notification.SlotType.SOCIAL_COMMUNICATION,
        wantAgent: wantAgentObj
      }

      Notification.requestEnableNotification().then(() => {
        Notification.publish(notificationRequest).then(() =>{
          console.log("发布成功")
        }).catch((err: BusinessError) => {
          console.error(`publish:${err}`)
        })
      }).catch((err: BusinessError) => {
        console.error(`${err}`)
      })
    });
  }

  build() {
    Column(){
      Button('发布通知').onClick(() => {
        this.notification("这是一个通知")
      })
    }
  }
}

服务端推送配置abilityName:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/notification-with-wantagent-V5#开发步骤

分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS 无法收到推送通知
48浏览 • 1回复 待解决
HarmonyOS 推送通知
63浏览 • 1回复 待解决
如何做到点击通知消息打开应用
541浏览 • 1回复 待解决
来电横幅通知头像无法显示
1814浏览 • 1回复 待解决
HarmonyOS 推送通知支持图文吗
51浏览 • 1回复 待解决
HarmonyOS 通知推送解决方案
88浏览 • 1回复 待解决
HarmonyOS系统如何实现推送通知
179浏览 • 0回复 待解决
HarmonyOS 企业内部应用推送通知
48浏览 • 1回复 待解决
怎么获取是否开启推送通知栏权限
2480浏览 • 1回复 待解决
HarmonyOS 无法接收推送数据
58浏览 • 1回复 待解决
HarmonyOS web加载链接显示效果异常
40浏览 • 1回复 待解决