You need to sign in or sign up before continuing.
faqs-event-notification.md 1.4 KB
Newer Older
E
esterzhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Common Event and Notification Development

## What is the emitter data size limit?

Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9

The emitter data size cannot exceed 10240.

## How do I implement the click-a-notification-to-open-an-application function?

Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9

You can implement this function by setting the **wantAgent** attribute in the **NotificationRequest** parameter of the **Notification.publish** API.

Reference: [Notification](../reference/apis/js-apis-notification.md#notificationpublish) and [WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md)

Example:

E
ester.zhou 已提交
19
```ts
E
esterzhou 已提交
20 21 22 23 24 25
import WantAgent from '@ohos.wantAgent';

async function publishNotification() {
  let wantAgentInfo = {
    wants: [
      {
E
ester.zhou 已提交
26 27
        bundleName: "com.example.myapplication",
        abilityName: "EntryAbility",
E
esterzhou 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
  }
  const wantAgent = await WantAgent.getWantAgent(wantAgentInfo)
  let contentType = Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT;
  await Notification.publish({
    content: {
      contentType: contentType,
      normal: {
        title: "Test Title",
        text: "Test content",
      }
    },
    id: 1,
    wantAgent: wantAgent
  })
  prompt.showToast ({ message: "Sent successfully." })
}
```