diff --git a/en/application-dev/notification/common-event.md b/en/application-dev/notification/common-event.md index cd139f0700d01475ad7f6fb358744e52ffafb913..2b048cbfc552920661c973fd08744bb18726e654 100644 --- a/en/application-dev/notification/common-event.md +++ b/en/application-dev/notification/common-event.md @@ -13,7 +13,7 @@ Each application can subscribe to common events as required. After your applicat ## Common Event Subscription Development ### When to Use -You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md). +You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md#required-permissions). ### Available APIs | API | Description| @@ -170,10 +170,8 @@ if (this.subscriber != null) { } ``` -## Development Example +## Samples The following sample is provided to help you better understand how to use the common event functionality: -- [CommonEvent](https://gitee.com/openharmony/app_samples/tree/master/ability/CommonEvent) - -This sample shows how to use **CommonEvent** APIs in Extended TypeScript (eTS) to create subscribers and subscribe to, publish, and unsubscribe from common events. +- [`CommonEvent`: eTS Common Event (API 8)](https://gitee.com/openharmony/app_samples/tree/master/Notification/CommonEvent) diff --git a/en/application-dev/notification/notification.md b/en/application-dev/notification/notification.md index a8822563cd639844817b860fb5760ee605edb307..9a440cb44441014f64a8aae6d87f8be2e2401c77 100644 --- a/en/application-dev/notification/notification.md +++ b/en/application-dev/notification/notification.md @@ -131,13 +131,25 @@ var subscriber = { ### Publishing Notifications -Before publishing a notification, make sure the notification feature is enabled for your application. This feature is disabled by default and can be enabled in the notification settings. +##### Enabling Notification + +Before publishing a notification, check whether the notification feature is enabled for your application. By default, the feature is disabled. The application calls **Notification.requestEnableNotification** to prompt the user to enable the feature. + +```js +Notification.requestEnableNotification() .then((data) => { + console.info('===>requestEnableNotification success'); +}).catch((err) => { + console.error('===>requestEnableNotification failed because ' + JSON.stringify(err)); +}); +``` + + ##### Publishing Notifications To publish a notification, create a **NotificationRequest** object and set attributes such as the notification type, title, and content. In the following examples, a normal text notification and a notification containing a **WantAgent** are being published. -Normal Text Notification +Normal text notification: ```js // Create a NotificationRequest object. @@ -163,7 +175,7 @@ Notification.publish(notificationRequest) .then((data) => { -Notification Containing WantAgent. +Notification containing **WantAgent**: For details about how to use **WantAgent**, see [WantAgent Development](https://gitee.com/openharmony/docs/blob/master/en/application-dev/ability/wantagent.md). @@ -234,7 +246,7 @@ Notification.publish(notificationRequest) .then((data) => { - Cancel the notification. -An application can cancel a single notification or all notifications. An application can cancel only the notifications published by itself. + An application can cancel a single notification or all notifications. An application can cancel only the notifications published by itself. ```js // cancel callback @@ -246,3 +258,8 @@ Notification.cancel(1, "label", cancelCallback) ``` +## Samples + +The following sample is provided to help you better understand how to develop notification functions: + +[`Notification`: Notification (eTS, API 8)](https://gitee.com/openharmony/app_samples/tree/master/common/Notification) \ No newline at end of file