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

如题 是缺少什么配置吗

HarmonyOS
2024-12-23 16:07:30
792浏览
收藏 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("这是一个通知")
      })
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.

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

分享
微博
QQ
微信
回复
2024-12-23 20:01:07


相关问题
HarmonyOS 无法收到推送通知
921浏览 • 1回复 待解决
HarmonyOS 推送通知
797浏览 • 1回复 待解决
如何做到点击通知消息打开应用
1379浏览 • 1回复 待解决
来电横幅通知头像无法显示
2395浏览 • 1回复 待解决
HarmonyOS 通知推送解决方案
1158浏览 • 1回复 待解决
HarmonyOS 推送通知支持图文吗
607浏览 • 1回复 待解决
HarmonyOS系统如何实现推送通知
850浏览 • 0回复 待解决
HarmonyOS 企业内部应用推送通知
819浏览 • 1回复 待解决
HarmonyOS 推送无法收到
746浏览 • 1回复 待解决
HarmonyOS 推送突然无法接收
570浏览 • 1回复 待解决