OpenHarmony开发者论坛

标题: 如何实现点击Notification通知打开App功能? [打印本页]

作者: 梦里啥都有    时间: 2023-9-14 09:22
标题: 如何实现点击Notification通知打开App功能?
[md]【问题描述】

接收到来自其他人的通信或来自应用的其他即时信息提醒,用户可以点击Notification通知打开相应App,在OpenHarmony如何实现?

【运行环境】

硬件:rk3568;  ROM: 3.2  ;  API 9

[/md]
作者: 海浪漂啊漂    时间: 2023-9-18 19:42
[md]通过配置Notification.publish发布通知接口的参数NotificationRequest中wantAgent属性实现

```
import notificationManager from '@ohos.notificationManager';

import WantAgent from '@ohos.app.ability.wantAgent';


async function publishNotification() {

  let wantAgentInfo = {

    wants: [

      {

        bundleName: "com.example.webuseragent", // 自己应用的bundleName

        abilityName: "EntryAbility",

      }

    ],

    operationType: WantAgent.OperationType.START\_ABILITIES,

    requestCode: 1,

  }

  const wantAgent = await WantAgent.getWantAgent(wantAgentInfo)

  let contentType = notificationManager.ContentType.NOTIFICATION\_CONTENT\_BASIC\_TEXT;

  await notificationManager.publish({

    content: {

      contentType: contentType,

      normal: {

        title: "测试标题",

        text: "测试内容",

      }

    },

    id: 1,

    wantAgent: wantAgent

  })

}
```

[/md]




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5