diff --git a/en/application-dev/notification/notification.md b/en/application-dev/notification/notification.md index 1572f0e3a6e570c301447ff863ead0757d8396dc..a8822563cd639844817b860fb5760ee605edb307 100644 --- a/en/application-dev/notification/notification.md +++ b/en/application-dev/notification/notification.md @@ -131,33 +131,7 @@ var subscriber = { ### Publishing Notifications -Before publishing a notification, check whether the notification feature is enabled for the respective application. By default, the feature is disabled for newly installed apps. - -##### Enabling Notification - -Check whether notification is enabled. - -```js -var bundle = { - bundle: "bundleName1", -} -Notification.isNotificationEnabled(bundle).then((data) => { - console.info("===>isNotificationEnabled success===>"); -}); -``` - -If the check result is **false**, notification is disabled. In this case, enable it. - -```js -var bundle = { - bundle: "bundleName1", -} -Notification.enableNotification(bundle, true, async(err) => { - console.log("===>enableNotification success===>"); -}); -``` - - +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. ##### Publishing Notifications @@ -170,7 +144,7 @@ Normal Text Notification var notificationRequest = { id: 1, content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: "test_title", text: "test_text", @@ -197,25 +171,18 @@ For details about how to use **WantAgent**, see [WantAgent Development](https:// ```js import wantAgent from '@ohos.wantAgent'; -import { OperationType, Flags } from '@ohos.wantagent'; // WantAgentInfo object var wantAgentInfo = { - wants: [ - { - deviceId: 'deviceId', - bundleName: 'com.example.myapplication', - abilityName: 'com.example.myapplication.MainAbility', - action: 'REMINDER_EVENT_REMOVE_NOTIFICATION', - entities: ['entity1'], - type: 'MIMETYPE', - uri: 'key={true,true,false}', - parameters: { myKey0: 1111 }, - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] + wants: [ + { + bundleName: 'ohos.samples.eTSNotification', + abilityName: 'ohos.samples.eTSNotification.MainAbility', + } + ], + operationType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] } // WantAgent object @@ -241,7 +208,7 @@ wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) // Create a NotificationRequest object. var notificationRequest = { content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: "AceApplication_Title", text: "AceApplication_Text", @@ -251,7 +218,7 @@ var notificationRequest = { id: 1, label: 'TEST', wantAgent: WantAgent, - slotType: notify.SlotType.OTHER_TYPES, + slotType: Notification.SlotType.OTHER_TYPES, deliveryTime: new Date().getTime() } @@ -279,11 +246,3 @@ Notification.cancel(1, "label", cancelCallback) ``` - -## Development Example - -The following sample is provided to help you better understand how to develop notification functions: - -- notification - -This sample shows how to use **Notification** APIs in Extended TypeScript (eTS) to subscribe to, unsubscribe from, publish, and cancel notifications as well as enable the notification feature and check whether the feature is enabled. diff --git a/en/application-dev/reference/apis/js-apis-notification.md b/en/application-dev/reference/apis/js-apis-notification.md index 14f043f8b325b4a4c20aca3a4686879e99d6213d..1bd8702edac6a361335c69520bb54e8571224ebb 100644 --- a/en/application-dev/reference/apis/js-apis-notification.md +++ b/en/application-dev/reference/apis/js-apis-notification.md @@ -1,10 +1,7 @@ -# Notification Module - - -## Required Permissions - -None +# Notification +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -12,152 +9,22 @@ None import Notification from '@ohos.notification'; ``` -## System Capabilities - -```js -SystemCapability.Notification.Notification -``` - -## Notification.publish(request: NotificationRequest, callback: AsyncCallback\) - -- Functionality - - Publishes a notification. This method uses a callback to return the result. - -- Parameters - - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ------------------------------------------- | -| request | Read-only| NotificationRequest | Yes| Notification to publish.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| - -- NotificationRequest - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------------------- | -------- | --------------------------------------------- | ---- | -------------------------- | -| content | Readable and writable| NotificationContent | Yes| Notification content.| -| id | Readable and writable| number | No| Notification ID.| -| slotType | Readable and writable| SlotType | No| Notification slot type.| -| isOngoing | Readable and writable| boolean | No| Whether the notification is an ongoing notification.| -| isUnremovable | Readable and writable| boolean | No| Whether the notification can be removed.| -| deliveryTime | Readable and writable| number | No| Time when the notification is sent.| -| tapDismissed | Readable and writable| boolean | No| Whether the notification can be automatically cleared.| -| autoDeletedTime | Readable and writable| number | No| Time when the notification is automatically cleared.| -| wantAgent | Readable and writable| WantAgent | No| **WantAgent** object to which the notification will be redirected after being clicked.| -| extraInfo | Readable and writable| {[key: string]: any} | No| Extended parameter.| -| color | Readable and writable| number | No| Background color of the notification.| -| colorEnabled | Readable and writable| boolean | No| Whether the notification background color is enabled.| -| isAlertOnce | Readable and writable| boolean | No| Whether the notification triggers an alert only once.| -| isStopwatch | Readable and writable| boolean | No| Whether to display the stopwatch.| -| isCountDown | Readable and writable| boolean | No| Whether to display the countdown time.| -| isFloatingIcon | Readable and writable| boolean | No| Whether the notification is displayed as a floating icon.| -| label | Readable and writable| string | No| Notification label.| -| badgeIconStyle | Readable and writable| number | No| Notification badge type.| -| showDeliveryTime | Readable and writable| boolean | No| Whether to display the time when the notification is delivered.| -| actionButtons | Readable and writable| Array\ | No| Buttons in the notification. Up to two buttons are allowed.| -| smallIcon | Readable and writable| PixelMap | No| Small notification icon.| -| largeIcon | Readable and writable| PixelMap | No| Large notification icon.| -| creatorBundleName | Read-only| string | No| Name of the bundle that creates the notification.| -| creatorUid | Read-only| number | No| UID of the notification creator.| -| creatorPid | Read-only| number | No| PID of the notification creator.| -| hashCode | Read-only| string | No| Unique ID of the notification.| -| classification | Readable and writable| string | No| Notification category.| -| groupName | Readable and writable| string | No| Notification group name.| -| template8+ | Readable and writable| [NotificationTemplate](#notificationtemplate) | No| Notification template.| - -NotificationContent +## Notification.publish -| Name| Readable/Writable| Type| Mandatory| Description| -| ----------- | -------- | ---------------------------- | ---- | ------------------ | -| contentType | Readable and writable| ContentType | Yes| Notification content type.| -| normal | Readable and writable| NotificationBasicContent | No| Normal text.| -| longText | Readable and writable| NotificationLongTextContent | No| Long text.| -| multiLine | Readable and writable| NotificationMultiLineContent | No| Multi-line text.| -| picture | Readable and writable| NotificationPictureContent | No| Picture-attached.| +publish(request: NotificationRequest, callback: AsyncCallback\): void -- ContentType +Publishes a notification. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Description| -| --------------------------------- | -------- | ----------- | ---------------- | -| NOTIFICATION_CONTENT_BASIC_TEXT | Read-only| ContentType | Normal text notification.| -| NOTIFICATION_CONTENT_LONG_TEXT | Read-only| ContentType | Long text notification.| -| NOTIFICATION_CONTENT_PICTURE | Read-only| ContentType | Picture-attached notification.| -| NOTIFICATION_CONTENT_CONVERSATION | Read-only| ContentType | Conversation notification.| -| NOTIFICATION_CONTENT_MULTILINE | Read-only| ContentType | Multi-line text notification.| +**System capability**: SystemCapability.Notification.Notification -- NotificationBasicContent +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | ------ | ---- | -------------------------------- | -| title | Readable and writable| string | Yes| Notification title.| -| text | Readable and writable| string | Yes| Notification content.| -| additionalText | Readable and writable| string | Yes| Additional information of the notification.| +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | ---- | ------------------------------------------- | ---- | ------------------------------------------- | +| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| +| callback | Yes | No |AsyncCallback\ | Yes | Callback used to return the result. | -- NotificationLongTextContent - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | ------ | ---- | -------------------------------- | -| title | Readable and writable| string | Yes| Notification title.| -| text | Readable and writable| string | Yes| Notification content.| -| additionalText | Readable and writable| string | Yes| Additional information of the notification.| -| longText | Readable and writable| string | Yes| Long text content of the notification.| -| briefText | Readable and writable| string | Yes| Brief text of the notification.| -| expandedTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| - -- NotificationMultiLineContent - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | --------------- | ---- | -------------------------------- | -| title | Readable and writable| string | Yes| Notification title.| -| text | Readable and writable| string | Yes| Notification content.| -| additionalText | Readable and writable| string | Yes| Additional information of the notification.| -| briefText | Readable and writable| string | Yes| Brief text of the notification.| -| longTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| -| lines | Readable and writable| Array\ | Yes| Multi-line content.| - -- NotificationPictureContent - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | -------------- | ---- | -------------------------------- | -| title | Readable and writable| string | Yes| Notification title.| -| text | Readable and writable| string | Yes| Notification content.| -| additionalText | Readable and writable| string | Yes| Additional information of the notification.| -| briefText | Readable and writable| string | Yes| Brief text of the notification.| -| expandedTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| -| picture | Readable and writable| image.PixelMap | Yes| Picture included in the notification.| - -- SlotType - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------------- | -------- | -------- | ---- | -------- | -| SOCIAL_COMMUNICATION | Read-only| SlotType | No| Notification slot for social communication.| -| SERVICE_INFORMATION | Read-only| SlotType | No| Notification slot for service information.| -| CONTENT_INFORMATION | Read-only| SlotType | No| Notification slot for content consultation.| -| OTHER_TYPES | Read-only| SlotType | No| Notification slot for other purposes.| - -- NotificationActionButton - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | --------------------- | ---- | ------------------------- | -| title | Readable and writable| string | Yes| Button title.| -| wantAgent | Readable and writable| wantAgent | Yes| **WantAgent** of the button.| -| extras | Readable and writable| Array\ | No| Extra information of the button.| -| icon | Readable and writable| image.PixelMap | No| Button icon.| -| userInput | Readable and writable| NotificationUserInput | No| User input object.| - -- NotificationUserInput - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------ | ---- | ----------------------------- | -| inputKey | Readable and writable| string | Yes| Key to identify the user input.| - - -- Return value - - void - -- Example +**Example** ```js // publish callback @@ -168,7 +35,7 @@ function publishCallback(err) { var notificationRequest = { id: 1, content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: "test_title", text: "test_text", @@ -181,24 +48,22 @@ Notification.publish(notificationRequest, publishCallback) -## Notification.publish(request: NotificationRequest) - -- Functionality +## Notification.publish - Publishes a notification. This method uses a promise to return the result. +publish(request: NotificationRequest): Promise\ -- Return value +Publishes a notification. This API uses a promise to return the result. - Promise\ +**System capability**: SystemCapability.Notification.Notification -- Example +**Example** ```js // NotificationRequest object var notificationRequest = { notificationId: 1, content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: "test_title", text: "test_text", @@ -206,33 +71,107 @@ var notificationRequest = { } } } -Notification.publish(notificationRequest).then((void) => { +Notification.publish(notificationRequest).then(() => { console.info("==========================>publishCallback=======================>"); }); ``` +## Notification.publish8+ + +publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void + +Publishes a notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| +| userId | Yes | No |number | Yes | ID of the user who receives the notification. | +| callback | Yes | No |AsyncCallback\ | Yes | Callback used to return the result. | + +**Example** + +```js +// publish callback +function publishCallback(err) { + console.info("==========================>publishCallback=======================>"); +} +// ID of the user who receives the notification. +var userId = 1 +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, userId, publishCallback); +``` + +## Notification.publish8+ + +publish(request: NotificationRequest, userId: number): Promise\ + +Publishes a notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| +| userId | Yes | No |number | Yes | ID of the user who receives the notification. | + +**Example** + +```js +var notificationRequest = { + notificationId: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +var userId = 1 +Notification.publish(notificationRequest, userId).then(() => { + console.info("==========================>publishCallback=======================>"); +}); +``` -## Notification.cancel(id: number, label: string, callback: AsyncCallback\) -- Functionality +## Notification.cancel - Cancels a notification with the specified ID and label. This method uses a callback to return the result. +cancel(id: number, label: string, callback: AsyncCallback\): void -- Parameters +Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| id | Read-only| number | Yes| Notification ID.| -| label | Read-only| string | Yes| Notification label.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | --- | ---- | --------------------- | ---- | -------------------- | +| id | Yes | No | number | Yes | Notification ID. | +| label | Yes | No | string | Yes | Notification label. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js // cancel callback @@ -244,51 +183,47 @@ Notification.cancel(0, "label", cancelCallback) -## Notification.cancel(id: number, label? : string) - -- Functionality +## Notification.cancel - Cancels a notification with the specified ID and label. This method uses a promise to return the result. +cancel(id: number, label?: string): Promise\ -- Parameters +Cancels a notification with the specified ID and label. This API uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | ------ | ---- | -------- | -| id | Read-only| number | Yes| Notification ID.| -| label | Read-only| string | No| Notification label.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - Promise\ +| Name | Readable| Writable| Type | Mandatory| Description | +| ----- | --- | ---- | ------ | ---- | -------- | +| id | Yes | No | number | Yes | Notification ID. | +| label | Yes | No | string | No | Notification label.| -- Example +**Example** ```js -Notification.cancel(0).then((void) => { +Notification.cancel(0).then(() => { console.info("==========================>cancelCallback=======================>"); }); ``` -## Notification.cancel(id: number, callback: AsyncCallback\) +## Notification.cancel -- Functionality +cancel(id: number, callback: AsyncCallback\): void - Cancels a notification with the specified ID. This method uses a callback to return the result. +Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| id | Read-only| number | Yes| Notification ID.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| id | Yes | No | number | Yes | Notification ID. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js // cancel callback @@ -300,92 +235,66 @@ Notification.cancel(0, cancelCallback) -## Notification.cancelAll(callback: AsyncCallback\) - -- Functionality +## Notification.cancelAll - Cancels all notifications. This method uses a callback to return the result. +cancelAll(callback: AsyncCallback\): void -- Parameters +Cancels all notifications. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js // cancel callback -function cancelAllback(err) { - console.info("==========================>cancelAllback=======================>"); +function cancelAllCallback(err) { + console.info("==========================>cancelAllCallback=======================>"); } -Notification.cancelAll(cancelCallback) +Notification.cancelAll(cancelAllCallback) ``` -## Notification.cancelAll() - -- Functionality - - Cancels all notifications. This method uses a promise to return the result. +## Notification.cancelAll -- Parameters +cancelAll(): Promise\ - None +Cancels all notifications. This API uses a promise to return the result. -- Return value +**System capability**: SystemCapability.Notification.Notification - Promise\ - -- Example +**Example** ```js -Notification.cancelAll().then((void) => { - console.info("==========================>cancelAllback=======================>"); +Notification.cancelAll().then(() => { + console.info("==========================>cancelAllCallback=======================>"); }); ``` -## Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\) - -- Functionality - - Adds a notification slot. This method uses a callback to return the result. - -- Parameters +## Notification.addSlot -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| slot | Read-only| NotificationSlot | Yes| Notification slot to add.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +addSlot(slot: NotificationSlot, callback: AsyncCallback\): void -- NotificationSlot +Adds a notification slot. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------------- | -------- | --------------- | ---- | ------------------------------------------ | -| type | Readable and writable| SlotType | Yes| Notification slot type.| -| level | Readable and writable| number | No| Notification level. If this parameter is not set, the default value is used based on the notification slot type.| -| desc | Readable and writable| string | No| Description of the notification slot.| -| badgeFlag | Readable and writable| boolean | No| Whether to display the badge.| -| bypassDnd | Readable and writable| boolean | No| Whether to bypass the system do-not-disturb (DND) setting.| -| lockscreenVisibility | Readable and writable| boolean | No| How the notification is displayed on the locked screen.| -| vibrationEnabled | Readable and writable| boolean | No| Whether vibration is enabled for the notification.| -| sound | Readable and writable| string | No| Notification sound.| -| lightEnabled | Readable and writable| boolean | No| Whether light is enabled for the notification.| -| lightColor | Readable and writable| number | No| Notification light color.| -| vibrationValues | Readable and writable| Array\ | No| Notification vibration mode.| +**System capability**: SystemCapability.Notification.Notification -* Return values +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -* Example +**Example** ```js // addSlot callback @@ -401,54 +310,50 @@ Notification.addSlot(notificationSlot, addSlotCallBack) -## Notification.addSlot(slot: NotificationSlot) +## Notification.addSlot -- Functionality +addSlot(slot: NotificationSlot): Promise\ - Adds a notification slot. This method uses a promise to return the result. +Adds a notification slot. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ---------------- | ---- | -------------------- | -| slot | Read-only| NotificationSlot | Yes| Notification slot to add.| +**Parameters** -- Return value +| Name| Readable| Writable| Type | Mandatory| Description | +| ---- | ---- | --- | ---------------- | ---- | -------------------- | +| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| - Promise\ - -- Example +**Example** ```js // NotificationSlot object var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } -Notification.addSlot(notificationSlot).then((void) => { +Notification.addSlot(notificationSlot).then(() => { console.info("==========================>addSlotCallback=======================>"); }); ``` -## Notification.addSlot(type: SlotType, callback: AsyncCallback\) - -- Functionality +## Notification.addSlot - Adds a notification slot. This method uses a callback to return the result. +addSlot(type: SlotType, callback: AsyncCallback\): void -- Parameters +Adds a notification slot. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ---------------------- | -| type | Read-only| SlotType | Yes| Type of the notification slot to add.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ---------------------- | +| type | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot to add.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result. | -- Example +**Example** ```js // addSlot callback @@ -460,50 +365,46 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack -## Notification.addSlot(type: SlotType) +## Notification.addSlot -- Functionality +addSlot(type: SlotType): Promise\ - Adds a notification slot. This method uses a promise to return the result. +Adds a notification slot. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | -------- | ---- | ---------------------- | -| type | Read-only| SlotType | Yes| Type of the notification slot to add.| +**Parameters** -- Return value +| Name| Readable| Writable| Type | Mandatory| Description | +| ---- | ---- | --- | -------- | ---- | ---------------------- | +| type | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot to add.| - Promise\ - -- Example +**Example** ```js -Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then((void) => { +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { console.info("==========================>addSlotCallback=======================>"); }); ``` -## Notification.addSlots(slots: Array\, callback: AsyncCallback\) - -- Functionality +## Notification.addSlots - Adds multiple notification slots. This method uses a callback to return the result. +addSlots(slots: Array\, callback: AsyncCallback\): void -- Parameters +Adds multiple notification slots. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------------------------- | ---- | ------------------------ | -| slots | Read-only| Array\ | Yes| Notification slots to add.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------- | ---- | ------------------------ | +| slots | Yes | No | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result. | -- Example +**Example** ```js // addSlots callback @@ -515,31 +416,29 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } // NotificationSlotArray object -var notificationSlotArray = new Array(); -notificationSlotArray[0] = notificationSlot; +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; Notification.addSlots(notificationSlotArray, addSlotsCallBack) ``` -## Notification.addSlots(slots: Array\) +## Notification.addSlots -- Functionality +addSlots(slots: Array\): Promise\ - Adds multiple notification slots. This method uses a promise to return the result. +Adds multiple notification slots. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | ------------------------- | ---- | ------------------------ | -| slots | Read-only| Array\ | Yes| Notification slots to add.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ----- | ---- | --- | ------------------------- | ---- | ------------------------ | +| slots | Yes | No | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| - Promise\ - -- Example +**Example** ```js // NotificationSlot object @@ -547,34 +446,32 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } // NotificationSlotArray object -var notificationSlotArray = new Array(); -notificationSlotArray[0] = notificationSlot; +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; -Notification.addSlots(notificationSlotArray).then((void) => { +Notification.addSlots(notificationSlotArray).then(() => { console.info("==========================>addSlotCallback=======================>"); }); ``` -## Notification.getSlot(slotType: SlotType, callback: AsyncCallback\) - -- Functionality +## Notification.getSlot - Obtains a notification slot of the specified type. This method uses a callback to return the result. +getSlot(slotType: SlotType, callback: AsyncCallback\): void -- Parameters +Obtains a notification slot of the specified type. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- | -| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------------------- | ---- | ----------------------------------------------------------- | +| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. | -- Example +**Example** ```js // getSlot callback @@ -587,23 +484,27 @@ Notification.getSlot(slotType, getSlotCallback) -## Notification.getSlot(slotType) +## Notification.getSlot -- Functionality +getSlot(slotType: SlotType): Promise\ - Obtains a notification slot of the specified type. This method uses a promise to return the result. +Obtains a notification slot of the specified type. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | -| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | -------- | ---- | ----------------------------------------------------------- | +| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| - Promise\ +**Return value** -- Example +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Example** ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; @@ -614,23 +515,21 @@ Notification.getSlot(slotType).then((data) => { -## Notification.getSlots(callback: AsyncCallback>) - -- Functionality +## Notification.getSlots - Obtains all notification slots. This method uses a callback to return the result. +getSlots(callback: AsyncCallback>): void -- Parameters +Obtains all notification slots. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------------------- | ---- | -------------------- | +| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result.| -- Example +**Example** ```js // getSlots callback @@ -642,21 +541,21 @@ Notification.getSlots(getSlotsCallback) -## Notification.getSlots() +## Notification.getSlots -- Functionality +getSlots(): Promise\> - Obtains all notification slots of the current application. This method uses a promise to return the result. +Obtains all notification slots of this application. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result.| - Promise\\> - -- Example +**Example** ```js Notification.getSlots().then((data) => { @@ -666,24 +565,22 @@ Notification.getSlots().then((data) => { -## Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\) - -- Functionality +## Notification.removeSlot - Removes a notification slot of the specified type. This method uses a callback to return the result. +removeSlot(slotType: SlotType, callback: AsyncCallback\): void -- Parameters +Removes a notification slot of the specified type. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- | -| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ----------------------------------------------------------- | +| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result. | -- Example +**Example** ```js // removeSlot callback @@ -696,50 +593,46 @@ Notification.removeSlot(slotType,removeSlotCallback) -## Notification.removeSlot(slotType: SlotType) +## Notification.removeSlot -- Functionality +removeSlot(slotType: SlotType): Promise\ - Removes a notification slot of the specified type. This method uses a promise to return the result. +Removes a notification slot of the specified type. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | -| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | -------- | ---- | ----------------------------------------------------------- | +| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| - Promise\ - -- Example +**Example** ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; -Notification.removeSlot(slotType).then((void) => { +Notification.removeSlot(slotType).then(() => { console.info("==========================>removeSlotCallback=======================>"); }); ``` -## Notification.removeAllSlots(callback: AsyncCallback\) - -- Functionality +## Notification.removeAllSlots - Removes all notification slots. This method uses a callback to return the result. +removeAllSlots(callback: AsyncCallback\): void -- Parameters +Removes all notification slots. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function removeAllCallBack(err) { @@ -750,111 +643,41 @@ Notification.removeAllSlots(removeAllCallBack) -## Notification.removeAllSlots() +## Notification.removeAllSlots -- Functionality +removeAllSlots(): Promise\ - Removes all notification slots. This method uses a promise to return the result. +Removes all notification slots. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None - -- Return value - - Promise\ - -- Example +**Example** ```js -Notification.removeAllSlots().then((void) => { +Notification.removeAllSlots().then(() => { console.info("==========================>removeAllCallBack=======================>"); }); ``` -## Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\) - -- Functionality +## Notification.subscribe - Subscribes to a notification with the subscription information specified. This method uses a callback to return the result. +subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\): void -- Parameters +Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------------------------- | ---- | ---------------- | -| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| -| info | Read-only| NotificationSubscribeInfo | Yes| Subscription information.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- NotificationSubscriber +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- | -| onConsume?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for receiving notifications.| -| onCancel?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for canceling notifications.| -| onUpdate?:(data: NotificationSortingMap) | Readable and writable| function | No| Callback for notification sorting updates.| -| onConnect?:() | Readable and writable| function | No| Callback for subscription.| -| onDisconnect?:() | Readable and writable| function | No| Callback for unsubscription.| -| onDestroy?:() | Readable and writable| function | No| Callback for service destruction.| -| onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) | Readable and writable| function | No| Callback for DND time setting updates.| +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------- | ---- | --- | ------------------------- | ---- | ---------------- | +| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| info | Yes | No | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- SubscribeCallbackData - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------------- | -------- | ---------------------- | ---- | -------- | -| request | Read-only| NotificationRequest | Yes| Notification content.| -| sortingMap | Read-only| NotificationSortingMap | No| Notification sorting information.| -| reason | Read-only| number | No| Reason for deletion.| -| sound | Read-only| string | No| Sound used for notification.| -| vibrationValues | Read-only| Array\ | No| Vibration used for notification.| - -- NotificationSortingMap - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | ------------------------------------ | ---- | ---------------- | -| sortings | Read-only| {[key: string]: NotificationSorting} | Yes| Array of notification sorting information.| -| sortedHashCode | Read-only| Array\ | Yes| Array of unique notification IDs.| - -- NotificationSorting - -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------------- | ---- | ------------ | -| slot | Read-only| NotificationSlot | Yes| Notification slot.| -| hashCode | Read-only| string | Yes| Unique ID of the notification.| -| ranking | Read-only| number | Yes| Notification sequence number.| - -- DoNotDisturbType - - -| Name| Readable/Writable| Type| Description| -| ------------ | -------- | --------------------- | ---------------------------------------- | -| TYPE_NONE | Read-only| enum DoNotDisturbType | Non-DND.| -| TYPE_ONCE | Read-only| enum DoNotDisturbType | One-shot DND at the specified time segment (only considering the hour and minute)| -| TYPE_DAILY | Read-only| enum DoNotDisturbType | Daily DND at the specified time segment (only considering the hour and minute)| -| TYPE_CLEARLY | Read-only| enum DoNotDisturbType | DND at the specified time segment (considering the year, month, day, hour, and minute)| - -- DoNotDisturbDate - -| Name| Readable/Writable| Type| Description| -| ----- | -------- | ---------------- | ------------------------ | -| type | Readable and writable| DoNotDisturbType | DND time type.| -| begin | Readable and writable| Date | DND start time.| -| end | Readable and writable| Date | DND end time.| - -- NotificationSubscribeInfo - -| Name| Readable/Writable| Type| Mandatory| Description| -| ----------- | -------- | --------------- | ---- | ------------------------------- | -| bundleNames | Readable and writable| Array\ | No| Bundle names of the applications whose notifications are to be subscribed to.| -| userId | Readable and writable| number | No| User whose notifications are to be subscribed to.| - -- Return value - - void - -- Example +**Example** ```js // subscribe callback @@ -875,24 +698,22 @@ Notification.subscribe(subscriber, info, subscribeCallback); -## Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) - -- Functionality +## Notification.subscribe - Subscribes to a notification. This method uses a callback to return the result. +subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void -- Parameters +Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ---------------------- | ---- | ---------------- | -| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------- | ---- | --- | ---------------------- | ---- | ---------------- | +| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function subscribeCallback(err) { @@ -909,24 +730,22 @@ Notification.subscribe(subscriber, subscribeCallback); -## Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) +## Notification.subscribe -- Functionality +subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\ - Subscribes to a notification with the subscription information specified. This method uses a promise to return the result. +Subscribes to a notification with the subscription information specified. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------------------------- | ---- | ------------ | -| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| -| info | Read-only| NotificationSubscribeInfo | No| Subscription information.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------- | ---- | --- | ------------------------- | ---- | ------------ | +| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| +| info | Yes | No | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Subscription information. | - Promise\ - -- Example +**Example** ```js function onConsumeCallback(err, data) { @@ -935,31 +754,29 @@ function onConsumeCallback(err, data) { var subscriber = { onConsume: onConsumeCallback }; -Notification.subscribe(subscriber).then((void) => { +Notification.subscribe(subscriber).then(() => { console.info("==========================>subscribeCallback=======================>"); }); ``` -## Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) - -- Functionality +## Notification.unsubscribe - Unsubscribes from a notification. This method uses a callback to return the result. +unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void -- Parameters +Unsubscribes from a notification. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ---------------------- | ---- | -------------------- | -| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------- | ---- | --- | ---------------------- | ---- | -------------------- | +| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function unsubscribeCallback(err) { @@ -976,23 +793,21 @@ Notification.unsubscribe(subscriber, unsubscribeCallback); -## Notification.unsubscribe(subscriber: NotificationSubscriber) +## Notification.unsubscribe -- Functionality +unsubscribe(subscriber: NotificationSubscriber): Promise\ - Unsubscribes from a notification. This method uses a promise to return the result. +Unsubscribes from a notification. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ---------------------- | ---- | ------------ | -| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------- | ---- | --- | ---------------------- | ---- | ------------ | +| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| - Promise\ - -- Example +**Example** ```js function onConsumeCallback(err, data) { @@ -1001,133 +816,125 @@ function onConsumeCallback(err, data) { var subscriber = { onConsume: onConsumeCallback }; -Notification.unsubscribe(subscriber).then((void) => { +Notification.unsubscribe(subscriber).then(() => { console.info("==========================>unsubscribeCallback=======================>"); }); ``` -## Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) - -- Functionality +## Notification.enableNotification - Sets whether to enable notification for a specified bundle. This method uses a callback to return the result. +enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -- Parameters +Sets whether to enable notification for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| enable | Read-only| boolean | Yes| Whether to enable notification.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- BundleOption +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------ | ---- | ------ | -| bundle | Readable and writable| string | Yes| Bundle name.| -| uid | Readable and writable| number | No| User ID.| -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| enable | Yes | No | boolean | Yes | Whether to enable notification. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js function enableNotificationCallback(err) { console.info("==========================>enableNotificationCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.enableNotification(bundle, false, enableNotificationCallback); ``` -## Notification.enableNotification(bundle: BundleOption, enable: boolean) - -- Functionality +## Notification.enableNotification - Sets whether to enable notification for a specified bundle. This method uses a promise to return the result. +enableNotification(bundle: BundleOption, enable: boolean): Promise\ -- Parameters +Sets whether to enable notification for a specified bundle. This API uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| enable | Read-only| boolean | Yes| Whether to enable notification.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - Promise\ +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| +| enable | Yes | No | boolean | Yes | Whether to enable notification. | -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } -Notification.enableNotification(bundle, false).then((void) => { +Notification.enableNotification(bundle, false).then(() => { console.info("==========================>enableNotificationCallback=======================>"); }); ``` -## Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\) +## Notification.isNotificationEnabled -- Functionality +isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void - Checks whether notification is enabled for a specified bundle. This method uses a callback to return the result. +Checks whether notification is enabled for a specified bundle. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ------------------------ | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ------------------------ | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js function isNotificationEnabledCallback(err, data) { console.info("==========================>isNotificationEnabledCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); ``` -## Notification.isNotificationEnabled(bundle: BundleOption) +## Notification.isNotificationEnabled + +isNotificationEnabled(bundle: BundleOption): Promise\ -- Functionality +Checks whether notification is enabled for a specified bundle. This API uses a promise to return the result. - Checks whether notification is enabled for a specified bundle. This method uses a promise to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| -- Return value +**Return value** - Promise\ +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.isNotificationEnabled(bundle).then((data) => { console.info("==========================>isNotificationEnabledCallback=======================>"); @@ -1136,23 +943,21 @@ Notification.isNotificationEnabled(bundle).then((data) => { -## Notification.isNotificationEnabled(callback: AsyncCallback\) - -- Functionality +## Notification.isNotificationEnabled - Checks whether notification is enabled for the current application. This method uses a callback to return the result. +isNotificationEnabled(callback: AsyncCallback\): void -- Parameters +Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ------------------------ | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ------------------------ | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function isNotificationEnabledCallback(err, data) { @@ -1164,21 +969,27 @@ Notification.isNotificationEnabled(isNotificationEnabledCallback); -## Notification.isNotificationEnabled() +## Notification.isNotificationEnabled -- Functionality +isNotificationEnabled(): Promise\ - Checks whether notification is enabled for the current application. This method uses a promise to return the result. +Checks whether notification is enabled for this application. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| - Promise\ +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| -- Example +**Example** ```js Notification.isNotificationEnabled().then((data) => { @@ -1188,120 +999,118 @@ Notification.isNotificationEnabled().then((data) => { -## Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) +## Notification.displayBadge -- Functionality +displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void - Sets whether to display the badge in notifications for a specified bundle. This method uses a callback to return the result. +Sets whether to enable the notification badge for a specified bundle. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| enable | Read-only| boolean | Yes| Whether to display the badge.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| enable | Yes | No | boolean | Yes | Whether to enable notification. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js function displayBadgeCallback(err) { console.info("==========================>displayBadgeCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.displayBadge(bundle, false, displayBadgeCallback); ``` -## Notification.displayBadge(bundle: BundleOption, enable: boolean) - -- Functionality +## Notification.displayBadge - Sets whether to display the badge in notifications for a specified bundle. This method uses a promise to return the result. +displayBadge(bundle: BundleOption, enable: boolean): Promise\ -- Parameters +Sets the notification slot for a specified bundle. This API uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| enable | Read-only| boolean | Yes| Whether to display the badge.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - Promise\ +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| +| enable | Yes | No | boolean | Yes | Whether to enable notification. | -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } -Notification.displayBadge(bundle, false).then((void) => { +Notification.displayBadge(bundle, false).then(() => { console.info("==========================>displayBadgeCallback=======================>"); }); ``` -## Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\) +## Notification.isBadgeDisplayed -- Functionality +isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\): void - Checks whether the badge will be displayed in notifications of a specified bundle. This method uses a callback to return the result. +Checks whether the notification badge is enabled for a specified bundle. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ------------------------ | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ------------------------ | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js function isBadgeDisplayedCallback(err, data) { console.info("==========================>isBadgeDisplayedCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); ``` -## Notification.isBadgeDisplayed(bundle: BundleOption) +## Notification.isBadgeDisplayed + +isBadgeDisplayed(bundle: BundleOption): Promise\ -- Functionality +Checks whether the notification badge is enabled for a specified bundle. This API uses a promise to return the result. - Checks whether the badge will be displayed in notifications of a specified bundle. This method uses a promise to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| -- Return value +**Return value** - Promise\ +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.isBadgeDisplayed(bundle).then((data) => { console.info("==========================>isBadgeDisplayedCallback=======================>"); @@ -1310,32 +1119,30 @@ Notification.isBadgeDisplayed(bundle).then((data) => { -## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\) - -- Functionality +## Notification.setSlotByBundle - Sets a notification slot for a specified bundle. This method uses a callback to return the result. +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\): void -- Parameters +Sets the notification slot for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| slot | Read-only| NotificationSlot | Yes| Notification slot.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function setSlotByBundleCallback(err) { console.info("==========================>setSlotByBundleCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION @@ -1345,91 +1152,91 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); -## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) +## Notification.setSlotByBundle -- Functionality +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\ - Sets a notification slot for a specified bundle. This method uses a promise to return the result. +Sets the notification slot for a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| slot| Read-only| NotificationSlot| Yes| Notification slot.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| +| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Whether to enable notification. | - Promise\ - -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } -Notification.displayBadge(bundle, notificationSlot).then((void) => { +Notification.displayBadge(bundle, notificationSlot).then(() => { console.info("==========================>setSlotByBundleCallback=======================>"); }); ``` -## Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>) - -- Functionality +## Notification.getSlotsByBundle - Obtains the notification slots of a specified bundle. This method uses a callback to return the result. +getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void -- Parameters +Obtains the notification slots of a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------------------------------------- | ---- | -------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ---------------------------------------- | ---- | -------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| callback | Yes | No | AsyncCallback> | Yes | Callback used to return the result.| -- Example +**Example** ```js function getSlotsByBundleCallback(err, data) { console.info("==========================>getSlotsByBundleCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); ``` -## Notification.getSlotsByBundle(bundle: BundleOption) +## Notification.getSlotsByBundle -- Functionality +getSlotsByBundle(bundle: BundleOption): Promise> - Obtains the notification slots of a specified bundle. This method uses a promise to return the result. +Obtains the notification slots of a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| - Promise> +**Return value** -- Example +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise> | Promise used to return the result.| + +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.getSlotsByBundle(bundle).then((data) => { console.info("==========================>getSlotsByBundleCallback=======================>"); @@ -1438,58 +1245,60 @@ Notification.getSlotsByBundle(bundle).then((data) => { -## Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\) - -- Functionality +## Notification.getSlotNumByBundle - Obtains the number of notification slots of a specified bundle. This method uses a callback to return the result. +getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\): void -- Parameters +Obtains the number of notification slots of a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------------------------- | ---- | ---------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------- | ---- | ---------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function getSlotNumByBundle(err, data) { console.info("==========================>getSlotNumByBundleCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); ``` -## Notification.getSlotNumByBundle(bundle: BundleOption) +## Notification.getSlotNumByBundle -- Functionality +getSlotNumByBundle(bundle: BundleOption): Promise\ - Obtains the number of notification slots of a specified bundle. This method uses a promise to return the result. +Obtains the number of notification slots of a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| - Promise\ +**Return value** -- Example +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.getSlotNumByBundle(bundle).then((data) => { console.info("==========================>getSlotNumByBundleCallback=======================>"); @@ -1498,101 +1307,88 @@ Notification.getSlotNumByBundle(bundle).then((data) => { -## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\) - -- Functionality +## Notification.remove - Removes a notification for a specified bundle. This method uses a callback to return the result. +remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\): void -- Parameters +Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| --------------- | -------- | --------------------- | ---- | -------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| notificationKey | Read-only| NotificationKey | Yes| Notification key.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- NotificationKey +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | ------ | ---- | -------- | -| id | Readable and writable| number | Yes| Notification ID.| -| label | Readable and writable| string | No| Notification label.| +| Name | Readable| Writable| Type | Mandatory| Description | +| --------------- | ---- | --- | ----------------------------------- | ---- | -------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| notificationKey | Yes | No | [NotificationKey](#notificationkey) | Yes | Notification key. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Return value - - void - -- Example +**Example** ```js function removeCallback(err) { console.info("==========================>removeCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } var notificationKey = { - id: 0; - label: "label"; + id: 0, + label: "label", } Notification.remove(bundle, notificationKey, removeCallback); ``` -## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) +## Notification.remove -- Functionality +remove(bundle: BundleOption, notificationKey: NotificationKey): Promise\ - Removes a notification for a specified bundle. This method uses a promise to return the result. +Removes a notification for a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| --------------- | -------- | --------------- | ---- | ---------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| notificationKey | Read-only| NotificationKey | Yes| Notification key.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| --------------- | ---- | --- | --------------- | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.| +| notificationKey | Yes | No | [NotificationKey](#notificationkey) | Yes | Notification key. | - Promise\ - -- Example +**Example** ```js var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } var notificationKey = { - id: 0; - label: "label"; + id: 0, + label: "label", } -Notification.remove(bundle, notificationKey).then((void) => { +Notification.remove(bundle, notificationKey).then(() => { console.info("==========================>removeCallback=======================>"); }); ``` -## Notification.remove(hashCode: string, callback: AsyncCallback\) - -- Functionality +## Notification.remove - Removes a notification. This method uses a callback to return the result. +remove(hashCode: string, callback: AsyncCallback\): void -- Parameters +Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| hashCode | Read-only| string | Yes| Unique notification ID.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| hashCode | Yes | No | string | Yes | Unique notification ID. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function removeCallback(err) { @@ -1604,80 +1400,74 @@ Notification.remove(hashCode, removeCallback); -## Notification.remove(hashCode: string) +## Notification.remove -- Functionality +remove(hashCode: string): Promise\ - Removes a notification. This method uses a promise to return the result. +Removes a notification for a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------- | ---- | ---------- | -| hashCode | Read-only| string | Yes| Unique notification ID.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ---------- | ---- | ---------- | +| hashCode | Yes | No | string | Yes | Unique notification ID.| - Promise\ - -- Example +**Example** ```js -Notification.remove(hashCode).then((void) => { +Notification.remove(hashCode).then(() => { console.info("==========================>removeCallback=======================>"); }); ``` -## Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\) - -- Functionality +## Notification.removeAll - Removes all notifications for a specified bundle. This method uses a callback to return the result. +removeAll(bundle: BundleOption, callback: AsyncCallback\): void -- Parameters +Removes all notifications for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ---------------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ---------------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function removeAllCallback(err) { console.info("==========================>removeAllCallback=======================>"); } var bundle = { - bundle: "bundleName1"; + bundle: "bundleName1", } Notification.removeAll(bundle, removeAllCallback); ``` -## Notification.removeAll(callback: AsyncCallback\) +## Notification.removeAll -- Functionality +removeAll(callback: AsyncCallback\): void - Removes all notifications. This method uses a callback to return the result. +Removes all notifications. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | -------------------- | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| - void - -- Example +**Example** ```js function removeAllCallback(err) { @@ -1689,49 +1479,97 @@ Notification.removeAll(removeAllCallback); -## Notification.removeAll(bundle?: BundleOption) - -- Functionality +## Notification.removeAll - Removes all notifications for a specified bundle. This method uses a promise to return the result. +removeAll(bundle?: BundleOption): Promise\ -- Parameters +Removes all notifications for a specified user. This API uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | Read-only| BundleOption | No| Bundle information.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - Promise\ +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | No | Bundle information.| -- Example +**Example** ```js -Notification.removeAll().then((void) => { +Notification.removeAll().then(() => { console.info("==========================>removeAllCallback=======================>"); }); ``` +## Notification.removeAll8+ +removeAll(userId: number, callback: AsyncCallback\): void -## Notification.getAllActiveNotifications(callback: AsyncCallback>) +Removes all notifications for a specified user. This API uses an asynchronous callback to return the result. -- Functionality +**System capability**: SystemCapability.Notification.Notification - Obtains all active notifications. This method uses a callback to return the result. +**Parameters** -- Parameters +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| userId | Yes | No | number | Yes | ID of the user who receives the notification.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------------------------------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| +**Example** -- Return value +```js +function removeAllCallback(err) { + console.info("==========================>removeAllCallback=======================>"); +} + +var userId = 1 + +Notification.removeAll(userId, removeAllCallback); +``` + +## Notification.removeAll8+ + +removeAll(userId: number): Promise\ + +Removes all notifications for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------------ | ---- | ---------- | +| userId | Yes | No | number | Yes | ID of the user who receives the notification.| + +**Example** + +```js +function removeAllCallback(err) { + console.info("==========================>removeAllCallback=======================>"); +} + +var userId = 1 + +Notification.removeAll(userId, removeAllCallback); +``` + + +## Notification.getAllActiveNotifications - void +getAllActiveNotifications(callback: AsyncCallback>): void -- Example +Obtains all active notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------------------------------------------ | ---- | -------------------- | +| callback | Yes | No | AsyncCallback> | Yes | Callback used to return the result.| + +**Example** ```js function getAllActiveNotificationsCallback(err, data) { @@ -1743,21 +1581,21 @@ Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); -## Notification.getAllActiveNotifications() +## Notification.getAllActiveNotifications -- Functionality +getAllActiveNotifications(): Promise\\> - Obtains all active notifications. This method uses a promise to return the result. +Obtains all active notifications. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result.| - Promise\\> - -- Example +**Example** ```js Notification.getAllActiveNotifications().then((data) => { @@ -1767,23 +1605,21 @@ Notification.getAllActiveNotifications().then((data) => { -## Notification.getActiveNotificationCount(callback: AsyncCallback\) - -- Functionality +## Notification.getActiveNotificationCount - Obtains the number of active notifications. This method uses a callback to return the result. +getActiveNotificationCount(callback: AsyncCallback\): void -- Parameters +Obtains the number of active notifications. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------------------- | ---- | ---------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ---------------------- | ---- | ---------------------- | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function getActiveNotificationCountCallback(err, data) { @@ -1795,21 +1631,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback); -## Notification.getActiveNotificationCount() +## Notification.getActiveNotificationCount -- Functionality +getActiveNotificationCount(): Promise\ - Obtains the number of active notifications. This method uses a promise to return the result. +Obtains the number of active notifications. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| - Promise\ - -- Example +**Example** ```js Notification.getActiveNotificationCount().then((data) => { @@ -1819,23 +1655,21 @@ Notification.getActiveNotificationCount().then((data) => { -## Notification.getActiveNotifications(callback: AsyncCallback>) - -- Functionality +## Notification.getActiveNotifications - Obtains active notifications of the current application. This method uses a callback to return the result. +getActiveNotifications(callback: AsyncCallback>): void -- Parameters +Obtains active notifications of this application. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ | -| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------------------ | +| callback | Yes | No | AsyncCallback> | Yes | Callback used to return the result.| -- Example +**Example** ```js function getActiveNotificationsCallback(err, data) { @@ -1847,21 +1681,21 @@ Notification.getActiveNotifications(getActiveNotificationsCallback); -## Notification.getActiveNotifications() +## Notification.getActiveNotifications -- Functionality +getActiveNotifications(): Promise\\> - Obtains active notifications. This method uses a promise to return the result. +Obtains active notifications of this application. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result.| - Promise\\> - -- Example +**Example** ```js Notification.getActiveNotifications().then((data) => { @@ -1871,24 +1705,22 @@ Notification.getActiveNotifications().then((data) => { -## Notification.cancelGroup(groupName: string, callback: AsyncCallback\) - -- Functionality +## Notification.cancelGroup8+ - Cancels a notification group of the current application. This method uses a callback to return the result. +cancelGroup(groupName: string, callback: AsyncCallback\): void -- Parameters +Cancels a notification group of this application. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | --------------------- | ---- | ---------------------------- | -| groupName | Read-only| string | Yes| Name of the notification group to cancel.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| --------- | ---- | --- | --------------------- | ---- | ---------------------------- | +| groupName | Yes | No | string | Yes | Name of the notification group. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function cancelGroupCallback(err) { @@ -1902,23 +1734,21 @@ Notification.cancelGroup(groupName, cancelGroupCallback); -## Notification.cancelGroup(groupName: string) +## Notification.cancelGroup8+ -- Functionality +cancelGroup(groupName: string): Promise\ - Cancels a notification group of the current application. This method uses a promise to return the result. +Cancels a notification group of this application. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------ | ---- | -------------- | -| groupName | Read-only| string | Yes| Name of the notification group to cancel.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| --------- | ---- | --- | ------ | ---- | -------------- | +| groupName | Yes | No | string | Yes | Name of the notification group.| - Promise\ - -- Example +**Example** ```js var groupName = "GroupName"; @@ -1929,25 +1759,23 @@ Notification.cancelGroup(groupName).then(() => { -## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\) - -- Functionality +## Notification.removeGroupByBundle8+ - Removes a notification group for a specified bundle. This method uses a callback to return the result. +removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\): void -- Parameters +Removes a notification group for a specified bundle. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | --------------------- | ---- | ---------------------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| groupName | Read-only| string | Yes| Name of the notification group to remove.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| --------- | ---- | --- | --------------------- | ---- | ---------------------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| groupName | Yes | No | string | Yes | Name of the notification group. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function removeGroupByBundleCallback(err) { @@ -1962,24 +1790,22 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal -## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) +## Notification.removeGroupByBundle8+ -- Functionality +removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\ - Removes a notification group for a specified bundle. This method uses a promise to return the result. +Removes a notification group for a specified bundle. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------ | ---- | -------------- | -| bundle | Read-only| BundleOption | Yes| Bundle information.| -| groupName | Read-only| string | Yes| Name of the notification group to remove.| +**Parameters** -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| --------- | ---- | --- | ------------ | ---- | -------------- | +| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. | +| groupName | Yes | No | string | Yes | Name of the notification group.| - Promise\ - -- Example +**Example** ```js var bundleOption = {bundle: "Bundle"}; @@ -1991,24 +1817,22 @@ Notification.removeGroupByBundle(bundleOption, groupName).then(() => { -## Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\) - -- Functionality +## Notification.setDoNotDisturbDate8+ - Sets the DND time. This method uses a callback to return the result. +setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\): void -- Parameters +Sets the DND time. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ---------------------- | -| date | Read-only| DoNotDisturbDate | Yes| DND time to set.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ---------------------- | +| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```js function setDoNotDisturbDateCallback(err) { @@ -2016,7 +1840,7 @@ function setDoNotDisturbDateCallback(err) { } var doNotDisturbDate = { - type: notification.DoNotDisturbType.TYPE_ONCE, + type: Notification.DoNotDisturbType.TYPE_ONCE, begin: new Date(), end: new Date(2021, 11, 15, 18, 0) } @@ -2026,27 +1850,25 @@ Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); -## Notification.setDoNotDisturbDate(date: DoNotDisturbDate) +## Notification.setDoNotDisturbDate8+ -- Functionality +setDoNotDisturbDate(date: DoNotDisturbDate): Promise\ - Sets the DND time. This method uses a promise to return the result. +Sets the DND time. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ---------------- | ---- | -------------- | -| date | Read-only| DoNotDisturbDate | Yes| DND time to set.| +**Parameters** -- Return value +| Name| Readable| Writable| Type | Mandatory| Description | +| ---- | ---- | --- | ---------------- | ---- | -------------- | +| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.| - Promise\ - -- Example +**Example** ```js var doNotDisturbDate = { - type: notification.DoNotDisturbType.TYPE_ONCE, + type: Notification.DoNotDisturbType.TYPE_ONCE, begin: new Date(), end: new Date(2021, 11, 15, 18, 0) } @@ -2056,24 +1878,89 @@ Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { ``` +## Notification.setDoNotDisturbDate8+ + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\): void + +Sets the DND time for a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------- | ---- | ---------------------- | +| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. | +| userId | Yes | No | number | Yes | User ID.| +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +function setDoNotDisturbDateCallback(err) { + console.info("==========================>setDoNotDisturbDateCallback=======================>"); +} + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate8+ + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\ + +Sets the DND time for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification -## Notification.getDoNotDisturbDate(callback: AsyncCallback\) +**Parameters** -- Functionality +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ---------------- | ---- | -------------- | +| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.| +| userId | Yes | No | number | Yes | User ID.| - Obtains the DND time. This method uses a callback to return the result. +**Example** -- Parameters +```js +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { + console.info("==========================>setDoNotDisturbDatePromise=======================>"); +}); +``` + + +## Notification.getDoNotDisturbDate8+ -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------------------- | ---- | ---------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +getDoNotDisturbDate(callback: AsyncCallback\): void -- Return value +Obtains the DND time. This API uses an asynchronous callback to return the result. - void +**System capability**: SystemCapability.Notification.Notification -- Example +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- | +| callback | Yes | No | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8)\> | Yes | Callback used to return the result.| + +**Example** ```js function getDoNotDisturbDateCallback(err,data) { @@ -2085,21 +1972,21 @@ Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); -## Notification.getDoNotDisturbDate() +## Notification.getDoNotDisturbDate8+ -- Functionality +getDoNotDisturbDate(): Promise\ - Obtains the DND time. This method uses a promise to return the result. +Obtains the DND time. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| - Promise\ - -- Example +**Example** ```js Notification.getDoNotDisturbDate().then((data) => { @@ -2108,24 +1995,81 @@ Notification.getDoNotDisturbDate().then((data) => { ``` +## Notification.getDoNotDisturbDate8+ + +getDoNotDisturbDate(userId: number, callback: AsyncCallback\): void + +Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- | +| callback | Yes | No | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8)\> | Yes | Callback used to return the result.| +| userId | Yes | No | number | Yes | User ID.| + +**Example** + +```js +function getDoNotDisturbDateCallback(err,data) { + console.info("==========================>getDoNotDisturbDateCallback=======================>"); +} + +var userId = 1 + +Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate8+ -## Notification.supportDoNotDisturbMode(callback: AsyncCallback\) +getDoNotDisturbDate(userId: number): Promise\ -- Functionality +Obtains the DND time of a specified user. This API uses a promise to return the result. - Checks whether the DND mode is supported. This method uses a callback to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ------------------------ | ---- | -------------------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- | +| userId | Yes | No | number | Yes | User ID.| -- Return value +**Return value** - void +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| -- Example +**Example** + +```js +var userId = 1 + +Notification.getDoNotDisturbDate(userId).then((data) => { + console.info("==========================>getDoNotDisturbDatePromise=======================>"); +}); +``` + + +## Notification.supportDoNotDisturbMode8+ + +supportDoNotDisturbMode(callback: AsyncCallback\): void + +Checks whether the DND mode is supported. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------ | ---- | -------------------------------- | +| callback | Yes | No | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** ```js function supportDoNotDisturbModeCallback(err,data) { @@ -2137,21 +2081,21 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); -## Notification.supportDoNotDisturbMode() +## Notification.supportDoNotDisturbMode8+ -- Functionality +supportDoNotDisturbMode(): Promise\ - Checks whether the DND mode is supported. This method uses a promise to return the result. +Checks whether the DND mode is supported. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification - None +**Return value** -- Return value - - Promise\ +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| -- Example +**Example** ```js Notification.supportDoNotDisturbMode().then((data) => { @@ -2161,20 +2105,22 @@ Notification.supportDoNotDisturbMode().then((data) => { -## Notification.isSupportTemplate +## Notification.isSupportTemplate8+ isSupportTemplate(templateName: string, callback: AsyncCallback\): void -Checks whether a specified template exists. This method uses a callback to return the result. +Checks whether a specified template exists. This API uses an asynchronous callback to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Type| Mandatory| Description| +**Parameters** + +| Name | Type | Mandatory| Description | | ------------ | ------------------------ | ---- | -------------------------- | -| templateName | string | Yes| Template name.| -| callback | AsyncCallback\ | Yes| Callback used to return the result.| +| templateName | string | Yes | Template name. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** ```javascript var templateName = 'process'; @@ -2187,25 +2133,27 @@ Notification.isSupportTemplate(templateName, isSupportTemplateCallback); -## Notification.isSupportTemplate +## Notification.isSupportTemplate8+ isSupportTemplate(templateName: string): Promise\ -Checks whether a specified template exists. This method uses a promise to return the result. +Checks whether a specified template exists. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification -| Name| Type| Mandatory| Description| +**Parameters** + +| Name | Type | Mandatory| Description | | ------------ | ------ | ---- | -------- | -| templateName | string | Yes| Name| +| templateName | string | Yes | Template name.| -- Return value +**Return value** -| Type| Description| +| Type | Description | | ------------------ | --------------- | | Promise\ | Promise used to return the result.| -- Example +**Example** ```javascript var templateName = 'process'; @@ -2217,974 +2165,962 @@ Notification.isSupportTemplate(templateName).then((data) => { -## NotificationTemplate +## Notification.requestEnableNotification8+ -Describes the template information. +requestEnableNotification(callback: AsyncCallback\): void -| Name| Type| Readable| Writable| Description| -| ---- | ---------------------- | ---- | ---- | -------- | -| name | string | Yes| Yes| Template name.| -| data | {[key:string]: Object} | Yes| Yes| Template data.| +Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Notification.Notification +**Parameters** -## WantAgent APIs +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| -## Modules to Import +**Example** -```js -import WantAgent from '@ohos.wantAgent'; +```javascript +function requestEnabledNotificationCallback() { + console.log('------------- requestEnabledNotification --------------'); +}; + +Notification.requestEnabledNotification(requestEnabledNotificationCallback); ``` -## WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\) -- Functionality - Obtains a **WantAgent** object. This method uses a callback to return the result. +## Notification.requestEnableNotification8+ -- Parameters +requestEnableNotification(): Promise\ +Requests notification to be enabled for this application. This API uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------------------------- | ---- | ----------------------- | -| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- WantAgentInfo +**Example** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | ------------------------------- | ---- | ---------------------- | -| wants | Readable and writable| Array\ | Yes| Array of all **Want** objects.| -| operationType | Readable and writable| wantAgent.OperationType | Yes| Type of the operation specified in a **Want** object.| -| requestCode | Readable and writable| number | Yes| Request code defined by the user.| -| wantAgentFlags | Readable and writable| Array | No| Array of flags for using the **WantAgent** object.| -| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.| +```javascript +Notification.requestEnableNotification() + .then(() => { + console.info("requestEnableNotification "); + }); +``` -- - WantAgentFlags +## Notification.enableDistributed8+ -| Name| Readable/Writable| Type| Mandatory| Description| -| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | -| ONE_TIME_FLAG | Read-only| enum | No| The **WantAgent** object can be used only once.| -| NO_BUILD_FLAG | Read-only| enum | No| The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.| -| CANCEL_PRESENT_FLAG | Read-only| enum | No| The existing **WantAgent** object should be canceled before a new object is generated.| -| UPDATE_PRESENT_FLAG | Read-only| enum | No| Extra data of the existing **WantAgent** object is replaced with that of the new object.| -| CONSTANT_FLAG | Read-only| enum | No| The **WantAgent** object is immutable.| +enableDistributed(enable: boolean, callback: AsyncCallback\): void -- OperationType +Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ----------------- | -------- | ---- | ---- | ----------------------- | -| UNKNOWN_TYPE | Read-only| enum | No| Unknown operation.| -| START_ABILITY | Read-only| enum | No| Starts an ability with a UI.| -| START_ABILITIES | Read-only| enum | No| Starts multiple abilities with a UI.| -| START_SERVICE | Read-only| enum | No| Starts an ability without a UI.| -| SEND_COMMON_EVENT | Read-only| enum | No| Sends a common event.| +**System capability**: SystemCapability.Notification.Notification -- Return value +**Parameters** - void +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| -- Example +**Example** -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +```javascript +function enabledNotificationCallback() { + console.log('----------- enableDistributed ------------'); +}; -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +var enable = true -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +Notification.enableDistributed(enable, enabledNotificationCallback); ``` -## WantAgent.getWantAgent(info: WantAgentInfo): Promise\ +## Notification.enableDistributed8+ -- Functionality +enableDistributed(enable: boolean): Promise\ - Obtains a **WantAgent** object. This method uses a promise to return the result. +Sets whether this device supports distributed notifications. This API uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.Notification.Notification +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ------------- | ---- | ------------- | -| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| -- Return value +**Example** - Promise\ +```javascript +var enable = true -- Example +Notification.enableDistributed(enable) + .then(() => { + console.log('-------- enableDistributed ----------'); + }); +``` -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +## Notification.isDistributedEnabled8+ -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); -}); -``` +isDistributedEnabled(callback: AsyncCallback\): void +Obtains whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Notification.Notification -## WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\) +**Parameters** -- Functionality +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| - Obtains the bundle name of a **WantAgent** object. This method uses a callback to return the result. +**Example** -- Parameters +```javascript +function isDistributedEnabledCallback() { + console.log('----------- isDistributedEnabled ------------'); +}; +Notification.enableDistributed(isDistributedEnabledCallback); +``` -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ----------------------- | ---- | --------------------------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| -- Return value - void +## Notification.isDistributedEnabled8+ -- Example +isDistributedEnabled(): Promise\ -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +Obtains whether this device supports distributed notifications. This API uses a promise to return the result. -// WantAgent object -var wantAgent; +**System capability**: SystemCapability.Notification.Notification -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +**Return value** -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +| Type | Description | +| ------------------ | --------------- | +| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| -// getBundleName callback -function getBundleNameCallback(err, data) { - console.info("==========================>getBundleNameCallback=======================>"); -} -WantAgent.getBundleName(wantAgent, getBundleNameCallback) +**Example** + +```javascript +Notification.isDistributedEnabled() + .then((data) => { + console.log('-------- isDistributedEnabled ----------'); + }); ``` +## Notification.enableDistributedByBundle8+ -## WantAgent.getBundleName(agent: WantAgent): Promise\ +enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -- Functionality +Sets whether an application supports distributed notifications based on the bundle. This API uses an asynchronous callback to return the result. - Obtains the bundle name of a **WantAgent** object. This method uses a promise to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | +| enable | boolean | Yes | Whether the device supports distributed notifications. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | --------- | ---- | ------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.| +**Example** -- Return value +```javascript +function enableDistributedByBundleCallback() { + console.log('----------- enableDistributedByBundle ------------'); +}; - Promise\ +var bundle = { + bundle: "bundleName1", +} -- Example +var enable = true -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundleCallback); +``` -// WantAgent object -var wantAgent; -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] + +## Notification.enableDistributedByBundle8+ + +bundleenableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise + +Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | +| enable | boolean | Yes | Whether the device supports distributed notifications. | + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", } -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); +var enable = true -WantAgent.getBundleName(wantAgent).then((data) => { - console.info("==========================>getBundleNameCallback=======================>"); -}); +Notification.enableDistributedByBundle(bundle, enable) + .then(() => { + console.log('-------- enableDistributedByBundle ----------'); + }); ``` +## Notification.isDistributedEnabledByBundle8+ +isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\): void -## WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\) +Obtains whether an application supports distributed notifications based on the bundle. This API uses an asynchronous callback to return the result. -- Functionality +**System capability**: SystemCapability.Notification.Notification - Obtains the user ID of a **WantAgent** object. This method uses a callback to return the result. +**Parameters** -- Parameters +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| +**Example** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ----------------------- | ---- | ----------------------------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +```javascript +function isDistributedEnabledByBundleCallback(data) { + console.log('----------- isDistributedEnabledByBundle ------------', data); +}; -- Return value +var bundle = { + bundle: "bundleName1", +} - void +Notification.enableDistributedByBundle(bundle, isDistributedEnabledByBundleCallback); +``` -- Example -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; -// WantAgent object -var wantAgent; +## Notification.isDistributedEnabledByBundle8+ -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +isDistributedEnabledByBundle(bundle: BundleOption): Promise\ -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. -// getUid callback -function getUidCallback(err, data) { - console.info("==========================>getUidCallback=======================>"); +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", } -WantAgent.getUid(wantAgent, getUidCallback) + +Notification.isDistributedEnabledByBundle(bundle) + .then((data) => { + console.log('-------- isDistributedEnabledByBundle ----------', data); + }); ``` +## Notification.getDeviceRemindType8+ -## WantAgent.getUid(agent: WantAgent): Promise\ +getDeviceRemindType(callback: AsyncCallback\): void -- Functionality +Obtains the notification reminder type. This API uses an asynchronous callback to return the result. - Obtains the user ID of a **WantAgent** object. This method uses a promise to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype8)\> | Yes | Callback used to return the result.| -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | --------- | ---- | ------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.| +**Example** -- Return value +```javascript +function getDeviceRemindTypeCallback(data) { + console.log('----------- getDeviceRemindType ------------', data); +}; - Promise\ +Notification.getDeviceRemindType(getDeviceRemindTypeCallback); +``` -- Example -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; -// WantAgent object -var wantAgent; +## Notification.getDeviceRemindType8+ -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +getDeviceRemindType(): Promise\ -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); +Obtains the notification reminder type. This API uses a promise to return the result. -WantAgent.getUid(wantAgent).then((data) => { - console.info("==========================>getUidCallback=======================>"); -}); +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\<[DeviceRemindType](#deviceremindtype8)\> | Promise used to return the result.| + +**Example** + +```javascript +Notification.getDeviceRemindType() + .then((data) => { + console.log('-------- getDeviceRemindType ----------', data); + }); ``` +## NotificationSubscriber + +### onConsume + +onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata)) +Callback for receiving notifications. -## WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\) +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | Yes| Notification information returned.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; -- Functionality +function onConsumeCallback(data) { + console.info('===> onConsume in test'); + let req = data.request; + console.info('===> onConsume callback req.id:' + req.id); + let wantAgent = data.wantAgent; + wantAgent .getWant(wantAgent) + .then((data1) => { + console.log('===> getWant success want:' + JSON.stringfy(data1)); + }) + .catch((err) => { + console.error('===> getWant failed because' + JSON.stringfy(err)); + }); + console.info('===> onConsume callback req.wantAgent:' + JSON.stringfy(req.wantAgent)); +}; - Obtains the want in a **WantAgent** object. This method uses a callback to return the result. +var subscriber = { + onConsume: onConsumeCallback +}; -- Parameters +Notification.subscribe(subscriber, subscribeCallback); +``` +### onCancel -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | ------------------------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) -- Return value +Callback for removing notifications. - void +**System capability**: SystemCapability.Notification.Notification -- Example +**Parameters** -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | Yes| Notification information returned.| -// WantAgent object -var wantAgent; +**Example** -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); } else { - console.info('----getWantAgent failed!----'); + console.info("subscribeCallback"); } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentWantAgentFlags.UPDATE_PRESENT_FLAG] +}; + +function onCancelCallback(data) { + console.info('===> onCancel in test'); + let req = data.request; + console.info('===> onCancel callback req.id:' + req.id); } -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +var subscriber = { + onCancel: onCancelCallback +}; -// getWant callback -function getWantCallback(err, data) { - console.info("==========================>getWantCallback=======================>"); -} -WantAgent.getWant(wantAgent, getWantCallback) +Notification.subscribe(subscriber, subscribeCallback); ``` +### onUpdate +onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) -## WantAgent.getWant(agent: WantAgent): Promise\ +Callback for notification sorting updates. -- Functionality +**System capability**: SystemCapability.Notification.Notification - Obtains the want in a **WantAgent** object. This method uses a promise to return the result. +**Parameters** -- Parameters +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Notification information returned.| +**Example** -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | --------- | ---- | ------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object.| +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; -- Return value +function onUpdateCallback() { + console.info('===> onUpdate in test'); +} - Promise\ +var subscriber = { + onUpdate: onUpdateCallback +}; -- Example +Notification.subscribe(subscriber, subscribeCallback); +``` -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +### onConnect -// WantAgent object -var wantAgent; +onConnect?:void -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +Callback for subscription. + +**System capability**: SystemCapability.Notification.Notification + +**Example** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConnectCallback() { + console.info('===> onConnect in test'); } -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); +var subscriber = { + onConnect: onConnectCallback +}; -WantAgent.getWant(wantAgent).then((data) => { - console.info("==========================>getWantCallback=======================>"); -}); +Notification.subscribe(subscriber, subscribeCallback); ``` +### onDisconnect +onDisconnect?:void -## WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\) +Callback for unsubscription. -- Functionality +**System capability**: SystemCapability.Notification.Notification - Cancels a **WantAgent** object. This method uses a callback to return the result. +**Example** -- Parameters +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; +function onDisconnectCallback() { + console.info('===> onDisconnect in test'); +} -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | --------------------- | ---- | --------------------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +var subscriber = { + onDisconnect: onDisconnectCallback +}; -- Return value +Notification.subscribe(subscriber, subscribeCallback); +``` - void +### onDestroy -- Example +onDestroy?:void -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +Callback for service disconnection. -// WantAgent object -var wantAgent; +**System capability**: SystemCapability.Notification.Notification -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; +**Example** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); } else { - console.info('----getWantAgent failed!----'); + console.info("subscribeCallback"); } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +}; + +function onDestroyCallback() { + console.info('===> onDestroy in test'); } -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +var subscriber = { + onDestroy: onDestroyCallback +}; -// cancel callback -function cancelCallback(err, data) { - console.info("==========================>cancelCallback=======================>"); -} -WantAgent.cancel(wantAgent, cancelCallback) +Notification.subscribe(subscriber, subscribeCallback); ``` +### onDoNotDisturbDateChange8+ + +onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate8)) + +Callback for DND time setting updates. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| mode | Notification.[DoNotDisturbDate](#donotdisturbdate8) | Yes| DND time setting updates.| + +**Example** +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; +function onDoNotDisturbDateChangeCallback() { + console.info('===> onDoNotDisturbDateChange in test'); +} -## WantAgent.cancel(agent: WantAgent): Promise\ +var subscriber = { + onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback +}; -- Functionality +Notification.subscribe(subscriber, subscribeCallback); +``` - Cancels a **WantAgent** object. This method uses a promise to return the result. -- Parameters +### onEnabledNotificationChanged8+ +onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) -| Name| Readable/Writable| Type| Mandatory| Description| -| ----- | -------- | --------- | ---- | ------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.| +Listens for the notification enable status changes. This API uses an asynchronous callback to return the result. -- Return value +**System capability**: SystemCapability.Notification.Notification - Promise\ +**Parameters** -- Example +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata8)\> | Yes| Callback used to return the result.| -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +**Example** -// WantAgent object -var wantAgent; +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +function onEnabledNotificationChangedCallback(err, callbackData) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("bundle: ", callbackData.bundle); + console.info("uid: ", callbackData.uid); + console.info("enable: ", callbackData.enable); + } +}; -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); +var subscriber = { + onEnabledNotificationChanged: onEnabledNotificationChangedCallback +}; -WantAgent.cancel(wantAgent).then((data) => { - console.info("==========================>cancelCallback=======================>"); -}); +Notification.subscribe(subscriber, subscribeCallback); ``` +## SubscribeCallbackData +**System capability**: SystemCapability.Notification.Notification -## WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\) +| Name | Readable| Writable| Type | Mandatory| Description | +| --------------- | ---- | --- | ------------------------------------------------- | ---- | -------- | +| request | Yes | No | [NotificationRequest](#notificationrequest) | Yes | Notification content.| +| sortingMap | Yes | No | [NotificationSortingMap](#notificationsortingmap) | No | Notification sorting information.| +| reason | Yes | No | number | No | Reason for deletion.| +| sound | Yes | No | string | No | Sound used for notification.| +| vibrationValues | Yes | No | Array\ | No | Vibration used for notification.| -- Functionality - Triggers a **WantAgent** object. This method uses a callback to return the result. +## EnabledNotificationCallbackData8+ -- Parameters +**System capability**: SystemCapability.Notification.Notification +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------- | ---- | ---------------- | +| bundle | Yes | No | string | Yes | Bundle name of the application. | +| uid | Yes | No | number | Yes | UID of the application. | +| enable | Yes | No | boolean | Yes | Notification enable status of the application.| -| Name| Readable/Writable| Type| Mandatory| Description| -| ----------- | -------- | ----------------------------- | ---- | ------------------------------- | -| agent | Read-only| WantAgent | Yes| **WantAgent** object to trigger.| -| triggerInfo | Read-only| TriggerInfo | Yes| **TriggerInfo** object.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| -- TriggerInfo +## DoNotDisturbDate8+ -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | -------------------- | ---- | ----------- | -| code | Readable and writable| number | Yes| Result code.| -| want | Readable and writable| Want | No| Want.| -| permission | Readable and writable| string | No| Permission.| -| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.| +**System capability**: SystemCapability.Notification.Notification -- Return value +| Name | Readable| Writable| Type | Description | +| ----- | ---- | --- | ------------------------------------- | ------------------------ | +| type | Yes | No | [DoNotDisturbType](#donotdisturbtype8) | DND time type.| +| begin | Yes | No | Date | DND start time.| +| end | Yes | No | Date | DND end time.| - void -- Example -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +## DoNotDisturbType8+ -// WantAgent object -var wantAgent; +**System capability**: SystemCapability.Notification.Notification -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +| Name | Value | Description | +| ------------ | ---------------- | ------------------------------------------ | +| TYPE_NONE | DoNotDisturbType | Non-DND. | +| TYPE_ONCE | DoNotDisturbType | One-shot DND at the specified time segment (only considering the hour and minute).| +| TYPE_DAILY | DoNotDisturbType | Daily DND at the specified time segment (only considering the hour and minute).| +| TYPE_CLEARLY | DoNotDisturbType | DND at the specified time segment (considering the year, month, day, hour, and minute). | -//Trigger callback -function triggerCallback(err, data) { - console.info("==========================>triggerCallback=======================>"); -} -var triggerInfo = { - code:0 -} -WantAgent.trigger(wantAgent, triggerInfo, triggerCallback) -``` +## ContentType +**System capability**: SystemCapability.Notification.Notification +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| NOTIFICATION_CONTENT_BASIC_TEXT | ContentType | Normal text notification. | +| NOTIFICATION_CONTENT_LONG_TEXT | ContentType | Long text notification. | +| NOTIFICATION_CONTENT_PICTURE | ContentType | Picture-attached notification. | +| NOTIFICATION_CONTENT_CONVERSATION | ContentType | Conversation notification. | +| NOTIFICATION_CONTENT_MULTILINE | ContentType | Multi-line text notification.| -## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\) +## SlotLevel -- Functionality +**System capability**: SystemCapability.Notification.Notification - Checks whether two **WantAgent** objects are equal. This method uses a callback to return the result. +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| LEVEL_NONE | 0 | The notification feature is disabled. | +| LEVEL_MIN | 1 | The notification feature is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.| +| LEVEL_LOW | 2 | The notification feature is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.| +| LEVEL_DEFAULT | 3 | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.| +| LEVEL_HIGH | 4 | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.| -- Parameters +## BundleOption -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------------------------ | ---- | --------------------------------------- | -| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.| -| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**System capability**: SystemCapability.Notification.Notification -- Return value +| Name | Readable| Writable| Type | Mandatory| Description | +| ------ | ---- | --- | ------ | ---- | ------ | +| bundle | Yes | Yes | string | Yes | Bundle name. | +| uid | Yes | Yes | number | No | User ID.| - void -- Example -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +## NotificationKey -// WantAgent object -var wantAgent1; -var wantAgent2; +**System capability**: SystemCapability.Notification.Notification -// getWantAgent callback -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent1 = data; - wantAgent2 = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +| Name | Readable| Writable| Type | Mandatory| Description | +| ----- | ---- | --- | ------ | ---- | -------- | +| id | Yes | Yes | number | Yes | Notification ID. | +| label | Yes | Yes | string | No | Notification label.| -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) -// equal callback -function equalCallback(err, data) { - console.info("==========================>equalCallback=======================>"); -} -WantAgent.equal(wantAgent1, wantAgent2, equalCallback) -``` +## SlotType +**System capability**: SystemCapability.Notification.Notification +| Name | Value | Description | +| -------------------- | -------- | ---------- | +| UNKNOWN_TYPE | SlotType | Unknown type.| +| SOCIAL_COMMUNICATION | SlotType | Notification slot for social communication.| +| SERVICE_INFORMATION | SlotType | Notification slot for service information.| +| CONTENT_INFORMATION | SlotType | Notification slot for content consultation.| +| OTHER_TYPES | SlotType | Notification slot for other purposes.| -## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\ -- Functionality +## NotificationActionButton - Checks whether two **WantAgent** objects are equal. This method uses a promise to return the result. +**System capability**: SystemCapability.Notification.Notification -- Parameters +| Name | Readable| Writable| Type | Mandatory| Description | +| --------- | --- | ---- | ----------------------------------------------- | ---- | ------------------------- | +| title | Yes | Yes | string | Yes | Button title. | +| wantAgent | Yes | Yes | WantAgent | Yes | **WantAgent** of the button.| +| extras | Yes | Yes | { [key: string]: any } | No | Extra information of the button. | +| userInput9+ | Yes | Yes | [NotificationUserInput](#notificationuserinput8) | No | User input object. | -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | --------- | ---- | ------------- | -| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.| -| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.| +## NotificationBasicContent -- Return value +**System capability**: SystemCapability.Notification.Notification - Promise\ +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- | +| title | Yes | Yes | string | Yes | Notification title. | +| text | Yes | Yes | string | Yes | Notification content. | +| additionalText | Yes | Yes | string | No | Additional information of the notification.| -- Example -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; +## NotificationLongTextContent -// WantAgent object -var wantAgent1; -var wantAgent2; +**System capability**: SystemCapability.Notification.Notification -// WantAgentInfo object -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------- | ---- | --- | ------ | ---- | -------------------------------- | +| title | Yes | Yes | string | Yes | Notification title. | +| text | Yes | Yes | string | Yes | Notification content. | +| additionalText | Yes | Yes | string | No | Additional information of the notification.| +| longText | Yes | Yes | string | Yes | Long text of the notification. | +| briefText | Yes | Yes | string | Yes | Brief text of the notification.| +| expandedTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. | -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent1 = data; - wantAgent2 = data; -}); -WantAgent.equal(wantAgent1, wantAgent2).then((data) => { - console.info("==========================>equalCallback=======================>"); -}); -``` +## NotificationMultiLineContent + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------- | --- | --- | --------------- | ---- | -------------------------------- | +| title | Yes | Yes | string | Yes | Notification title. | +| text | Yes | Yes | string | Yes | Notification content. | +| additionalText | Yes | Yes | string | No | Additional information of the notification.| +| briefText | Yes | Yes | string | Yes | Brief text of the notification.| +| longTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. | +| lines | Yes | Yes | Array\ | Yes | Multi-line text of the notification. | + + +## NotificationPictureContent + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------- | ---- | --- | -------------- | ---- | -------------------------------- | +| title | Yes | Yes | string | Yes | Notification title. | +| text | Yes | Yes | string | Yes | Notification content. | +| additionalText | Yes | Yes | string | No | Additional information of the notification.| +| briefText | Yes | Yes | string | Yes | Brief text of the notification.| +| expandedTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. | +| picture | Yes | Yes | image.PixelMap | Yes | Picture attached to the notification. | + + +## NotificationContent + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| ----------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------ | +| contentType | Yes | Yes | [ContentType](#contenttype) | Yes | Notification content type. | +| normal | Yes | Yes | [NotificationBasicContent](#notificationbasiccontent) | No | Normal text. | +| longText | Yes | Yes | [NotificationLongTextContent](#notificationlongtextcontent) | No | Long text.| +| multiLine | Yes | Yes | [NotificationMultiLineContent](#notificationmultilinecontent) | No | Multi-line text. | +| picture | Yes | Yes | [NotificationPictureContent](#notificationpicturecontent) | No | Picture-attached. | + + +## NotificationFlagStatus8+ + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| -------------- | --- | --------------------------------- | +| TYPE_NONE | 0 | The default flag is used. | +| TYPE_OPEN | 1 | The notification flag is enabled. | +| TYPE_CLOSE | 2 | The notification flag is disabled. | + + +## NotificationFlags8+ + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------------- | ---- | ---- | ---------------------- | ---- | --------------------------------- | +| soundEnabled | Yes | No | NotificationFlagStatus | No | Whether to enable the sound alert for the notification. | +| vibrationEnabled | Yes | No | NotificationFlagStatus | No | Whether to enable vibration for the notification. | + + +## NotificationRequest + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| --------------------- | ---- | --- | --------------------------------------------- | ---- | -------------------------- | +| content | Yes | Yes | [NotificationContent](#notificationcontent) | Yes | Notification content. | +| id | Yes | Yes | number | No | Notification ID. | +| slotType | Yes | Yes | [SlotType](#slottype) | No | Slot type. | +| isOngoing | Yes | Yes | boolean | No | Whether the notification is an ongoing notification. | +| isUnremovable | Yes | Yes | boolean | No | Whether the notification can be removed. | +| deliveryTime | Yes | Yes | number | No | Time when the notification is sent. | +| tapDismissed | Yes | Yes | boolean | No | Whether the notification is automatically cleared. | +| autoDeletedTime | Yes | Yes | number | No | Time when the notification is automatically cleared. | +| wantAgent | Yes | Yes | WantAgent | No | **WantAgent** instance to which the notification will be redirected after being clicked. | +| extraInfo | Yes | Yes | {[key: string]: any} | No | Extended parameters. | +| color | Yes | Yes | number | No | Background color of the notification. | +| colorEnabled | Yes | Yes | boolean | No | Whether the notification background color is enabled. | +| isAlertOnce | Yes | Yes | boolean | No | Whether the notification triggers an alert only once.| +| isStopwatch | Yes | Yes | boolean | No | Whether to display the stopwatch. | +| isCountDown | Yes | Yes | boolean | No | Whether to display the countdown time. | +| isFloatingIcon | Yes | Yes | boolean | No | Whether the notification is displayed as a floating icon. | +| label | Yes | Yes | string | No | Notification label. | +| badgeIconStyle | Yes | Yes | number | No | Notification badge type. | +| showDeliveryTime | Yes | Yes | boolean | No | Whether to display the time when the notification is delivered. | +| actionButtons | Yes | Yes | Array\<[NotificationActionButton](#notificationactionbutton)\> | No | Buttons in the notification. Up to two buttons are allowed. | +| smallIcon | Yes | Yes | PixelMap | No | Small notification icon. | +| largeIcon | Yes | Yes | PixelMap | No | Large notification icon. | +| creatorBundleName | Yes | No | string | No | Name of the bundle that creates the notification. | +| creatorUid | Yes | No | number | No | UID used for creating the notification. | +| creatorPid | Yes | No | number | No | PID used for creating the notification. | +| creatorUserId8+| Yes | No | number | No | ID of the user who creates a notification. | +| hashCode | Yes | No | string | No | Unique ID of the notification. | +| classification | Yes | Yes | string | No | Notification category. | +| groupName8+| Yes | Yes | string | No | Group notification name. | +| template8+ | Yes | Yes | [NotificationTemplate](#notificationtemplate8) | No | Notification template. | +| isRemoveAllowed8+ | Yes | No | boolean | No | Whether the notification can be removed. | +| source8+ | Yes | No | number | No | Notification source. | +| distributedOption8+ | Yes | Yes | [DistributedOptions](#distributedoptions8) | No | Option of distributed notification. | +| deviceId8+ | Yes | No | string | No | Device ID of the notification source. | +| notificationFlags8+ | Yes | No | [NotificationFlags](#notificationflags8) | No | Notification flags. | + + +## DistributedOptions8+ + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| ---------------------- | ---- | ---- | -------------- | ---- | ---------------------------------- | +| isDistributed | Yes | Yes | boolean | No | Whether the notification is a distributed notification. | +| supportDisplayDevices | Yes | Yes | Array\ | Yes | Types of the devices to which the notification can be synchronized. | +| supportOperateDevices | Yes | Yes | Array\ | No | Devices on which notification can be enabled. | +| remindType | Yes | No | number | No | Notification reminder type. | + + +## NotificationSlot + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------------- | ---- | --- | --------------------- | ---- | ------------------------------------------ | +| type | Yes | Yes | [SlotType](#slottype) | Yes | Slot type. | +| level | Yes | Yes | number | No | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| +| desc | Yes | Yes | string | No | Notification slot description. | +| badgeFlag | Yes | Yes | boolean | No | Whether to display the badge. | +| bypassDnd | Yes | Yes | boolean | No | Whether to bypass the DND mode in the system. | +| lockscreenVisibility | Yes | Yes | boolean | No | Mode for displaying the notification on the lock screen. | +| vibrationEnabled | Yes | Yes | boolean | No | Whether vibration is supported for the notification. | +| sound | Yes | Yes | string | No | Notification alert tone. | +| lightEnabled | Yes | Yes | boolean | No | Whether the indicator blinks for the notification. | +| lightColor | Yes | Yes | number | No | Indicator color of the notification. | +| vibrationValues | Yes | Yes | Array\ | No | Vibration mode of the notification. | + + +## NotificationSorting + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | ---- | --- | ------------------------------------- | ---- | ------------ | +| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot content.| +| hashCode | Yes | No | string | Yes | Unique ID of the notification.| +| ranking | Yes | No | number | Yes | Notification sequence number.| + + +## NotificationSortingMap + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------------- | ---- | --- | ------------------------------------------------------------ | ---- | ---------------- | +| sortings | Yes | No | {[key: string]: [NotificationSorting](#notificationsorting)} | Yes | Array of notification sorting information.| +| sortedHashCode | Yes | No | Array\ | Yes | Array of unique notification IDs.| + + +## NotificationSubscribeInfo + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| ----------- | --- | ---- | --------------- | ---- | ------------------------------- | +| bundleNames | Yes | Yes | Array\ | No | Bundle names of the applications whose notifications are to be subscribed to.| +| userId | Yes | Yes | number | No | User whose notifications are to be subscribed to. | + + +## NotificationTemplate8+ + +**System capability**: SystemCapability.Notification.Notification + +| Name| Type | Readable| Writable| Description | +| ---- | ---------------------- | ---- | ---- | ---------- | +| name | string | Yes | Yes | Template name.| +| data | {[key:string]: Object} | Yes | Yes | Template data.| + + +## NotificationUserInput8+ + +**System capability**: SystemCapability.Notification.Notification + +| Name | Readable| Writable| Type | Mandatory| Description | +| -------- | --- | ---- | ------ | ---- | ----------------------------- | +| inputKey | Yes | Yes | string | Yes | Key to identify the user input.| + +## DeviceRemindType8+ +**System capability**: SystemCapability.Notification.Notification -#### +| Name | Value | Description | +| -------------------- | --- | --------------------------------- | +| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. | +| IDLE_REMIND | 1 | The device is not in use. | +| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | +| ACTIVE_REMIND | 3 | The device is in use. |