• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 公共事件与通知开发常见问题
2
3## emitter数据大小限制
4
5适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
6
7emitter数据大小限制不超过10240。
8
9## 如何实现点击Notification通知打开对应App
10
11适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
12
13通过配置Notification.publish发布通知接口的参数NotificationRequest中wantAgent属性实现
14
15参考文档:[Notification](../reference/apis/js-apis-notification.md#notificationpublish)、[WantAgent](../reference/apis/js-apis-wantAgent.md)
16
17示例:
18
19```
20import WantAgent from '@ohos.wantAgent';
21
22async function publishNotification() {
23  let wantAgentInfo = {
24    wants: [
25      {
26        bundleName: "com.example.notification",
27        abilityName: "MainAbility",
28      }
29    ],
30    operationType: WantAgent.OperationType.START_ABILITIES,
31    requestCode: 0,
32  }
33  const wantAgent = await WantAgent.getWantAgent(wantAgentInfo)
34  let contentType = Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT;
35  await Notification.publish({
36    content: {
37      contentType: contentType,
38      normal: {
39        title: "测试标题",
40        text: "测试内容",
41      }
42    },
43    id: 1,
44    wantAgent: wantAgent
45  })
46  prompt.showToast({ message: "发送成功" })
47}
48```
49