提交 6a37a47f 编写于 作者: E ester.zhou

update docs

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 47621db1
...@@ -131,33 +131,7 @@ var subscriber = { ...@@ -131,33 +131,7 @@ var subscriber = {
### Publishing Notifications ### 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. Before publishing a notification, make sure the notification feature is enabled for your application. This feature is disabled by default and can be enabled in the notification settings.
##### Enabling Notification
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===>");
});
```
##### Publishing Notifications ##### Publishing Notifications
...@@ -170,7 +144,7 @@ Normal Text Notification ...@@ -170,7 +144,7 @@ Normal Text Notification
var notificationRequest = { var notificationRequest = {
id: 1, id: 1,
content: { content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: { normal: {
title: "test_title", title: "test_title",
text: "test_text", text: "test_text",
...@@ -197,25 +171,18 @@ For details about how to use **WantAgent**, see [WantAgent Development](https:// ...@@ -197,25 +171,18 @@ For details about how to use **WantAgent**, see [WantAgent Development](https://
```js ```js
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
// WantAgentInfo object // WantAgentInfo object
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
{ {
deviceId: 'deviceId', bundleName: 'ohos.samples.eTSNotification',
bundleName: 'com.example.myapplication', abilityName: 'ohos.samples.eTSNotification.MainAbility',
abilityName: 'com.example.myapplication.MainAbility', }
action: 'REMINDER_EVENT_REMOVE_NOTIFICATION', ],
entities: ['entity1'], operationType: wantAgent.OperationType.START_ABILITY,
type: 'MIMETYPE', requestCode: 0,
uri: 'key={true,true,false}', wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
parameters: { myKey0: 1111 },
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
} }
// WantAgent object // WantAgent object
...@@ -241,7 +208,7 @@ wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) ...@@ -241,7 +208,7 @@ wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// Create a NotificationRequest object. // Create a NotificationRequest object.
var notificationRequest = { var notificationRequest = {
content: { content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: { normal: {
title: "AceApplication_Title", title: "AceApplication_Title",
text: "AceApplication_Text", text: "AceApplication_Text",
...@@ -251,7 +218,7 @@ var notificationRequest = { ...@@ -251,7 +218,7 @@ var notificationRequest = {
id: 1, id: 1,
label: 'TEST', label: 'TEST',
wantAgent: WantAgent, wantAgent: WantAgent,
slotType: notify.SlotType.OTHER_TYPES, slotType: Notification.SlotType.OTHER_TYPES,
deliveryTime: new Date().getTime() deliveryTime: new Date().getTime()
} }
...@@ -279,11 +246,3 @@ Notification.cancel(1, "label", cancelCallback) ...@@ -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.
# Notification Module # Notification
## Required Permissions
None
> ![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 ## Modules to Import
...@@ -12,152 +9,22 @@ None ...@@ -12,152 +9,22 @@ None
import Notification from '@ohos.notification'; import Notification from '@ohos.notification';
``` ```
## System Capabilities ## Notification.publish
```js
SystemCapability.Notification.Notification
```
## Notification.publish(request: NotificationRequest, callback: AsyncCallback\<void\>)
- 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\<void\> | 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\<NotificationActionButton\> | 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.|
| template<sup>8+</sup> | Readable and writable| [NotificationTemplate](#notificationtemplate) | No| Notification template.|
NotificationContent
| Name| Readable/Writable| Type| Mandatory| Description| publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
| ----------- | -------- | ---------------------------- | ---- | ------------------ |
| 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.|
- ContentType Publishes a notification. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Description| **System capability**: SystemCapability.Notification.Notification
| --------------------------------- | -------- | ----------- | ---------------- |
| 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.|
- NotificationBasicContent **Parameters**
| Name| Readable/Writable| Type| Mandatory| Description| | Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | -------- | ------ | ---- | -------------------------------- | | -------- | ---- | ---- | ------------------------------------------- | ---- | ------------------------------------------- |
| title | Readable and writable| string | Yes| Notification title.| | request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.|
| text | Readable and writable| string | Yes| Notification content.| | callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. |
| additionalText | Readable and writable| string | Yes| Additional information of the notification.|
- NotificationLongTextContent **Example**
| 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\<String\> | 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\<String\> | 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
```js ```js
// publish callback // publish callback
...@@ -168,7 +35,7 @@ function publishCallback(err) { ...@@ -168,7 +35,7 @@ function publishCallback(err) {
var notificationRequest = { var notificationRequest = {
id: 1, id: 1,
content: { content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: { normal: {
title: "test_title", title: "test_title",
text: "test_text", text: "test_text",
...@@ -181,24 +48,22 @@ Notification.publish(notificationRequest, publishCallback) ...@@ -181,24 +48,22 @@ Notification.publish(notificationRequest, publishCallback)
## Notification.publish(request: NotificationRequest) ## Notification.publish
- Functionality
Publishes a notification. This method uses a promise to return the result. publish(request: NotificationRequest): Promise\<void\>
- Return value Publishes a notification. This API uses a promise to return the result.
Promise\<void\> **System capability**: SystemCapability.Notification.Notification
- Example **Example**
```js ```js
// NotificationRequest object // NotificationRequest object
var notificationRequest = { var notificationRequest = {
notificationId: 1, notificationId: 1,
content: { content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: { normal: {
title: "test_title", title: "test_title",
text: "test_text", text: "test_text",
...@@ -206,33 +71,107 @@ var notificationRequest = { ...@@ -206,33 +71,107 @@ var notificationRequest = {
} }
} }
} }
Notification.publish(notificationRequest).then((void) => { Notification.publish(notificationRequest).then(() => {
console.info("==========================>publishCallback=======================>"); console.info("==========================>publishCallback=======================>");
}); });
``` ```
## Notification.publish<sup>8+</sup>
publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): 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\<void\> | 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.publish<sup>8+</sup>
publish(request: NotificationRequest, userId: number): Promise\<void\>
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\<void\>)
- 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\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| id | Read-only| number | Yes| Notification ID.|
| label | Read-only| string | Yes| Notification label.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
// cancel callback // cancel callback
...@@ -244,51 +183,47 @@ Notification.cancel(0, "label", cancelCallback) ...@@ -244,51 +183,47 @@ Notification.cancel(0, "label", cancelCallback)
## Notification.cancel(id: number, label? : string) ## Notification.cancel
- Functionality
Cancels a notification with the specified ID and label. This method uses a promise to return the result. cancel(id: number, label?: string): Promise\<void\>
- 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| **System capability**: SystemCapability.Notification.Notification
| ----- | -------- | ------ | ---- | -------- |
| id | Read-only| number | Yes| Notification ID.|
| label | Read-only| string | No| Notification label.|
- Return value **Parameters**
Promise\<void\> | Name | Readable| Writable| Type | Mandatory| Description |
| ----- | --- | ---- | ------ | ---- | -------- |
| id | Yes | No | number | Yes | Notification ID. |
| label | Yes | No | string | No | Notification label.|
- Example **Example**
```js ```js
Notification.cancel(0).then((void) => { Notification.cancel(0).then(() => {
console.info("==========================>cancelCallback=======================>"); console.info("==========================>cancelCallback=======================>");
}); });
``` ```
## Notification.cancel(id: number, callback: AsyncCallback\<void\>) ## Notification.cancel
- Functionality cancel(id: number, callback: AsyncCallback\<void\>): 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| **Parameters**
| -------- | -------- | --------------------- | ---- | -------------------- |
| id | Read-only| number | Yes| Notification ID.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| id | Yes | No | number | Yes | Notification ID. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
// cancel callback // cancel callback
...@@ -300,92 +235,66 @@ Notification.cancel(0, cancelCallback) ...@@ -300,92 +235,66 @@ Notification.cancel(0, cancelCallback)
## Notification.cancelAll(callback: AsyncCallback\<void\>) ## Notification.cancelAll
- Functionality
Cancels all notifications. This method uses a callback to return the result. cancelAll(callback: AsyncCallback\<void\>): void
- Parameters Cancels all notifications. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
// cancel callback // cancel callback
function cancelAllback(err) { function cancelAllCallback(err) {
console.info("==========================>cancelAllback=======================>"); console.info("==========================>cancelAllCallback=======================>");
} }
Notification.cancelAll(cancelCallback) Notification.cancelAll(cancelAllCallback)
``` ```
## Notification.cancelAll() ## Notification.cancelAll
- Functionality
Cancels all notifications. This method uses a promise to return the result.
- Parameters cancelAll(): Promise\<void\>
None Cancels all notifications. This API uses a promise to return the result.
- Return value **System capability**: SystemCapability.Notification.Notification
Promise\<void\> **Example**
- Example
```js ```js
Notification.cancelAll().then((void) => { Notification.cancelAll().then(() => {
console.info("==========================>cancelAllback=======================>"); console.info("==========================>cancelAllCallback=======================>");
}); });
``` ```
## Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>) ## Notification.addSlot
- Functionality
Adds a notification slot. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description| addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
| -------- | -------- | --------------------- | ---- | -------------------- |
| slot | Read-only| NotificationSlot | Yes| Notification slot to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- NotificationSlot Adds a notification slot. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------------------- | -------- | --------------- | ---- | ------------------------------------------ |
| 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\<number\> | No| Notification vibration mode.|
* Return values **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
* Example **Example**
```js ```js
// addSlot callback // addSlot callback
...@@ -401,54 +310,50 @@ Notification.addSlot(notificationSlot, addSlotCallBack) ...@@ -401,54 +310,50 @@ Notification.addSlot(notificationSlot, addSlotCallBack)
## Notification.addSlot(slot: NotificationSlot) ## Notification.addSlot
- Functionality addSlot(slot: NotificationSlot): Promise\<void\>
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| **Parameters**
| ---- | -------- | ---------------- | ---- | -------------------- |
| slot | Read-only| NotificationSlot | Yes| Notification slot to add.|
- Return value | Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | ---------------- | ---- | -------------------- |
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
Promise\<void\> **Example**
- Example
```js ```js
// NotificationSlot object // NotificationSlot object
var notificationSlot = { var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
Notification.addSlot(notificationSlot).then((void) => { Notification.addSlot(notificationSlot).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("==========================>addSlotCallback=======================>");
}); });
``` ```
## Notification.addSlot(type: SlotType, callback: AsyncCallback\<void\>) ## Notification.addSlot
- Functionality
Adds a notification slot. This method uses a callback to return the result. addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
- Parameters Adds a notification slot. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | ---------------------- |
| type | Read-only| SlotType | Yes| Type of the notification slot to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result. |
- Example **Example**
```js ```js
// addSlot callback // addSlot callback
...@@ -460,50 +365,46 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack ...@@ -460,50 +365,46 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack
## Notification.addSlot(type: SlotType) ## Notification.addSlot
- Functionality addSlot(type: SlotType): Promise\<void\>
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| **Parameters**
| ---- | -------- | -------- | ---- | ---------------------- |
| type | Read-only| SlotType | Yes| Type of the notification slot to add.|
- Return value | Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | -------- | ---- | ---------------------- |
| type | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot to add.|
Promise\<void\> **Example**
- Example
```js ```js
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then((void) => { Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("==========================>addSlotCallback=======================>");
}); });
``` ```
## Notification.addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>) ## Notification.addSlots
- Functionality
Adds multiple notification slots. This method uses a callback to return the result. addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void
- Parameters Adds multiple notification slots. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | ------------------------- | ---- | ------------------------ |
| slots | Read-only| Array\<NotificationSlot\> | Yes| Notification slots to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result. |
- Example **Example**
```js ```js
// addSlots callback // addSlots callback
...@@ -515,31 +416,29 @@ var notificationSlot = { ...@@ -515,31 +416,29 @@ var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
// NotificationSlotArray object // NotificationSlotArray object
var notificationSlotArray = new Array(); var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot; notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray, addSlotsCallBack) Notification.addSlots(notificationSlotArray, addSlotsCallBack)
``` ```
## Notification.addSlots(slots: Array\<NotificationSlot\>) ## Notification.addSlots
- Functionality addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
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| **Parameters**
| ----- | -------- | ------------------------- | ---- | ------------------------ |
| slots | Read-only| Array\<NotificationSlot\> | Yes| Notification slots to add.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| ----- | ---- | --- | ------------------------- | ---- | ------------------------ |
| slots | Yes | No | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.|
Promise\<void\> **Example**
- Example
```js ```js
// NotificationSlot object // NotificationSlot object
...@@ -547,34 +446,32 @@ var notificationSlot = { ...@@ -547,34 +446,32 @@ var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
// NotificationSlotArray object // NotificationSlotArray object
var notificationSlotArray = new Array(); var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot; notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then((void) => { Notification.addSlots(notificationSlotArray).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("==========================>addSlotCallback=======================>");
}); });
``` ```
## Notification.getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>) ## Notification.getSlot
- Functionality
Obtains a notification slot of the specified type. This method uses a callback to return the result. getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
| 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\<NotificationSlot\> | Yes| Callback used to return the result.|
- 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 ```js
// getSlot callback // getSlot callback
...@@ -587,23 +484,27 @@ Notification.getSlot(slotType, getSlotCallback) ...@@ -587,23 +484,27 @@ Notification.getSlot(slotType, getSlotCallback)
## Notification.getSlot(slotType) ## Notification.getSlot
- Functionality getSlot(slotType: SlotType): Promise\<NotificationSlot\>
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| **Parameters**
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
- 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\<NotificationSlot\> **Return value**
- Example | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<NotificationSlot\> | Promise used to return the result.|
**Example**
```js ```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
...@@ -614,23 +515,21 @@ Notification.getSlot(slotType).then((data) => { ...@@ -614,23 +515,21 @@ Notification.getSlot(slotType).then((data) => {
## Notification.getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>) ## Notification.getSlots
- Functionality
Obtains all notification slots. This method uses a callback to return the result. getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>): void
- Parameters Obtains all notification slots. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<NotificationSlot\> | Yes| Callback used to return the result.|
- 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 ```js
// getSlots callback // getSlots callback
...@@ -642,21 +541,21 @@ Notification.getSlots(getSlotsCallback) ...@@ -642,21 +541,21 @@ Notification.getSlots(getSlotsCallback)
## Notification.getSlots() ## Notification.getSlots
- Functionality getSlots(): Promise\<Array\<NotificationSlot\>>
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\<Array\<[NotificationSlot](#notificationslot)\>\> | Promise used to return the result.|
Promise\<Array\<NotificationSlot\>\> **Example**
- Example
```js ```js
Notification.getSlots().then((data) => { Notification.getSlots().then((data) => {
...@@ -666,24 +565,22 @@ Notification.getSlots().then((data) => { ...@@ -666,24 +565,22 @@ Notification.getSlots().then((data) => {
## Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>) ## Notification.removeSlot
- Functionality
Removes a notification slot of the specified type. This method uses a callback to return the result. removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- |
| 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\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result. |
- Example **Example**
```js ```js
// removeSlot callback // removeSlot callback
...@@ -696,50 +593,46 @@ Notification.removeSlot(slotType,removeSlotCallback) ...@@ -696,50 +593,46 @@ Notification.removeSlot(slotType,removeSlotCallback)
## Notification.removeSlot(slotType: SlotType) ## Notification.removeSlot
- Functionality removeSlot(slotType: SlotType): Promise\<void\>
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| **Parameters**
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
- 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\<void\> **Example**
- Example
```js ```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then((void) => { Notification.removeSlot(slotType).then(() => {
console.info("==========================>removeSlotCallback=======================>"); console.info("==========================>removeSlotCallback=======================>");
}); });
``` ```
## Notification.removeAllSlots(callback: AsyncCallback\<void\>) ## Notification.removeAllSlots
- Functionality
Removes all notification slots. This method uses a callback to return the result. removeAllSlots(callback: AsyncCallback\<void\>): void
- Parameters Removes all notification slots. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function removeAllCallBack(err) { function removeAllCallBack(err) {
...@@ -750,111 +643,41 @@ Notification.removeAllSlots(removeAllCallBack) ...@@ -750,111 +643,41 @@ Notification.removeAllSlots(removeAllCallBack)
## Notification.removeAllSlots() ## Notification.removeAllSlots
- Functionality removeAllSlots(): Promise\<void\>
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 **Example**
- Return value
Promise\<void\>
- Example
```js ```js
Notification.removeAllSlots().then((void) => { Notification.removeAllSlots().then(() => {
console.info("==========================>removeAllCallBack=======================>"); console.info("==========================>removeAllCallBack=======================>");
}); });
``` ```
## Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>) ## Notification.subscribe
- Functionality
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\>): 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| **System capability**: SystemCapability.Notification.Notification
| ---------- | -------- | ------------------------- | ---- | ---------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| info | Read-only| NotificationSubscribeInfo | Yes| Subscription information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- NotificationSubscriber **Parameters**
| Name| Readable/Writable| Type| Mandatory| Description| | Name | Readable| Writable| Type | Mandatory| Description |
| ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- | | ---------- | ---- | --- | ------------------------- | ---- | ---------------- |
| onConsume?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for receiving notifications.| | subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| onCancel?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for canceling notifications.| | info | Yes | No | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. |
| onUpdate?:(data: NotificationSortingMap) | Readable and writable| function | No| Callback for notification sorting updates.| | callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
| 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.|
- SubscribeCallbackData **Example**
| 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\<number\> | 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\<string\> | 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\<string\> | 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
```js ```js
// subscribe callback // subscribe callback
...@@ -875,24 +698,22 @@ Notification.subscribe(subscriber, info, subscribeCallback); ...@@ -875,24 +698,22 @@ Notification.subscribe(subscriber, info, subscribeCallback);
## Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) ## Notification.subscribe
- Functionality
Subscribes to a notification. This method uses a callback to return the result. subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| ---------- | -------- | ---------------------- | ---- | ---------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | ---------------- |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function subscribeCallback(err) { function subscribeCallback(err) {
...@@ -909,24 +730,22 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -909,24 +730,22 @@ Notification.subscribe(subscriber, subscribeCallback);
## Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) ## Notification.subscribe
- Functionality subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\>
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| **Parameters**
| ---------- | -------- | ------------------------- | ---- | ------------ |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| info | Read-only| NotificationSubscribeInfo | No| Subscription information.|
- 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\<void\> **Example**
- Example
```js ```js
function onConsumeCallback(err, data) { function onConsumeCallback(err, data) {
...@@ -935,31 +754,29 @@ function onConsumeCallback(err, data) { ...@@ -935,31 +754,29 @@ function onConsumeCallback(err, data) {
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
}; };
Notification.subscribe(subscriber).then((void) => { Notification.subscribe(subscriber).then(() => {
console.info("==========================>subscribeCallback=======================>"); console.info("==========================>subscribeCallback=======================>");
}); });
``` ```
## Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) ## Notification.unsubscribe
- Functionality
Unsubscribes from a notification. This method uses a callback to return the result. unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void
- Parameters Unsubscribes from a notification. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| ---------- | -------- | ---------------------- | ---- | -------------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | -------------------- |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function unsubscribeCallback(err) { function unsubscribeCallback(err) {
...@@ -976,23 +793,21 @@ Notification.unsubscribe(subscriber, unsubscribeCallback); ...@@ -976,23 +793,21 @@ Notification.unsubscribe(subscriber, unsubscribeCallback);
## Notification.unsubscribe(subscriber: NotificationSubscriber) ## Notification.unsubscribe
- Functionality unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
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| **Parameters**
| ---------- | -------- | ---------------------- | ---- | ------------ |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | ------------ |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
Promise\<void\> **Example**
- Example
```js ```js
function onConsumeCallback(err, data) { function onConsumeCallback(err, data) {
...@@ -1001,133 +816,125 @@ function onConsumeCallback(err, data) { ...@@ -1001,133 +816,125 @@ function onConsumeCallback(err, data) {
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
}; };
Notification.unsubscribe(subscriber).then((void) => { Notification.unsubscribe(subscriber).then(() => {
console.info("==========================>unsubscribeCallback=======================>"); console.info("==========================>unsubscribeCallback=======================>");
}); });
``` ```
## Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) ## Notification.enableNotification
- Functionality
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\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to enable notification.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- BundleOption **Parameters**
| Name| Readable/Writable| Type| Mandatory| Description| | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | -------- | ------ | ---- | ------ | | -------- | ---- | --- | --------------------- | ---- | -------------------- |
| bundle | Readable and writable| string | Yes| Bundle name.| | bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| uid | Readable and writable| number | No| User ID.| | enable | Yes | No | boolean | Yes | Whether to enable notification. |
- Return value | callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
function enableNotificationCallback(err) { function enableNotificationCallback(err) {
console.info("==========================>enableNotificationCallback=======================>"); console.info("==========================>enableNotificationCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.enableNotification(bundle, false, enableNotificationCallback); Notification.enableNotification(bundle, false, enableNotificationCallback);
``` ```
## Notification.enableNotification(bundle: BundleOption, enable: boolean) ## Notification.enableNotification
- Functionality
Sets whether to enable notification for a specified bundle. This method uses a promise to return the result. enableNotification(bundle: BundleOption, enable: boolean): Promise\<void\>
- 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| **System capability**: SystemCapability.Notification.Notification
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to enable notification.|
- Return value **Parameters**
Promise\<void\> | 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 ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.enableNotification(bundle, false).then((void) => { Notification.enableNotification(bundle, false).then(() => {
console.info("==========================>enableNotificationCallback=======================>"); console.info("==========================>enableNotificationCallback=======================>");
}); });
``` ```
## Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>) ## Notification.isNotificationEnabled
- Functionality isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): 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| **Parameters**
| -------- | -------- | --------------------- | ---- | ------------------------ |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
function isNotificationEnabledCallback(err, data) { function isNotificationEnabledCallback(err, data) {
console.info("==========================>isNotificationEnabledCallback=======================>"); console.info("==========================>isNotificationEnabledCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
``` ```
## Notification.isNotificationEnabled(bundle: BundleOption) ## Notification.isNotificationEnabled
isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
- 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| | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | -------- | ------------ | ---- | ---------- | | ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.| | bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
- Return value **Return value**
Promise\<boolean\> | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example **Example**
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.isNotificationEnabled(bundle).then((data) => { Notification.isNotificationEnabled(bundle).then((data) => {
console.info("==========================>isNotificationEnabledCallback=======================>"); console.info("==========================>isNotificationEnabledCallback=======================>");
...@@ -1136,23 +943,21 @@ Notification.isNotificationEnabled(bundle).then((data) => { ...@@ -1136,23 +943,21 @@ Notification.isNotificationEnabled(bundle).then((data) => {
## Notification.isNotificationEnabled(callback: AsyncCallback\<boolean\>) ## Notification.isNotificationEnabled
- Functionality
Checks whether notification is enabled for the current application. This method uses a callback to return the result. isNotificationEnabled(callback: AsyncCallback\<boolean\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | ------------------------ |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function isNotificationEnabledCallback(err, data) { function isNotificationEnabledCallback(err, data) {
...@@ -1164,21 +969,27 @@ Notification.isNotificationEnabled(isNotificationEnabledCallback); ...@@ -1164,21 +969,27 @@ Notification.isNotificationEnabled(isNotificationEnabledCallback);
## Notification.isNotificationEnabled() ## Notification.isNotificationEnabled
- Functionality isNotificationEnabled(): Promise\<boolean\>
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\<boolean\> **Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example **Example**
```js ```js
Notification.isNotificationEnabled().then((data) => { Notification.isNotificationEnabled().then((data) => {
...@@ -1188,120 +999,118 @@ Notification.isNotificationEnabled().then((data) => { ...@@ -1188,120 +999,118 @@ Notification.isNotificationEnabled().then((data) => {
## Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) ## Notification.displayBadge
- Functionality displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): 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| **Parameters**
| -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to display the badge.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
function displayBadgeCallback(err) { function displayBadgeCallback(err) {
console.info("==========================>displayBadgeCallback=======================>"); console.info("==========================>displayBadgeCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.displayBadge(bundle, false, displayBadgeCallback); Notification.displayBadge(bundle, false, displayBadgeCallback);
``` ```
## Notification.displayBadge(bundle: BundleOption, enable: boolean) ## Notification.displayBadge
- Functionality
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\<void\>
- Parameters Sets the notification slot for a specified bundle. This API uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to display the badge.|
- Return value **Parameters**
Promise\<void\> | 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 ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.displayBadge(bundle, false).then((void) => { Notification.displayBadge(bundle, false).then(() => {
console.info("==========================>displayBadgeCallback=======================>"); console.info("==========================>displayBadgeCallback=======================>");
}); });
``` ```
## Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>) ## Notification.isBadgeDisplayed
- Functionality isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): 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| **Parameters**
| -------- | -------- | --------------------- | ---- | ------------------------ |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
function isBadgeDisplayedCallback(err, data) { function isBadgeDisplayedCallback(err, data) {
console.info("==========================>isBadgeDisplayedCallback=======================>"); console.info("==========================>isBadgeDisplayedCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
``` ```
## Notification.isBadgeDisplayed(bundle: BundleOption) ## Notification.isBadgeDisplayed
isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
- 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| | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | -------- | ------------ | ---- | ---------- | | ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.| | bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
- Return value **Return value**
Promise\<boolean\> | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example **Example**
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.isBadgeDisplayed(bundle).then((data) => { Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("==========================>isBadgeDisplayedCallback=======================>"); console.info("==========================>isBadgeDisplayedCallback=======================>");
...@@ -1310,32 +1119,30 @@ Notification.isBadgeDisplayed(bundle).then((data) => { ...@@ -1310,32 +1119,30 @@ Notification.isBadgeDisplayed(bundle).then((data) => {
## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>) ## Notification.setSlotByBundle
- Functionality
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\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| slot | Read-only| NotificationSlot | Yes| Notification slot.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function setSlotByBundleCallback(err) { function setSlotByBundleCallback(err) {
console.info("==========================>setSlotByBundleCallback=======================>"); console.info("==========================>setSlotByBundleCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
var notificationSlot = { var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
...@@ -1345,91 +1152,91 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); ...@@ -1345,91 +1152,91 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) ## Notification.setSlotByBundle
- Functionality setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
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| **Parameters**
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| slot| Read-only| NotificationSlot| Yes| Notification slot.|
- 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\<void\> **Example**
- Example
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
var notificationSlot = { var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
Notification.displayBadge(bundle, notificationSlot).then((void) => { Notification.displayBadge(bundle, notificationSlot).then(() => {
console.info("==========================>setSlotByBundleCallback=======================>"); console.info("==========================>setSlotByBundleCallback=======================>");
}); });
``` ```
## Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>) ## Notification.getSlotsByBundle
- Functionality
Obtains the notification slots of a specified bundle. This method uses a callback to return the result. getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | ---------------------------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback<Array\<NotificationSlot\>> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------------------------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function getSlotsByBundleCallback(err, data) { function getSlotsByBundleCallback(err, data) {
console.info("==========================>getSlotsByBundleCallback=======================>"); console.info("==========================>getSlotsByBundleCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
``` ```
## Notification.getSlotsByBundle(bundle: BundleOption) ## Notification.getSlotsByBundle
- Functionality getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>>
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| **Parameters**
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
Promise<Array\<NotificationSlot\>> **Return value**
- Example | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise<Array\<[NotificationSlot](#notificationslot)\>> | Promise used to return the result.|
**Example**
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.getSlotsByBundle(bundle).then((data) => { Notification.getSlotsByBundle(bundle).then((data) => {
console.info("==========================>getSlotsByBundleCallback=======================>"); console.info("==========================>getSlotsByBundleCallback=======================>");
...@@ -1438,58 +1245,60 @@ Notification.getSlotsByBundle(bundle).then((data) => { ...@@ -1438,58 +1245,60 @@ Notification.getSlotsByBundle(bundle).then((data) => {
## Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>) ## Notification.getSlotNumByBundle
- Functionality
Obtains the number of notification slots of a specified bundle. This method uses a callback to return the result. getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | ------------------------- | ---- | ---------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ------------------------- | ---- | ---------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<number\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function getSlotNumByBundle(err, data) { function getSlotNumByBundle(err, data) {
console.info("==========================>getSlotNumByBundleCallback=======================>"); console.info("==========================>getSlotNumByBundleCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
``` ```
## Notification.getSlotNumByBundle(bundle: BundleOption) ## Notification.getSlotNumByBundle
- Functionality getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
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| **Parameters**
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
Promise\<number\> **Return value**
- Example | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the result.|
**Example**
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.getSlotNumByBundle(bundle).then((data) => { Notification.getSlotNumByBundle(bundle).then((data) => {
console.info("==========================>getSlotNumByBundleCallback=======================>"); console.info("==========================>getSlotNumByBundleCallback=======================>");
...@@ -1498,101 +1307,88 @@ Notification.getSlotNumByBundle(bundle).then((data) => { ...@@ -1498,101 +1307,88 @@ Notification.getSlotNumByBundle(bundle).then((data) => {
## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>) ## Notification.remove
- Functionality
Removes a notification for a specified bundle. This method uses a callback to return the result. remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| --------------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| notificationKey | Read-only| NotificationKey | Yes| Notification key.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- NotificationKey **Parameters**
| Name| Readable/Writable| Type| Mandatory| Description| | Name | Readable| Writable| Type | Mandatory| Description |
| ----- | -------- | ------ | ---- | -------- | | --------------- | ---- | --- | ----------------------------------- | ---- | -------------------- |
| id | Readable and writable| number | Yes| Notification ID.| | bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| label | Readable and writable| string | No| Notification label.| | notificationKey | Yes | No | [NotificationKey](#notificationkey) | Yes | Notification key. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Return value **Example**
void
- Example
```js ```js
function removeCallback(err) { function removeCallback(err) {
console.info("==========================>removeCallback=======================>"); console.info("==========================>removeCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
var notificationKey = { var notificationKey = {
id: 0; id: 0,
label: "label"; label: "label",
} }
Notification.remove(bundle, notificationKey, removeCallback); Notification.remove(bundle, notificationKey, removeCallback);
``` ```
## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) ## Notification.remove
- Functionality remove(bundle: BundleOption, notificationKey: NotificationKey): Promise\<void\>
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| **Parameters**
| --------------- | -------- | --------------- | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| notificationKey | Read-only| NotificationKey | Yes| Notification key.|
- 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\<void\> **Example**
- Example
```js ```js
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
var notificationKey = { var notificationKey = {
id: 0; id: 0,
label: "label"; label: "label",
} }
Notification.remove(bundle, notificationKey).then((void) => { Notification.remove(bundle, notificationKey).then(() => {
console.info("==========================>removeCallback=======================>"); console.info("==========================>removeCallback=======================>");
}); });
``` ```
## Notification.remove(hashCode: string, callback: AsyncCallback\<void\>) ## Notification.remove
- Functionality
Removes a notification. This method uses a callback to return the result. remove(hashCode: string, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | -------------------- |
| hashCode | Read-only| string | Yes| Unique notification ID.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| hashCode | Yes | No | string | Yes | Unique notification ID. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function removeCallback(err) { function removeCallback(err) {
...@@ -1604,80 +1400,74 @@ Notification.remove(hashCode, removeCallback); ...@@ -1604,80 +1400,74 @@ Notification.remove(hashCode, removeCallback);
## Notification.remove(hashCode: string) ## Notification.remove
- Functionality remove(hashCode: string): Promise\<void\>
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| **Parameters**
| -------- | -------- | ---------- | ---- | ---------- |
| hashCode | Read-only| string | Yes| Unique notification ID.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------- | ---- | ---------- |
| hashCode | Yes | No | string | Yes | Unique notification ID.|
Promise\<void\> **Example**
- Example
```js ```js
Notification.remove(hashCode).then((void) => { Notification.remove(hashCode).then(() => {
console.info("==========================>removeCallback=======================>"); console.info("==========================>removeCallback=======================>");
}); });
``` ```
## Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>) ## Notification.removeAll
- Functionality
Removes all notifications for a specified bundle. This method uses a callback to return the result. removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | ---------------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ---------------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>"); console.info("==========================>removeAllCallback=======================>");
} }
var bundle = { var bundle = {
bundle: "bundleName1"; bundle: "bundleName1",
} }
Notification.removeAll(bundle, removeAllCallback); Notification.removeAll(bundle, removeAllCallback);
``` ```
## Notification.removeAll(callback: AsyncCallback\<void\>) ## Notification.removeAll
- Functionality removeAll(callback: AsyncCallback\<void\>): 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| **Parameters**
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void **Example**
- Example
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
...@@ -1689,49 +1479,97 @@ Notification.removeAll(removeAllCallback); ...@@ -1689,49 +1479,97 @@ Notification.removeAll(removeAllCallback);
## Notification.removeAll(bundle?: BundleOption) ## Notification.removeAll
- Functionality
Removes all notifications for a specified bundle. This method uses a promise to return the result. removeAll(bundle?: BundleOption): Promise\<void\>
- Parameters Removes all notifications for a specified user. This API uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | No| Bundle information.|
- Return value **Parameters**
Promise\<void\> | Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | No | Bundle information.|
- Example **Example**
```js ```js
Notification.removeAll().then((void) => { Notification.removeAll().then(() => {
console.info("==========================>removeAllCallback=======================>"); console.info("==========================>removeAllCallback=======================>");
}); });
``` ```
## Notification.removeAll<sup>8+</sup>
removeAll(userId: number, callback: AsyncCallback\<void>): void
## Notification.getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) 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\<void\> | Yes | Callback used to return the result.|
| Name| Readable/Writable| Type| Mandatory| Description| **Example**
| -------- | -------- | ------------------------------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback<Array\<NotificationRequest\>> | Yes| Callback used to return the result.|
- Return value ```js
function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>");
}
var userId = 1
Notification.removeAll(userId, removeAllCallback);
```
## Notification.removeAll<sup>8+</sup>
removeAll(userId: number): Promise\<void>
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<Array\<NotificationRequest\>>): 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<Array\<[NotificationRequest](#notificationrequest)\>> | Yes | Callback used to return the result.|
**Example**
```js ```js
function getAllActiveNotificationsCallback(err, data) { function getAllActiveNotificationsCallback(err, data) {
...@@ -1743,21 +1581,21 @@ Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); ...@@ -1743,21 +1581,21 @@ Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
## Notification.getAllActiveNotifications() ## Notification.getAllActiveNotifications
- Functionality getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationrequest)\>\>
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\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.|
Promise\<Array\<NotificationRequest\>\> **Example**
- Example
```js ```js
Notification.getAllActiveNotifications().then((data) => { Notification.getAllActiveNotifications().then((data) => {
...@@ -1767,23 +1605,21 @@ Notification.getAllActiveNotifications().then((data) => { ...@@ -1767,23 +1605,21 @@ Notification.getAllActiveNotifications().then((data) => {
## Notification.getActiveNotificationCount(callback: AsyncCallback\<number\>) ## Notification.getActiveNotificationCount
- Functionality
Obtains the number of active notifications. This method uses a callback to return the result. getActiveNotificationCount(callback: AsyncCallback\<number\>): void
- Parameters Obtains the number of active notifications. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------------------- | ---- | ---------------------- |
| callback | Yes | No | AsyncCallback\<number\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function getActiveNotificationCountCallback(err, data) { function getActiveNotificationCountCallback(err, data) {
...@@ -1795,21 +1631,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback); ...@@ -1795,21 +1631,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
## Notification.getActiveNotificationCount() ## Notification.getActiveNotificationCount
- Functionality getActiveNotificationCount(): Promise\<number\>
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\<number\> | Promise used to return the result.|
Promise\<number> **Example**
- Example
```js ```js
Notification.getActiveNotificationCount().then((data) => { Notification.getActiveNotificationCount().then((data) => {
...@@ -1819,23 +1655,21 @@ Notification.getActiveNotificationCount().then((data) => { ...@@ -1819,23 +1655,21 @@ Notification.getActiveNotificationCount().then((data) => {
## Notification.getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) ## Notification.getActiveNotifications
- Functionality
Obtains active notifications of the current application. This method uses a callback to return the result. getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
- Parameters Obtains active notifications of this application. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | Read-only| AsyncCallback<Array\<NotificationRequest\>> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------------------ |
| callback | Yes | No | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function getActiveNotificationsCallback(err, data) { function getActiveNotificationsCallback(err, data) {
...@@ -1847,21 +1681,21 @@ Notification.getActiveNotifications(getActiveNotificationsCallback); ...@@ -1847,21 +1681,21 @@ Notification.getActiveNotifications(getActiveNotificationsCallback);
## Notification.getActiveNotifications() ## Notification.getActiveNotifications
- Functionality getActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationrequest)\>\>
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\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.|
Promise\<Array\<NotificationRequest\>\> **Example**
- Example
```js ```js
Notification.getActiveNotifications().then((data) => { Notification.getActiveNotifications().then((data) => {
...@@ -1871,24 +1705,22 @@ Notification.getActiveNotifications().then((data) => { ...@@ -1871,24 +1705,22 @@ Notification.getActiveNotifications().then((data) => {
## Notification.cancelGroup(groupName: string, callback: AsyncCallback\<void\>) ## Notification.cancelGroup<sup>8+</sup>
- Functionality
Cancels a notification group of the current application. This method uses a callback to return the result. cancelGroup(groupName: string, callback: AsyncCallback\<void\>): 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| **System capability**: SystemCapability.Notification.Notification
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| groupName | Read-only| string | Yes| Name of the notification group to cancel.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | --------------------- | ---- | ---------------------------- |
| groupName | Yes | No | string | Yes | Name of the notification group. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function cancelGroupCallback(err) { function cancelGroupCallback(err) {
...@@ -1902,23 +1734,21 @@ Notification.cancelGroup(groupName, cancelGroupCallback); ...@@ -1902,23 +1734,21 @@ Notification.cancelGroup(groupName, cancelGroupCallback);
## Notification.cancelGroup(groupName: string) ## Notification.cancelGroup<sup>8+</sup>
- Functionality cancelGroup(groupName: string): Promise\<void\>
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| **Parameters**
| --------- | -------- | ------ | ---- | -------------- |
| groupName | Read-only| string | Yes| Name of the notification group to cancel.|
- Return value | Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | ------ | ---- | -------------- |
| groupName | Yes | No | string | Yes | Name of the notification group.|
Promise\<void\> **Example**
- Example
```js ```js
var groupName = "GroupName"; var groupName = "GroupName";
...@@ -1929,25 +1759,23 @@ Notification.cancelGroup(groupName).then(() => { ...@@ -1929,25 +1759,23 @@ Notification.cancelGroup(groupName).then(() => {
## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>) ## Notification.removeGroupByBundle<sup>8+</sup>
- Functionality
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\>): 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| **System capability**: SystemCapability.Notification.Notification
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| groupName | Read-only| string | Yes| Name of the notification group to remove.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- 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\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function removeGroupByBundleCallback(err) { function removeGroupByBundleCallback(err) {
...@@ -1962,24 +1790,22 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal ...@@ -1962,24 +1790,22 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal
## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) ## Notification.removeGroupByBundle<sup>8+</sup>
- Functionality removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
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| **Parameters**
| --------- | -------- | ------------ | ---- | -------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| groupName | Read-only| string | Yes| Name of the notification group to remove.|
- 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\<void\> **Example**
- Example
```js ```js
var bundleOption = {bundle: "Bundle"}; var bundleOption = {bundle: "Bundle"};
...@@ -1991,24 +1817,22 @@ Notification.removeGroupByBundle(bundleOption, groupName).then(() => { ...@@ -1991,24 +1817,22 @@ Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
## Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>) ## Notification.setDoNotDisturbDate<sup>8+</sup>
- Functionality
Sets the DND time. This method uses a callback to return the result. setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void
- Parameters Sets the DND time. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | --------------------- | ---- | ---------------------- |
| date | Read-only| DoNotDisturbDate | Yes| DND time to set.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value **Parameters**
void | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ---------------------- |
| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```js
function setDoNotDisturbDateCallback(err) { function setDoNotDisturbDateCallback(err) {
...@@ -2016,7 +1840,7 @@ function setDoNotDisturbDateCallback(err) { ...@@ -2016,7 +1840,7 @@ function setDoNotDisturbDateCallback(err) {
} }
var doNotDisturbDate = { var doNotDisturbDate = {
type: notification.DoNotDisturbType.TYPE_ONCE, type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(), begin: new Date(),
end: new Date(2021, 11, 15, 18, 0) end: new Date(2021, 11, 15, 18, 0)
} }
...@@ -2026,27 +1850,25 @@ Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); ...@@ -2026,27 +1850,25 @@ Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
## Notification.setDoNotDisturbDate(date: DoNotDisturbDate) ## Notification.setDoNotDisturbDate<sup>8+</sup>
- Functionality setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
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| **Parameters**
| ---- | -------- | ---------------- | ---- | -------------- |
| date | Read-only| DoNotDisturbDate | Yes| DND time to set.|
- Return value | Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | ---------------- | ---- | -------------- |
| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.|
Promise\<void\> **Example**
- Example
```js ```js
var doNotDisturbDate = { var doNotDisturbDate = {
type: notification.DoNotDisturbType.TYPE_ONCE, type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(), begin: new Date(),
end: new Date(2021, 11, 15, 18, 0) end: new Date(2021, 11, 15, 18, 0)
} }
...@@ -2056,24 +1878,89 @@ Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { ...@@ -2056,24 +1878,89 @@ Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
``` ```
## Notification.setDoNotDisturbDate<sup>8+</sup>
setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): 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\<void\> | 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.setDoNotDisturbDate<sup>8+</sup>
setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
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\<DoNotDisturbDate\>) **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.getDoNotDisturbDate<sup>8+</sup>
| Name| Readable/Writable| Type| Mandatory| Description| getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
| -------- | -------- | --------------------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<DoNotDisturbDate\> | Yes| Callback used to return the result.|
- 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 ```js
function getDoNotDisturbDateCallback(err,data) { function getDoNotDisturbDateCallback(err,data) {
...@@ -2085,21 +1972,21 @@ Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); ...@@ -2085,21 +1972,21 @@ Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
## Notification.getDoNotDisturbDate() ## Notification.getDoNotDisturbDate<sup>8+</sup>
- Functionality getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
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\<DoNotDisturbDate\> **Example**
- Example
```js ```js
Notification.getDoNotDisturbDate().then((data) => { Notification.getDoNotDisturbDate().then((data) => {
...@@ -2108,24 +1995,81 @@ Notification.getDoNotDisturbDate().then((data) => { ...@@ -2108,24 +1995,81 @@ Notification.getDoNotDisturbDate().then((data) => {
``` ```
## Notification.getDoNotDisturbDate<sup>8+</sup>
getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): 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.getDoNotDisturbDate<sup>8+</sup>
## Notification.supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>) getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
- 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| | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | -------- | ------------------------ | ---- | -------------------------------- | | -------- | ---- | --- | --------------------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<boolean\> | Yes| Callback used to return the result.| | 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.supportDoNotDisturbMode<sup>8+</sup>
supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): 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\<boolean\> | Yes | Callback used to return the result.|
**Example**
```js ```js
function supportDoNotDisturbModeCallback(err,data) { function supportDoNotDisturbModeCallback(err,data) {
...@@ -2137,21 +2081,21 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); ...@@ -2137,21 +2081,21 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback);
## Notification.supportDoNotDisturbMode() ## Notification.supportDoNotDisturbMode<sup>8+</sup>
- Functionality supportDoNotDisturbMode(): Promise\<boolean\>
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 | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
Promise\<boolean\> | Promise\<boolean\> | Promise used to return the result.|
- Example **Example**
```js ```js
Notification.supportDoNotDisturbMode().then((data) => { Notification.supportDoNotDisturbMode().then((data) => {
...@@ -2161,20 +2105,22 @@ Notification.supportDoNotDisturbMode().then((data) => { ...@@ -2161,20 +2105,22 @@ Notification.supportDoNotDisturbMode().then((data) => {
## Notification.isSupportTemplate ## Notification.isSupportTemplate<sup>8+</sup>
isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): 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.| | templateName | string | Yes | Template name. |
| callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
- Example **Example**
```javascript ```javascript
var templateName = 'process'; var templateName = 'process';
...@@ -2187,25 +2133,27 @@ Notification.isSupportTemplate(templateName, isSupportTemplateCallback); ...@@ -2187,25 +2133,27 @@ Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
## Notification.isSupportTemplate ## Notification.isSupportTemplate<sup>8+</sup>
isSupportTemplate(templateName: string): Promise\<boolean\> isSupportTemplate(templateName: string): Promise\<boolean\>
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\<boolean\> | Promise used to return the result.| | Promise\<boolean\> | Promise used to return the result.|
- Example **Example**
```javascript ```javascript
var templateName = 'process'; var templateName = 'process';
...@@ -2217,974 +2165,962 @@ Notification.isSupportTemplate(templateName).then((data) => { ...@@ -2217,974 +2165,962 @@ Notification.isSupportTemplate(templateName).then((data) => {
## NotificationTemplate ## Notification.requestEnableNotification<sup>8+</sup>
Describes the template information. requestEnableNotification(callback: AsyncCallback\<void\>): void
| Name| Type| Readable| Writable| Description| Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
| ---- | ---------------------- | ---- | ---- | -------- |
| name | string | Yes| Yes| Template name.|
| data | {[key:string]: Object} | Yes| Yes| Template data.|
**System capability**: SystemCapability.Notification.Notification
**Parameters**
## WantAgent APIs | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
## Modules to Import **Example**
```js ```javascript
import WantAgent from '@ohos.wantAgent'; function requestEnabledNotificationCallback() {
console.log('------------- requestEnabledNotification --------------');
};
Notification.requestEnabledNotification(requestEnabledNotificationCallback);
``` ```
## WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>)
- Functionality
Obtains a **WantAgent** object. This method uses a callback to return the result. ## Notification.requestEnableNotification<sup>8+</sup>
- Parameters requestEnableNotification(): Promise\<void\>
Requests notification to be enabled for this application. This API uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| -------- | -------- | -------------------------- | ---- | ----------------------- |
| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.|
| callback | Read-only| AsyncCallback\<WantAgent\> | Yes| Callback used to return the result.|
- WantAgentInfo **Example**
| Name| Readable/Writable| Type| Mandatory| Description| ```javascript
| -------------- | -------- | ------------------------------- | ---- | ---------------------- | Notification.requestEnableNotification()
| wants | Readable and writable| Array\<Want\> | Yes| Array of all **Want** objects.| .then(() => {
| operationType | Readable and writable| wantAgent.OperationType | Yes| Type of the operation specified in a **Want** object.| console.info("requestEnableNotification ");
| requestCode | Readable and writable| number | Yes| Request code defined by the user.| });
| wantAgentFlags | Readable and writable| Array<wantAgent.WantAgentFlags> | No| Array of flags for using the **WantAgent** object.| ```
| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.|
-
WantAgentFlags
## Notification.enableDistributed<sup>8+</sup>
| Name| Readable/Writable| Type| Mandatory| Description| enableDistributed(enable: boolean, callback: AsyncCallback\<void\>): void
| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ |
| 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.|
- OperationType Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| ----------------- | -------- | ---- | ---- | ----------------------- |
| 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.|
- Return value **Parameters**
void | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example **Example**
```js ```javascript
import WantAgent from '@ohos.wantAgent'; function enabledNotificationCallback() {
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; console.log('----------- enableDistributed ------------');
};
// getWantAgent callback var enable = true
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]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) Notification.enableDistributed(enable, enabledNotificationCallback);
``` ```
## WantAgent.getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> ## Notification.enableDistributed<sup>8+</sup>
- Functionality enableDistributed(enable: boolean): Promise\<void>
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| | Name | Type | Mandatory| Description |
| ---- | -------- | ------------- | ---- | ------------- | | -------- | ------------------------ | ---- | -------------------------- |
| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.| | enable | boolean | Yes | Whether the device supports distributed notifications.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.|
- Return value **Example**
Promise\<WantAgent\> ```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 ## Notification.isDistributedEnabled<sup>8+</sup>
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).then((data) => { isDistributedEnabled(callback: AsyncCallback\<boolean>): void
console.info("==========================>getWantAgentCallback=======================>");
});
```
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\<string\>) **Parameters**
- Functionality | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<boolean\> | 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\<string\> | Yes| Callback used to return the result.|
- Return value
void ## Notification.isDistributedEnabled<sup>8+</sup>
- Example isDistributedEnabled(): Promise\<boolean>
```js Obtains whether this device supports distributed notifications. This API uses a promise to return the result.
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object **System capability**: SystemCapability.Notification.Notification
var wantAgent;
// getWantAgent callback **Return value**
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) | Type | Description |
| ------------------ | --------------- |
| Promise\<boolean\> | Promise used to return the result.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.|
// getBundleName callback **Example**
function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>"); ```javascript
} Notification.isDistributedEnabled()
WantAgent.getBundleName(wantAgent, getBundleNameCallback) .then((data) => {
console.log('-------- isDistributedEnabled ----------');
});
``` ```
## Notification.enableDistributedByBundle<sup>8+</sup>
## WantAgent.getBundleName(agent: WantAgent): Promise\<string\> enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): 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\<void\> | Yes | Callback used to return the result.|
| Name| Readable/Writable| Type| Mandatory| Description| **Example**
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.|
- Return value ```javascript
function enableDistributedByBundleCallback() {
console.log('----------- enableDistributedByBundle ------------');
};
Promise\<string\> var bundle = {
bundle: "bundleName1",
}
- Example var enable = true
```js Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundleCallback);
import WantAgent from '@ohos.wantAgent'; ```
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = { ## Notification.enableDistributedByBundle<sup>8+</sup>
wants: [
{ bundleenableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise<void>
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1", Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result.
abilityName: "com.example.test.MainAbility",
action: "action1", **System capability**: SystemCapability.Notification.Notification
entities: ["entity1"],
type: "MIMETYPE", **Parameters**
uri: "key={true,true,false}",
parameters: | Name | Type | Mandatory| Description |
{ | -------- | ------------------------ | ---- | -------------------------- |
mykey0: 2222, | bundle | [BundleOption](#bundleoption) | Yes | Application bundle. |
mykey1: [1, 2, 3], | enable | boolean | Yes | Whether the device supports distributed notifications. |
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss", **Example**
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], ```javascript
mykey6: true, var bundle = {
} bundle: "bundleName1",
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { var enable = true
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getBundleName(wantAgent).then((data) => { Notification.enableDistributedByBundle(bundle, enable)
console.info("==========================>getBundleNameCallback=======================>"); .then(() => {
}); console.log('-------- enableDistributedByBundle ----------');
});
``` ```
## Notification.isDistributedEnabledByBundle<sup>8+</sup>
isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void
## WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\<number\>) 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\<boolean\> | Yes | Callback used to return the result.|
**Example**
| Name| Readable/Writable| Type| Mandatory| Description| ```javascript
| -------- | -------- | ----------------------- | ---- | ----------------------------------- | function isDistributedEnabledByBundleCallback(data) {
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.| console.log('----------- isDistributedEnabledByBundle ------------', data);
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.| };
- 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 ## Notification.isDistributedEnabledByBundle<sup>8+</sup>
var wantAgent;
// getWantAgent callback isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
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) Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result.
// getUid callback **System capability**: SystemCapability.Notification.Notification
function getUidCallback(err, data) {
console.info("==========================>getUidCallback=======================>"); **Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. |
**Return value**
| Type | Description |
| ------------------ | --------------- |
| Promise\<boolean\> | Promise used to return the result.<br>**true**: The device supports distributed notifications.<br>**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.getDeviceRemindType<sup>8+</sup>
## WantAgent.getUid(agent: WantAgent): Promise\<number\> getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): 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| **Example**
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.|
- Return value ```javascript
function getDeviceRemindTypeCallback(data) {
console.log('----------- getDeviceRemindType ------------', data);
};
Promise\<number\> Notification.getDeviceRemindType(getDeviceRemindTypeCallback);
```
- Example
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object ## Notification.getDeviceRemindType<sup>8+</sup>
var wantAgent;
// WantAgentInfo object getDeviceRemindType(): Promise\<DeviceRemindType\>
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).then((data) => { Obtains the notification reminder type. This API uses a promise to return the result.
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getUid(wantAgent).then((data) => { **System capability**: SystemCapability.Notification.Notification
console.info("==========================>getUidCallback=======================>");
}); **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\<Want\>) **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| onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata))
| -------- | -------- | --------------------- | ---- | ------------------------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object.|
| callback | Read-only| AsyncCallback\<Want\> | Yes| Callback used to return the result.|
- Return value Callback for removing notifications.
void **System capability**: SystemCapability.Notification.Notification
- Example **Parameters**
```js | Name| Type| Mandatory| Description|
import WantAgent from '@ohos.wantAgent'; | ------------ | ------------------------ | ---- | -------------------------- |
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; | data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | Yes| Notification information returned.|
// WantAgent object **Example**
var wantAgent;
// getWantAgent callback ```javascript
function getWantAgentCallback(err, data) { function subscribeCallback(err) {
console.info("==========================>getWantAgentCallback=======================>"); if (err.code) {
if (err.code == 0) { console.info("subscribe failed " + JSON.stringify(err));
wantAgent = data;
} else { } else {
console.info('----getWantAgent failed!----'); console.info("subscribeCallback");
} }
} };
// WantAgentInfo object
var wantAgentInfo = { function onCancelCallback(data) {
wants: [ console.info('===> onCancel in test');
{ let req = data.request;
deviceId: "deviceId", console.info('===> onCancel callback req.id:' + req.id);
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]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) var subscriber = {
onCancel: onCancelCallback
};
// getWant callback Notification.subscribe(subscriber, subscribeCallback);
function getWantCallback(err, data) {
console.info("==========================>getWantCallback=======================>");
}
WantAgent.getWant(wantAgent, getWantCallback)
``` ```
### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap))
## WantAgent.getWant(agent: WantAgent): Promise\<Want\> 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| ```javascript
| ----- | -------- | --------- | ---- | ------------- | function subscribeCallback(err) {
| agent | Read-only| WantAgent | Yes| **WantAgent** object.| if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
- Return value function onUpdateCallback() {
console.info('===> onUpdate in test');
}
Promise\<Want\> var subscriber = {
onUpdate: onUpdateCallback
};
- Example Notification.subscribe(subscriber, subscribeCallback);
```
```js ### onConnect
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object onConnect?:void
var wantAgent;
// WantAgentInfo object Callback for subscription.
var wantAgentInfo = {
wants: [ **System capability**: SystemCapability.Notification.Notification
{
deviceId: "deviceId", **Example**
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", ```javascript
action: "action1", function subscribeCallback(err) {
entities: ["entity1"], if (err.code) {
type: "MIMETYPE", console.info("subscribe failed " + JSON.stringify(err));
uri: "key={true,true,false}", } else {
parameters: console.info("subscribeCallback");
{ }
mykey0: 2222, };
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", function onConnectCallback() {
mykey3: "ssssssssssssssssssssssssss", console.info('===> onConnect in test');
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { var subscriber = {
console.info("==========================>getWantAgentCallback=======================>"); onConnect: onConnectCallback
wantAgent = data; };
});
WantAgent.getWant(wantAgent).then((data) => { Notification.subscribe(subscriber, subscribeCallback);
console.info("==========================>getWantCallback=======================>");
});
``` ```
### onDisconnect
onDisconnect?:void
## WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\<void\>) 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| var subscriber = {
| -------- | -------- | --------------------- | ---- | --------------------------- | onDisconnect: onDisconnectCallback
| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.| };
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value Notification.subscribe(subscriber, subscribeCallback);
```
void ### onDestroy
- Example onDestroy?:void
```js Callback for service disconnection.
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object **System capability**: SystemCapability.Notification.Notification
var wantAgent;
// getWantAgent callback **Example**
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); ```javascript
if (err.code == 0) { function subscribeCallback(err) {
wantAgent = data; if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else { } else {
console.info('----getWantAgent failed!----'); console.info("subscribeCallback");
} }
} };
// WantAgentInfo object
var wantAgentInfo = { function onDestroyCallback() {
wants: [ console.info('===> onDestroy in test');
{
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) var subscriber = {
onDestroy: onDestroyCallback
};
// cancel callback Notification.subscribe(subscriber, subscribeCallback);
function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>");
}
WantAgent.cancel(wantAgent, cancelCallback)
``` ```
### onDoNotDisturbDateChange<sup>8+</sup>
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\<void\> var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
- Functionality Notification.subscribe(subscriber, subscribeCallback);
```
Cancels a **WantAgent** object. This method uses a promise to return the result.
- Parameters ### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8))
| Name| Readable/Writable| Type| Mandatory| Description| Listens for the notification enable status changes. This API uses an asynchronous callback to return the result.
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.|
- Return value **System capability**: SystemCapability.Notification.Notification
Promise\<void\> **Parameters**
- Example | Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata8)\> | Yes| Callback used to return the result.|
```js **Example**
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object ```javascript
var wantAgent; function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
// WantAgentInfo object function onEnabledNotificationChangedCallback(err, callbackData) {
var wantAgentInfo = { if (err.code) {
wants: [ console.info("subscribe failed " + JSON.stringify(err));
{ } else {
deviceId: "deviceId", console.info("bundle: ", callbackData.bundle);
bundleName: "com.neu.setResultOnAbilityResultTest1", console.info("uid: ", callbackData.uid);
abilityName: "com.example.test.MainAbility", console.info("enable: ", callbackData.enable);
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).then((data) => { var subscriber = {
console.info("==========================>getWantAgentCallback=======================>"); onEnabledNotificationChanged: onEnabledNotificationChangedCallback
wantAgent = data; };
});
WantAgent.cancel(wantAgent).then((data) => { Notification.subscribe(subscriber, subscribeCallback);
console.info("==========================>cancelCallback=======================>");
});
``` ```
## SubscribeCallbackData
**System capability**: SystemCapability.Notification.Notification
## WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>) | 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\<number\> | No | Vibration used for notification.|
- Functionality
Triggers a **WantAgent** object. This method uses a callback to return the result. ## EnabledNotificationCallbackData<sup>8+</sup>
- 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\<CompleteData\> | Yes| Callback used to return the result.|
- TriggerInfo ## DoNotDisturbDate<sup>8+</sup>
| Name| Readable/Writable| Type| Mandatory| Description| **System capability**: SystemCapability.Notification.Notification
| ---------- | -------- | -------------------- | ---- | ----------- |
| 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.|
- 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 ## DoNotDisturbType<sup>8+</sup>
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object **System capability**: SystemCapability.Notification.Notification
var wantAgent;
// 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 = { ## ContentType
code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)
```
**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\<boolean\>) ## 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| **System capability**: SystemCapability.Notification.Notification
| ---------- | -------- | ------------------------ | ---- | --------------------------------------- |
| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.|
| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.|
| callback | Read-only| AsyncCallback\<boolean\> | Yes| Callback used to return the result.|
- 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 ## NotificationKey
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object **System capability**: SystemCapability.Notification.Notification
var wantAgent1;
var wantAgent2;
// getWantAgent callback | Name | Readable| Writable| Type | Mandatory| Description |
function getWantAgentCallback(err, data) { | ----- | ---- | --- | ------ | ---- | -------- |
console.info("==========================>getWantAgentCallback=======================>"); | id | Yes | Yes | number | Yes | Notification ID. |
if (err.code == 0) { | label | Yes | Yes | string | No | Notification label.|
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]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// equal callback ## SlotType
function equalCallback(err, data) {
console.info("==========================>equalCallback=======================>");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)
```
**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\<boolean\>
- 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. |
| userInput<sup>9+</sup> | Yes | Yes | [NotificationUserInput](#notificationuserinput8) | No | User input object. |
| Name| Readable/Writable| Type| Mandatory| Description| ## NotificationBasicContent
| ---------- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.|
| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.|
- Return value **System capability**: SystemCapability.Notification.Notification
Promise\<boolean\> | 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 ## NotificationLongTextContent
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object **System capability**: SystemCapability.Notification.Notification
var wantAgent1;
var wantAgent2;
// WantAgentInfo object | Name | Readable| Writable| Type | Mandatory| Description |
var wantAgentInfo = { | -------------- | ---- | --- | ------ | ---- | -------------------------------- |
wants: [ | title | Yes | Yes | string | Yes | Notification title. |
{ | text | Yes | Yes | string | Yes | Notification content. |
deviceId: "deviceId", | additionalText | Yes | Yes | string | No | Additional information of the notification.|
bundleName: "com.neu.setResultOnAbilityResultTest1", | longText | Yes | Yes | string | Yes | Long text of the notification. |
abilityName: "com.example.test.MainAbility", | briefText | Yes | Yes | string | Yes | Brief text of the notification.|
action: "action1", | expandedTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. |
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).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent1 = data;
wantAgent2 = data;
});
WantAgent.equal(wantAgent1, wantAgent2).then((data) => { ## NotificationMultiLineContent
console.info("==========================>equalCallback=======================>");
}); **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\<string\> | 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. |
## NotificationFlagStatus<sup>8+</sup>
**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. |
## NotificationFlags<sup>8+</sup>
**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. |
| creatorUserId<sup>8+</sup>| 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. |
| groupName<sup>8+</sup>| Yes | Yes | string | No | Group notification name. |
| template<sup>8+</sup> | Yes | Yes | [NotificationTemplate](#notificationtemplate8) | No | Notification template. |
| isRemoveAllowed<sup>8+</sup> | Yes | No | boolean | No | Whether the notification can be removed. |
| source<sup>8+</sup> | Yes | No | number | No | Notification source. |
| distributedOption<sup>8+</sup> | Yes | Yes | [DistributedOptions](#distributedoptions8) | No | Option of distributed notification. |
| deviceId<sup>8+</sup> | Yes | No | string | No | Device ID of the notification source. |
| notificationFlags<sup>8+</sup> | Yes | No | [NotificationFlags](#notificationflags8) | No | Notification flags. |
## DistributedOptions<sup>8+</sup>
**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\<string> | Yes | Types of the devices to which the notification can be synchronized. |
| supportOperateDevices | Yes | Yes | Array\<string> | 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\<number\> | 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\<string\> | Yes | Array of unique notification IDs.|
## NotificationSubscribeInfo
**System capability**: SystemCapability.Notification.Notification
| Name | Readable| Writable| Type | Mandatory| Description |
| ----------- | --- | ---- | --------------- | ---- | ------------------------------- |
| bundleNames | Yes | Yes | Array\<string\> | 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. |
## NotificationTemplate<sup>8+</sup>
**System capability**: SystemCapability.Notification.Notification
| Name| Type | Readable| Writable| Description |
| ---- | ---------------------- | ---- | ---- | ---------- |
| name | string | Yes | Yes | Template name.|
| data | {[key:string]: Object} | Yes | Yes | Template data.|
## NotificationUserInput<sup>8+</sup>
**System capability**: SystemCapability.Notification.Notification
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | --- | ---- | ------ | ---- | ----------------------------- |
| inputKey | Yes | Yes | string | Yes | Key to identify the user input.|
## DeviceRemindType<sup>8+</sup>
**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. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册