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

update docs

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 47621db1
......@@ -131,33 +131,7 @@ var subscriber = {
### Publishing Notifications
Before publishing a notification, check whether the notification feature is enabled for the respective application. By default, the feature is disabled for newly installed apps.
##### Enabling Notification
Check whether notification is enabled.
```js
var bundle = {
bundle: "bundleName1",
}
Notification.isNotificationEnabled(bundle).then((data) => {
console.info("===>isNotificationEnabled success===>");
});
```
If the check result is **false**, notification is disabled. In this case, enable it.
```js
var bundle = {
bundle: "bundleName1",
}
Notification.enableNotification(bundle, true, async(err) => {
console.log("===>enableNotification success===>");
});
```
Before publishing a notification, make sure the notification feature is enabled for your application. This feature is disabled by default and can be enabled in the notification settings.
##### Publishing Notifications
......@@ -170,7 +144,7 @@ Normal Text Notification
var notificationRequest = {
id: 1,
content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
......@@ -197,25 +171,18 @@ For details about how to use **WantAgent**, see [WantAgent Development](https://
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: 'deviceId',
bundleName: 'com.example.myapplication',
abilityName: 'com.example.myapplication.MainAbility',
action: 'REMINDER_EVENT_REMOVE_NOTIFICATION',
entities: ['entity1'],
type: 'MIMETYPE',
uri: 'key={true,true,false}',
parameters: { myKey0: 1111 },
bundleName: 'ohos.samples.eTSNotification',
abilityName: 'ohos.samples.eTSNotification.MainAbility',
}
],
operationType: OperationType.START_ABILITIES,
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
// WantAgent object
......@@ -241,7 +208,7 @@ wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// Create a NotificationRequest object.
var notificationRequest = {
content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "AceApplication_Title",
text: "AceApplication_Text",
......@@ -251,7 +218,7 @@ var notificationRequest = {
id: 1,
label: 'TEST',
wantAgent: WantAgent,
slotType: notify.SlotType.OTHER_TYPES,
slotType: Notification.SlotType.OTHER_TYPES,
deliveryTime: new Date().getTime()
}
......@@ -279,11 +246,3 @@ Notification.cancel(1, "label", cancelCallback)
```
## Development Example
The following sample is provided to help you better understand how to develop notification functions:
- notification
This sample shows how to use **Notification** APIs in Extended TypeScript (eTS) to subscribe to, unsubscribe from, publish, and cancel notifications as well as enable the notification feature and check whether the feature is enabled.
# Notification Module
## Required Permissions
None
# Notification
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -12,152 +9,22 @@ None
import Notification from '@ohos.notification';
```
## System Capabilities
```js
SystemCapability.Notification.Notification
```
## Notification.publish(request: NotificationRequest, callback: AsyncCallback\<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
## Notification.publish
| Name| Readable/Writable| Type| Mandatory| Description|
| ----------- | -------- | ---------------------------- | ---- | ------------------ |
| contentType | Readable and writable| ContentType | Yes| Notification content type.|
| normal | Readable and writable| NotificationBasicContent | No| Normal text.|
| longText | Readable and writable| NotificationLongTextContent | No| Long text.|
| multiLine | Readable and writable| NotificationMultiLineContent | No| Multi-line text.|
| picture | Readable and writable| NotificationPictureContent | No| Picture-attached.|
publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
- ContentType
Publishes a notification. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Description|
| --------------------------------- | -------- | ----------- | ---------------- |
| NOTIFICATION_CONTENT_BASIC_TEXT | Read-only| ContentType | Normal text notification.|
| NOTIFICATION_CONTENT_LONG_TEXT | Read-only| ContentType | Long text notification.|
| NOTIFICATION_CONTENT_PICTURE | Read-only| ContentType | Picture-attached notification.|
| NOTIFICATION_CONTENT_CONVERSATION | Read-only| ContentType | Conversation notification.|
| NOTIFICATION_CONTENT_MULTILINE | Read-only| ContentType | Multi-line text notification.|
**System capability**: SystemCapability.Notification.Notification
- NotificationBasicContent
**Parameters**
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------- | -------- | ------ | ---- | -------------------------------- |
| title | Readable and writable| string | Yes| Notification title.|
| text | Readable and writable| string | Yes| Notification content.|
| additionalText | Readable and writable| string | Yes| Additional information of the notification.|
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | ---- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.|
| callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. |
- NotificationLongTextContent
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------- | -------- | ------ | ---- | -------------------------------- |
| title | Readable and writable| string | Yes| Notification title.|
| text | Readable and writable| string | Yes| Notification content.|
| additionalText | Readable and writable| string | Yes| Additional information of the notification.|
| longText | Readable and writable| string | Yes| Long text content of the notification.|
| briefText | Readable and writable| string | Yes| Brief text of the notification.|
| expandedTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.|
- NotificationMultiLineContent
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------- | -------- | --------------- | ---- | -------------------------------- |
| title | Readable and writable| string | Yes| Notification title.|
| text | Readable and writable| string | Yes| Notification content.|
| additionalText | Readable and writable| string | Yes| Additional information of the notification.|
| briefText | Readable and writable| string | Yes| Brief text of the notification.|
| longTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.|
| lines | Readable and writable| Array\<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
**Example**
```js
// publish callback
......@@ -168,7 +35,7 @@ function publishCallback(err) {
var notificationRequest = {
id: 1,
content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
......@@ -181,24 +48,22 @@ Notification.publish(notificationRequest, publishCallback)
## Notification.publish(request: NotificationRequest)
- Functionality
## Notification.publish
Publishes a notification. This method uses a promise to return the result.
publish(request: NotificationRequest): Promise\<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
// NotificationRequest object
var notificationRequest = {
notificationId: 1,
content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
......@@ -206,33 +71,107 @@ var notificationRequest = {
}
}
}
Notification.publish(notificationRequest).then((void) => {
Notification.publish(notificationRequest).then(() => {
console.info("==========================>publishCallback=======================>");
});
```
## Notification.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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| 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.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | --- | ---- | --------------------- | ---- | -------------------- |
| id | Yes | No | number | Yes | Notification ID. |
| label | Yes | No | string | Yes | Notification label. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
// cancel callback
......@@ -244,51 +183,47 @@ Notification.cancel(0, "label", cancelCallback)
## Notification.cancel(id: number, label? : string)
- Functionality
## Notification.cancel
Cancels a notification with the specified ID and label. This method uses a promise to return the result.
cancel(id: number, label?: string): Promise\<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|
| ----- | -------- | ------ | ---- | -------- |
| id | Read-only| number | Yes| Notification ID.|
| label | Read-only| string | No| Notification label.|
**System capability**: SystemCapability.Notification.Notification
- 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
Notification.cancel(0).then((void) => {
Notification.cancel(0).then(() => {
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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| id | Read-only| number | Yes| Notification ID.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| id | Yes | No | number | Yes | Notification ID. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
// cancel callback
......@@ -300,92 +235,66 @@ Notification.cancel(0, cancelCallback)
## Notification.cancelAll(callback: AsyncCallback\<void\>)
- Functionality
## Notification.cancelAll
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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
// cancel callback
function cancelAllback(err) {
console.info("==========================>cancelAllback=======================>");
function cancelAllCallback(err) {
console.info("==========================>cancelAllCallback=======================>");
}
Notification.cancelAll(cancelCallback)
Notification.cancelAll(cancelAllCallback)
```
## Notification.cancelAll()
- Functionality
Cancels all notifications. This method uses a promise to return the result.
## Notification.cancelAll
- Parameters
cancelAll(): Promise\<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
Notification.cancelAll().then((void) => {
console.info("==========================>cancelAllback=======================>");
Notification.cancelAll().then(() => {
console.info("==========================>cancelAllCallback=======================>");
});
```
## Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>)
- Functionality
Adds a notification slot. This method uses a callback to return the result.
- Parameters
## Notification.addSlot
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | -------------------- |
| slot | Read-only| NotificationSlot | Yes| Notification slot to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
- NotificationSlot
Adds a notification slot. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------------- | -------- | --------------- | ---- | ------------------------------------------ |
| type | Readable and writable| SlotType | Yes| Notification slot type.|
| level | Readable and writable| number | No| Notification level. If this parameter is not set, the default value is used based on the notification slot type.|
| desc | Readable and writable| string | No| Description of the notification slot.|
| badgeFlag | Readable and writable| boolean | No| Whether to display the badge.|
| bypassDnd | Readable and writable| boolean | No| Whether to bypass the system do-not-disturb (DND) setting.|
| lockscreenVisibility | Readable and writable| boolean | No| How the notification is displayed on the locked screen.|
| vibrationEnabled | Readable and writable| boolean | No| Whether vibration is enabled for the notification.|
| sound | Readable and writable| string | No| Notification sound.|
| lightEnabled | Readable and writable| boolean | No| Whether light is enabled for the notification.|
| lightColor | Readable and writable| number | No| Notification light color.|
| vibrationValues | Readable and writable| Array\<number\> | No| Notification vibration mode.|
**System capability**: SystemCapability.Notification.Notification
* Return values
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
* Example
**Example**
```js
// addSlot callback
......@@ -401,54 +310,50 @@ Notification.addSlot(notificationSlot, addSlotCallBack)
## Notification.addSlot(slot: NotificationSlot)
## Notification.addSlot
- Functionality
addSlot(slot: NotificationSlot): Promise\<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|
| ---- | -------- | ---------------- | ---- | -------------------- |
| slot | Read-only| NotificationSlot | Yes| Notification slot to add.|
**Parameters**
- Return value
| Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | ---------------- | ---- | -------------------- |
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
Promise\<void\>
- Example
**Example**
```js
// NotificationSlot object
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.addSlot(notificationSlot).then((void) => {
Notification.addSlot(notificationSlot).then(() => {
console.info("==========================>addSlotCallback=======================>");
});
```
## Notification.addSlot(type: SlotType, callback: AsyncCallback\<void\>)
- Functionality
## Notification.addSlot
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|
| -------- | -------- | --------------------- | ---- | ---------------------- |
| type | Read-only| SlotType | Yes| Type of the notification slot to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ---------------------- |
| type | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot to add.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result. |
- Example
**Example**
```js
// addSlot callback
......@@ -460,50 +365,46 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack
## Notification.addSlot(type: SlotType)
## Notification.addSlot
- Functionality
addSlot(type: SlotType): Promise\<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|
| ---- | -------- | -------- | ---- | ---------------------- |
| type | Read-only| SlotType | Yes| Type of the notification slot to add.|
**Parameters**
- Return value
| Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | -------- | ---- | ---------------------- |
| type | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot to add.|
Promise\<void\>
- Example
**Example**
```js
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then((void) => {
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("==========================>addSlotCallback=======================>");
});
```
## Notification.addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>)
- Functionality
## Notification.addSlots
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|
| -------- | -------- | ------------------------- | ---- | ------------------------ |
| slots | Read-only| Array\<NotificationSlot\> | Yes| Notification slots to add.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ------------------------- | ---- | ------------------------ |
| slots | Yes | No | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result. |
- Example
**Example**
```js
// addSlots callback
......@@ -523,23 +424,21 @@ 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|
| ----- | -------- | ------------------------- | ---- | ------------------------ |
| slots | Read-only| Array\<NotificationSlot\> | Yes| Notification slots to add.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | ---- | --- | ------------------------- | ---- | ------------------------ |
| slots | Yes | No | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.|
Promise\<void\>
- Example
**Example**
```js
// NotificationSlot object
......@@ -550,31 +449,29 @@ var notificationSlot = {
var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then((void) => {
Notification.addSlots(notificationSlotArray).then(() => {
console.info("==========================>addSlotCallback=======================>");
});
```
## Notification.getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>)
- Functionality
## Notification.getSlot
Obtains a notification slot of the specified type. This method uses a callback to return the result.
getSlot(slotType: SlotType, callback: AsyncCallback\<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|
| -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
| 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.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------------------- | ---- | ----------------------------------------------------------- |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. |
- Example
**Example**
```js
// getSlot callback
......@@ -587,23 +484,27 @@ Notification.getSlot(slotType, getSlotCallback)
## Notification.getSlot(slotType)
## Notification.getSlot
- Functionality
getSlot(slotType: SlotType): Promise\<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|
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | -------- | ---- | ----------------------------------------------------------- |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
Promise\<NotificationSlot\>
**Return value**
- Example
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<NotificationSlot\> | Promise used to return the result.|
**Example**
```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
......@@ -614,23 +515,21 @@ Notification.getSlot(slotType).then((data) => {
## Notification.getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>)
- Functionality
## Notification.getSlots
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|
| -------- | -------- | --------------------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<NotificationSlot\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
// getSlots callback
......@@ -642,21 +541,21 @@ Notification.getSlots(getSlotsCallback)
## Notification.getSlots()
## Notification.getSlots
- Functionality
getSlots(): Promise\<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
Notification.getSlots().then((data) => {
......@@ -666,24 +565,22 @@ Notification.getSlots().then((data) => {
## Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>)
- Functionality
## Notification.removeSlot
Removes a notification slot of the specified type. This method uses a callback to return the result.
removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
- Parameters
Removes a notification slot of the specified type. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- |
| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ----------------------------------------------------------- |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result. |
- Example
**Example**
```js
// removeSlot callback
......@@ -696,50 +593,46 @@ Notification.removeSlot(slotType,removeSlotCallback)
## Notification.removeSlot(slotType: SlotType)
## Notification.removeSlot
- Functionality
removeSlot(slotType: SlotType): Promise\<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|
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | -------- | ---- | ----------------------------------------------------------- |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
Promise\<void\>
- Example
**Example**
```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then((void) => {
Notification.removeSlot(slotType).then(() => {
console.info("==========================>removeSlotCallback=======================>");
});
```
## Notification.removeAllSlots(callback: AsyncCallback\<void\>)
- Functionality
## Notification.removeAllSlots
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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function removeAllCallBack(err) {
......@@ -750,111 +643,41 @@ Notification.removeAllSlots(removeAllCallBack)
## Notification.removeAllSlots()
## Notification.removeAllSlots
- Functionality
removeAllSlots(): Promise\<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
- Return value
Promise\<void\>
- Example
**Example**
```js
Notification.removeAllSlots().then((void) => {
Notification.removeAllSlots().then(() => {
console.info("==========================>removeAllCallBack=======================>");
});
```
## Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>)
- Functionality
## Notification.subscribe
Subscribes to a notification with the subscription information specified. This method uses a callback to return the result.
subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void
- Parameters
Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | ------------------------- | ---- | ---------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| info | Read-only| NotificationSubscribeInfo | Yes| Subscription information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- NotificationSubscriber
**Parameters**
| Name| Readable/Writable| Type| Mandatory| Description|
| ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- |
| onConsume?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for receiving notifications.|
| onCancel?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for canceling notifications.|
| onUpdate?:(data: NotificationSortingMap) | Readable and writable| function | No| Callback for notification sorting updates.|
| onConnect?:() | Readable and writable| function | No| Callback for subscription.|
| onDisconnect?:() | Readable and writable| function | No| Callback for unsubscription.|
| onDestroy?:() | Readable and writable| function | No| Callback for service destruction.|
| onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) | Readable and writable| function | No| Callback for DND time setting updates.|
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ------------------------- | ---- | ---------------- |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| info | Yes | No | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- SubscribeCallbackData
| Name| Readable/Writable| Type| Mandatory| Description|
| --------------- | -------- | ---------------------- | ---- | -------- |
| request | Read-only| NotificationRequest | Yes| Notification content.|
| sortingMap | Read-only| NotificationSortingMap | No| Notification sorting information.|
| reason | Read-only| number | No| Reason for deletion.|
| sound | Read-only| string | No| Sound used for notification.|
| vibrationValues | Read-only| Array\<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
**Example**
```js
// subscribe callback
......@@ -875,24 +698,22 @@ Notification.subscribe(subscriber, info, subscribeCallback);
## Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
- Functionality
## Notification.subscribe
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|
| ---------- | -------- | ---------------------- | ---- | ---------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | ---------------- |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function subscribeCallback(err) {
......@@ -909,24 +730,22 @@ Notification.subscribe(subscriber, subscribeCallback);
## Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo)
## Notification.subscribe
- Functionality
subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<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|
| ---------- | -------- | ------------------------- | ---- | ------------ |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| info | Read-only| NotificationSubscribeInfo | No| Subscription information.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ------------------------- | ---- | ------------ |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
| info | Yes | No | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Subscription information. |
Promise\<void\>
- Example
**Example**
```js
function onConsumeCallback(err, data) {
......@@ -935,31 +754,29 @@ function onConsumeCallback(err, data) {
var subscriber = {
onConsume: onConsumeCallback
};
Notification.subscribe(subscriber).then((void) => {
Notification.subscribe(subscriber).then(() => {
console.info("==========================>subscribeCallback=======================>");
});
```
## Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
- Functionality
## Notification.unsubscribe
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|
| ---------- | -------- | ---------------------- | ---- | -------------------- |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | -------------------- |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function unsubscribeCallback(err) {
......@@ -976,23 +793,21 @@ Notification.unsubscribe(subscriber, unsubscribeCallback);
## Notification.unsubscribe(subscriber: NotificationSubscriber)
## Notification.unsubscribe
- Functionality
unsubscribe(subscriber: NotificationSubscriber): Promise\<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|
| ---------- | -------- | ---------------------- | ---- | ------------ |
| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | ---- | --- | ---------------------- | ---- | ------------ |
| subscriber | Yes | No | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
Promise\<void\>
- Example
**Example**
```js
function onConsumeCallback(err, data) {
......@@ -1001,133 +816,125 @@ function onConsumeCallback(err, data) {
var subscriber = {
onConsume: onConsumeCallback
};
Notification.unsubscribe(subscriber).then((void) => {
Notification.unsubscribe(subscriber).then(() => {
console.info("==========================>unsubscribeCallback=======================>");
});
```
## Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>)
- Functionality
## Notification.enableNotification
Sets whether to enable notification for a specified bundle. This method uses a callback to return the result.
enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
- Parameters
Sets whether to enable notification for a specified bundle. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to enable notification.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- BundleOption
**Parameters**
| Name| Readable/Writable| Type| Mandatory| Description|
| ------ | -------- | ------ | ---- | ------ |
| bundle | Readable and writable| string | Yes| Bundle name.|
| uid | Readable and writable| number | No| User ID.|
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| enable | Yes | No | boolean | Yes | Whether to enable notification. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
function enableNotificationCallback(err) {
console.info("==========================>enableNotificationCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.enableNotification(bundle, false, enableNotificationCallback);
```
## Notification.enableNotification(bundle: BundleOption, enable: boolean)
- Functionality
## Notification.enableNotification
Sets whether to enable notification for a specified bundle. This method uses a promise to return the result.
enableNotification(bundle: BundleOption, enable: boolean): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to enable notification.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
Promise\<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
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.enableNotification(bundle, false).then((void) => {
Notification.enableNotification(bundle, false).then(() => {
console.info("==========================>enableNotificationCallback=======================>");
});
```
## Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<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|
| -------- | -------- | --------------------- | ---- | ------------------------ |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
function isNotificationEnabledCallback(err, data) {
console.info("==========================>isNotificationEnabledCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
```
## Notification.isNotificationEnabled(bundle: BundleOption)
## Notification.isNotificationEnabled
isNotificationEnabled(bundle: BundleOption): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
- Return value
**Return value**
Promise\<boolean\>
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.isNotificationEnabled(bundle).then((data) => {
console.info("==========================>isNotificationEnabledCallback=======================>");
......@@ -1136,23 +943,21 @@ Notification.isNotificationEnabled(bundle).then((data) => {
## Notification.isNotificationEnabled(callback: AsyncCallback\<boolean\>)
- Functionality
## Notification.isNotificationEnabled
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|
| -------- | -------- | --------------------- | ---- | ------------------------ |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function isNotificationEnabledCallback(err, data) {
......@@ -1164,21 +969,27 @@ Notification.isNotificationEnabled(isNotificationEnabledCallback);
## Notification.isNotificationEnabled()
## Notification.isNotificationEnabled
- Functionality
isNotificationEnabled(): Promise\<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
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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| 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.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| enable | Yes | No | boolean | Yes | Whether to enable notification. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
function displayBadgeCallback(err) {
console.info("==========================>displayBadgeCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.displayBadge(bundle, false, displayBadgeCallback);
```
## Notification.displayBadge(bundle: BundleOption, enable: boolean)
- Functionality
## Notification.displayBadge
Sets whether to display the badge in notifications for a specified bundle. This method uses a promise to return the result.
displayBadge(bundle: BundleOption, enable: boolean): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| enable | Read-only| boolean | Yes| Whether to display the badge.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
Promise\<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
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.displayBadge(bundle, false).then((void) => {
Notification.displayBadge(bundle, false).then(() => {
console.info("==========================>displayBadgeCallback=======================>");
});
```
## Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<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|
| -------- | -------- | --------------------- | ---- | ------------------------ |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ------------------------ |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
function isBadgeDisplayedCallback(err, data) {
console.info("==========================>isBadgeDisplayedCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
```
## Notification.isBadgeDisplayed(bundle: BundleOption)
## Notification.isBadgeDisplayed
isBadgeDisplayed(bundle: BundleOption): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
- Return value
**Return value**
Promise\<boolean\>
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("==========================>isBadgeDisplayedCallback=======================>");
......@@ -1310,32 +1119,30 @@ Notification.isBadgeDisplayed(bundle).then((data) => {
## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>)
- Functionality
## Notification.setSlotByBundle
Sets a notification slot for a specified bundle. This method uses a callback to return the result.
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void
- Parameters
Sets the notification slot for a specified bundle. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| slot | Read-only| NotificationSlot | Yes| Notification slot.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Notification slot. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function setSlotByBundleCallback(err) {
console.info("==========================>setSlotByBundleCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
......@@ -1345,91 +1152,91 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot)
## Notification.setSlotByBundle
- Functionality
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| slot| Read-only| NotificationSlot| Yes| Notification slot.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
| slot | Yes | No | [NotificationSlot](#notificationslot) | Yes | Whether to enable notification. |
Promise\<void\>
- Example
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.displayBadge(bundle, notificationSlot).then((void) => {
Notification.displayBadge(bundle, notificationSlot).then(() => {
console.info("==========================>setSlotByBundleCallback=======================>");
});
```
## Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>)
- Functionality
## Notification.getSlotsByBundle
Obtains the notification slots of a specified bundle. This method uses a callback to return the result.
getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<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|
| -------- | -------- | ---------------------------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback<Array\<NotificationSlot\>> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------------------------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function getSlotsByBundleCallback(err, data) {
console.info("==========================>getSlotsByBundleCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
```
## Notification.getSlotsByBundle(bundle: BundleOption)
## Notification.getSlotsByBundle
- Functionality
getSlotsByBundle(bundle: BundleOption): Promise<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
Promise<Array\<NotificationSlot\>>
**Return value**
- Example
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise<Array\<[NotificationSlot](#notificationslot)\>> | Promise used to return the result.|
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.getSlotsByBundle(bundle).then((data) => {
console.info("==========================>getSlotsByBundleCallback=======================>");
......@@ -1438,58 +1245,60 @@ Notification.getSlotsByBundle(bundle).then((data) => {
## Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>)
- Functionality
## Notification.getSlotNumByBundle
Obtains the number of notification slots of a specified bundle. This method uses a callback to return the result.
getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<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|
| -------- | -------- | ------------------------- | ---- | ---------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ------------------------- | ---- | ---------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<number\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function getSlotNumByBundle(err, data) {
console.info("==========================>getSlotNumByBundleCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
```
## Notification.getSlotNumByBundle(bundle: BundleOption)
## Notification.getSlotNumByBundle
- Functionality
getSlotNumByBundle(bundle: BundleOption): Promise\<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|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
Promise\<number\>
**Return value**
- Example
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the result.|
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.getSlotNumByBundle(bundle).then((data) => {
console.info("==========================>getSlotNumByBundleCallback=======================>");
......@@ -1498,101 +1307,88 @@ Notification.getSlotNumByBundle(bundle).then((data) => {
## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>)
- Functionality
## Notification.remove
Removes a notification for a specified bundle. This method uses a callback to return the result.
remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>): void
- Parameters
Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| --------------- | -------- | --------------------- | ---- | -------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| notificationKey | Read-only| NotificationKey | Yes| Notification key.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- NotificationKey
**Parameters**
| Name| Readable/Writable| Type| Mandatory| Description|
| ----- | -------- | ------ | ---- | -------- |
| id | Readable and writable| number | Yes| Notification ID.|
| label | Readable and writable| string | No| Notification label.|
| Name | Readable| Writable| Type | Mandatory| Description |
| --------------- | ---- | --- | ----------------------------------- | ---- | -------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| notificationKey | Yes | No | [NotificationKey](#notificationkey) | Yes | Notification key. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Return value
void
- Example
**Example**
```js
function removeCallback(err) {
console.info("==========================>removeCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
var notificationKey = {
id: 0;
label: "label";
id: 0,
label: "label",
}
Notification.remove(bundle, notificationKey, removeCallback);
```
## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey)
## Notification.remove
- Functionality
remove(bundle: BundleOption, notificationKey: NotificationKey): Promise\<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|
| --------------- | -------- | --------------- | ---- | ---------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| notificationKey | Read-only| NotificationKey | Yes| Notification key.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| --------------- | ---- | --- | --------------- | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information.|
| notificationKey | Yes | No | [NotificationKey](#notificationkey) | Yes | Notification key. |
Promise\<void\>
- Example
**Example**
```js
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
var notificationKey = {
id: 0;
label: "label";
id: 0,
label: "label",
}
Notification.remove(bundle, notificationKey).then((void) => {
Notification.remove(bundle, notificationKey).then(() => {
console.info("==========================>removeCallback=======================>");
});
```
## Notification.remove(hashCode: string, callback: AsyncCallback\<void\>)
- Functionality
## Notification.remove
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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| hashCode | Read-only| string | Yes| Unique notification ID.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| hashCode | Yes | No | string | Yes | Unique notification ID. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function removeCallback(err) {
......@@ -1604,80 +1400,74 @@ Notification.remove(hashCode, removeCallback);
## Notification.remove(hashCode: string)
## Notification.remove
- Functionality
remove(hashCode: string): Promise\<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|
| -------- | -------- | ---------- | ---- | ---------- |
| hashCode | Read-only| string | Yes| Unique notification ID.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------- | ---- | ---------- |
| hashCode | Yes | No | string | Yes | Unique notification ID.|
Promise\<void\>
- Example
**Example**
```js
Notification.remove(hashCode).then((void) => {
Notification.remove(hashCode).then(() => {
console.info("==========================>removeCallback=======================>");
});
```
## Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>)
- Functionality
## Notification.removeAll
Removes all notifications for a specified bundle. This method uses a callback to return the result.
removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
- Parameters
Removes all notifications for a specified bundle. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | ---------------------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ---------------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>");
}
var bundle = {
bundle: "bundleName1";
bundle: "bundleName1",
}
Notification.removeAll(bundle, removeAllCallback);
```
## Notification.removeAll(callback: AsyncCallback\<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|
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | -------------------- |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
void
- Example
**Example**
```js
function removeAllCallback(err) {
......@@ -1689,49 +1479,97 @@ Notification.removeAll(removeAllCallback);
## Notification.removeAll(bundle?: BundleOption)
- Functionality
## Notification.removeAll
Removes all notifications for a specified bundle. This method uses a promise to return the result.
removeAll(bundle?: BundleOption): Promise\<void\>
- Parameters
Removes all notifications for a specified user. This API uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | Read-only| BundleOption | No| Bundle information.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
Promise\<void\>
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | No | Bundle information.|
- Example
**Example**
```js
Notification.removeAll().then((void) => {
Notification.removeAll().then(() => {
console.info("==========================>removeAllCallback=======================>");
});
```
## Notification.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|
| -------- | -------- | ------------------------------------------- | ---- | -------------------- |
| callback | Read-only| AsyncCallback<Array\<NotificationRequest\>> | Yes| Callback used to return the result.|
**Example**
- Return value
```js
function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>");
}
var userId = 1
Notification.removeAll(userId, removeAllCallback);
```
## Notification.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
function getAllActiveNotificationsCallback(err, data) {
......@@ -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
Notification.getAllActiveNotifications().then((data) => {
......@@ -1767,23 +1605,21 @@ Notification.getAllActiveNotifications().then((data) => {
## Notification.getActiveNotificationCount(callback: AsyncCallback\<number\>)
- Functionality
## Notification.getActiveNotificationCount
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|
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ---------------------- | ---- | ---------------------- |
| callback | Yes | No | AsyncCallback\<number\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function getActiveNotificationCountCallback(err, data) {
......@@ -1795,21 +1631,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
## Notification.getActiveNotificationCount()
## Notification.getActiveNotificationCount
- Functionality
getActiveNotificationCount(): Promise\<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
Notification.getActiveNotificationCount().then((data) => {
......@@ -1819,23 +1655,21 @@ Notification.getActiveNotificationCount().then((data) => {
## Notification.getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>)
- Functionality
## Notification.getActiveNotifications
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|
| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | Read-only| AsyncCallback<Array\<NotificationRequest\>> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------------------ |
| callback | Yes | No | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function getActiveNotificationsCallback(err, data) {
......@@ -1847,21 +1681,21 @@ Notification.getActiveNotifications(getActiveNotificationsCallback);
## Notification.getActiveNotifications()
## Notification.getActiveNotifications
- Functionality
getActiveNotifications(): Promise\<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
Notification.getActiveNotifications().then((data) => {
......@@ -1871,24 +1705,22 @@ Notification.getActiveNotifications().then((data) => {
## Notification.cancelGroup(groupName: string, callback: AsyncCallback\<void\>)
- Functionality
## Notification.cancelGroup<sup>8+</sup>
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|
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| groupName | Read-only| string | Yes| Name of the notification group to cancel.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | --------------------- | ---- | ---------------------------- |
| groupName | Yes | No | string | Yes | Name of the notification group. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function cancelGroupCallback(err) {
......@@ -1902,23 +1734,21 @@ Notification.cancelGroup(groupName, cancelGroupCallback);
## Notification.cancelGroup(groupName: string)
## Notification.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|
| --------- | -------- | ------ | ---- | -------------- |
| groupName | Read-only| string | Yes| Name of the notification group to cancel.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | ------ | ---- | -------------- |
| groupName | Yes | No | string | Yes | Name of the notification group.|
Promise\<void\>
- Example
**Example**
```js
var groupName = "GroupName";
......@@ -1929,25 +1759,23 @@ Notification.cancelGroup(groupName).then(() => {
## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>)
- Functionality
## Notification.removeGroupByBundle<sup>8+</sup>
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|
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| 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.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | --------------------- | ---- | ---------------------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| groupName | Yes | No | string | Yes | Name of the notification group. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function removeGroupByBundleCallback(err) {
......@@ -1962,24 +1790,22 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal
## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string)
## Notification.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|
| --------- | -------- | ------------ | ---- | -------------- |
| bundle | Read-only| BundleOption | Yes| Bundle information.|
| groupName | Read-only| string | Yes| Name of the notification group to remove.|
**Parameters**
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| --------- | ---- | --- | ------------ | ---- | -------------- |
| bundle | Yes | No | [BundleOption](#bundleoption) | Yes | Bundle information. |
| groupName | Yes | No | string | Yes | Name of the notification group.|
Promise\<void\>
- Example
**Example**
```js
var bundleOption = {bundle: "Bundle"};
......@@ -1991,24 +1817,22 @@ Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
## Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>)
- Functionality
## Notification.setDoNotDisturbDate<sup>8+</sup>
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|
| -------- | -------- | --------------------- | ---- | ---------------------- |
| date | Read-only| DoNotDisturbDate | Yes| DND time to set.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------- | ---- | ---------------------- |
| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
- Example
**Example**
```js
function setDoNotDisturbDateCallback(err) {
......@@ -2016,7 +1840,7 @@ function setDoNotDisturbDateCallback(err) {
}
var doNotDisturbDate = {
type: notification.DoNotDisturbType.TYPE_ONCE,
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
......@@ -2026,27 +1850,25 @@ Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
## Notification.setDoNotDisturbDate(date: DoNotDisturbDate)
## Notification.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|
| ---- | -------- | ---------------- | ---- | -------------- |
| date | Read-only| DoNotDisturbDate | Yes| DND time to set.|
**Parameters**
- Return value
| Name| Readable| Writable| Type | Mandatory| Description |
| ---- | ---- | --- | ---------------- | ---- | -------------- |
| date | Yes | No | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.|
Promise\<void\>
- Example
**Example**
```js
var doNotDisturbDate = {
type: notification.DoNotDisturbType.TYPE_ONCE,
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
......@@ -2056,24 +1878,89 @@ Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
```
## Notification.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|
| -------- | -------- | --------------------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<DoNotDisturbDate\> | Yes| Callback used to return the result.|
getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
- Return value
Obtains the DND time. This API uses an asynchronous callback to return the result.
void
**System capability**: SystemCapability.Notification.Notification
- Example
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- |
| callback | Yes | No | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8)\> | Yes | Callback used to return the result.|
**Example**
```js
function getDoNotDisturbDateCallback(err,data) {
......@@ -2085,21 +1972,21 @@ Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
## Notification.getDoNotDisturbDate()
## Notification.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
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|
| -------- | -------- | ------------------------ | ---- | -------------------------------- |
| callback | Read-only| AsyncCallback\<boolean\> | Yes| Callback used to return the result.|
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- |
| userId | Yes | No | number | Yes | User ID.|
- Return value
**Return value**
void
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.|
- Example
**Example**
```js
var userId = 1
Notification.getDoNotDisturbDate(userId).then((data) => {
console.info("==========================>getDoNotDisturbDatePromise=======================>");
});
```
## Notification.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
function supportDoNotDisturbModeCallback(err,data) {
......@@ -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
Promise\<boolean\>
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
- Example
**Example**
```js
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
Checks whether a specified template exists. This method uses a callback to return the result.
Checks whether a specified template exists. This API uses an asynchronous callback to return the result.
- Parameters
**System capability**: SystemCapability.Notification.Notification
| Name| Type| Mandatory| Description|
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------ | ---- | -------------------------- |
| templateName | string | Yes| Template name.|
| callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result.|
| templateName | string | Yes | Template name. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
- Example
**Example**
```javascript
var templateName = 'process';
......@@ -2187,25 +2133,27 @@ Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
## Notification.isSupportTemplate
## Notification.isSupportTemplate<sup>8+</sup>
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.|
- Example
**Example**
```javascript
var templateName = 'process';
......@@ -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|
| ---- | ---------------------- | ---- | ---- | -------- |
| name | string | Yes| Yes| Template name.|
| data | {[key:string]: Object} | Yes| Yes| Template data.|
Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
## WantAgent APIs
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
## Modules to Import
**Example**
```js
import WantAgent from '@ohos.wantAgent';
```javascript
function requestEnabledNotificationCallback() {
console.log('------------- requestEnabledNotification --------------');
};
Notification.requestEnabledNotification(requestEnabledNotificationCallback);
```
## WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<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|
| -------- | -------- | -------------------------- | ---- | ----------------------- |
| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.|
| callback | Read-only| AsyncCallback\<WantAgent\> | Yes| Callback used to return the result.|
**System capability**: SystemCapability.Notification.Notification
- WantAgentInfo
**Example**
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------- | -------- | ------------------------------- | ---- | ---------------------- |
| wants | Readable and writable| Array\<Want\> | Yes| Array of all **Want** objects.|
| operationType | Readable and writable| wantAgent.OperationType | Yes| Type of the operation specified in a **Want** object.|
| requestCode | Readable and writable| number | Yes| Request code defined by the user.|
| wantAgentFlags | Readable and writable| Array<wantAgent.WantAgentFlags> | No| Array of flags for using the **WantAgent** object.|
| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.|
```javascript
Notification.requestEnableNotification()
.then(() => {
console.info("requestEnableNotification ");
});
```
-
WantAgentFlags
## Notification.enableDistributed<sup>8+</sup>
| Name| Readable/Writable| Type| Mandatory| Description|
| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ |
| ONE_TIME_FLAG | Read-only| enum | No| The **WantAgent** object can be used only once.|
| NO_BUILD_FLAG | Read-only| enum | No| The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.|
| CANCEL_PRESENT_FLAG | Read-only| enum | No| The existing **WantAgent** object should be canceled before a new object is generated.|
| UPDATE_PRESENT_FLAG | Read-only| enum | No| Extra data of the existing **WantAgent** object is replaced with that of the new object.|
| CONSTANT_FLAG | Read-only| enum | No| The **WantAgent** object is immutable.|
enableDistributed(enable: boolean, callback: AsyncCallback\<void\>): void
- OperationType
Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description|
| ----------------- | -------- | ---- | ---- | ----------------------- |
| UNKNOWN_TYPE | Read-only| enum | No| Unknown operation.|
| START_ABILITY | Read-only| enum | No| Starts an ability with a UI.|
| START_ABILITIES | Read-only| enum | No| Starts multiple abilities with a UI.|
| START_SERVICE | Read-only| enum | No| Starts an ability without a UI.|
| SEND_COMMON_EVENT | Read-only| enum | No| Sends a common event.|
**System capability**: SystemCapability.Notification.Notification
- Return value
**Parameters**
void
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.<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
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
```javascript
function enabledNotificationCallback() {
console.log('----------- enableDistributed ------------');
};
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
var enable = true
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
Notification.enableDistributed(enable, enabledNotificationCallback);
```
## WantAgent.getWantAgent(info: WantAgentInfo): Promise\<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|
| ---- | -------- | ------------- | ---- | ------------- |
| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.|
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.<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
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
## Notification.isDistributedEnabled<sup>8+</sup>
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
});
```
isDistributedEnabled(callback: AsyncCallback\<boolean>): void
Obtains whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
## WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\<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
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Obtains whether this device supports distributed notifications. This API uses a promise to return the result.
// WantAgent object
var wantAgent;
**System capability**: SystemCapability.Notification.Notification
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
**Return value**
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
| Type | Description |
| ------------------ | --------------- |
| Promise\<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
function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>");
}
WantAgent.getBundleName(wantAgent, getBundleNameCallback)
**Example**
```javascript
Notification.isDistributedEnabled()
.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|
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.|
**Example**
- Return value
```javascript
function enableDistributedByBundleCallback() {
console.log('----------- enableDistributedByBundle ------------');
};
Promise\<string\>
var bundle = {
bundle: "bundleName1",
}
- Example
var enable = true
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundleCallback);
```
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
## Notification.enableDistributedByBundle<sup>8+</sup>
bundleenableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise<void>
Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. |
| enable | boolean | Yes | Whether the device supports distributed notifications. |
**Example**
```javascript
var bundle = {
bundle: "bundleName1",
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
var enable = true
WantAgent.getBundleName(wantAgent).then((data) => {
console.info("==========================>getBundleNameCallback=======================>");
});
Notification.enableDistributedByBundle(bundle, enable)
.then(() => {
console.log('-------- enableDistributedByBundle ----------');
});
```
## Notification.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|
| -------- | -------- | ----------------------- | ---- | ----------------------------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.|
| callback | Read-only| AsyncCallback\<number\> | Yes| Callback used to return the result.|
```javascript
function isDistributedEnabledByBundleCallback(data) {
console.log('----------- isDistributedEnabledByBundle ------------', data);
};
- Return value
var bundle = {
bundle: "bundleName1",
}
void
Notification.enableDistributedByBundle(bundle, isDistributedEnabledByBundleCallback);
```
- Example
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
## Notification.isDistributedEnabledByBundle<sup>8+</sup>
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result.
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
**System capability**: SystemCapability.Notification.Notification
// getUid callback
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>
getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
Obtains the notification reminder type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
## WantAgent.getUid(agent: WantAgent): Promise\<number\>
**Parameters**
- Functionality
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype8)\> | Yes | Callback used to return the result.|
Obtains the user ID of a **WantAgent** object. This method uses a promise to return the result.
**Example**
- Parameters
```javascript
function getDeviceRemindTypeCallback(data) {
console.log('----------- getDeviceRemindType ------------', data);
};
Notification.getDeviceRemindType(getDeviceRemindTypeCallback);
```
| Name| Readable/Writable| Type| Mandatory| Description|
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.|
- Return value
Promise\<number\>
## Notification.getDeviceRemindType<sup>8+</sup>
- Example
getDeviceRemindType(): Promise\<DeviceRemindType\>
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Obtains the notification reminder type. This API uses a promise to return the result.
// WantAgent object
var wantAgent;
**System capability**: SystemCapability.Notification.Notification
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
**Return value**
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
| Type | Description |
| ------------------ | --------------- |
| Promise\<[DeviceRemindType](#deviceremindtype8)\> | Promise used to return the result.|
WantAgent.getUid(wantAgent).then((data) => {
console.info("==========================>getUidCallback=======================>");
});
**Example**
```javascript
Notification.getDeviceRemindType()
.then((data) => {
console.log('-------- getDeviceRemindType ----------', data);
});
```
## NotificationSubscriber
### onConsume
## WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\<Want\>)
onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata))
- Functionality
Callback for receiving notifications.
Obtains the want in a **WantAgent** object. This method uses a callback to return the result.
**System capability**: SystemCapability.Notification.Notification
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | Yes| Notification information returned.|
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | ------------------------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object.|
| callback | Read-only| AsyncCallback\<Want\> | Yes| Callback used to return the result.|
**Example**
- Return value
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
void
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));
};
- Example
var subscriber = {
onConsume: onConsumeCallback
};
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Notification.subscribe(subscriber, subscribeCallback);
```
### onCancel
// WantAgent object
var wantAgent;
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata))
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
Callback for removing notifications.
**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('----getWantAgent failed!----');
console.info("subscribeCallback");
}
};
function onCancelCallback(data) {
console.info('===> onCancel in test');
let req = data.request;
console.info('===> onCancel callback req.id:' + req.id);
}
// 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,
}
var subscriber = {
onCancel: onCancelCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap))
Callback for notification sorting updates.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Notification information returned.|
**Example**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentWantAgentFlags.UPDATE_PRESENT_FLAG]
};
function onUpdateCallback() {
console.info('===> onUpdate in test');
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
var subscriber = {
onUpdate: onUpdateCallback
};
// getWant callback
function getWantCallback(err, data) {
console.info("==========================>getWantCallback=======================>");
}
WantAgent.getWant(wantAgent, getWantCallback)
Notification.subscribe(subscriber, subscribeCallback);
```
### onConnect
onConnect?:void
## WantAgent.getWant(agent: WantAgent): Promise\<Want\>
Callback for subscription.
- Functionality
**System capability**: SystemCapability.Notification.Notification
Obtains the want in a **WantAgent** object. This method uses a promise 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 onConnectCallback() {
console.info('===> onConnect in test');
}
| Name| Readable/Writable| Type| Mandatory| Description|
| ----- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object.|
var subscriber = {
onConnect: onConnectCallback
};
- Return value
Notification.subscribe(subscriber, subscribeCallback);
```
Promise\<Want\>
### onDisconnect
- Example
onDisconnect?:void
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Callback for unsubscription.
// WantAgent object
var wantAgent;
**System capability**: SystemCapability.Notification.Notification
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
**Example**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
};
function onDisconnectCallback() {
console.info('===> onDisconnect in test');
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
var subscriber = {
onDisconnect: onDisconnectCallback
};
WantAgent.getWant(wantAgent).then((data) => {
console.info("==========================>getWantCallback=======================>");
});
Notification.subscribe(subscriber, subscribeCallback);
```
### onDestroy
onDestroy?:void
## WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\<void\>)
Callback for service disconnection.
- 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 onDestroyCallback() {
console.info('===> onDestroy in test');
}
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------- | ---- | --------------------------- |
| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
var subscriber = {
onDestroy: onDestroyCallback
};
- Return value
Notification.subscribe(subscriber, subscribeCallback);
```
void
### onDoNotDisturbDateChange<sup>8+</sup>
- Example
onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate8))
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
Callback for DND time setting updates.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
// WantAgent object
var wantAgent;
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| mode | Notification.[DoNotDisturbDate](#donotdisturbdate8) | Yes| DND time setting updates.|
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
**Example**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info('----getWantAgent failed!----');
console.info("subscribeCallback");
}
};
function onDoNotDisturbDateChangeCallback() {
console.info('===> onDoNotDisturbDateChange in test');
}
// 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,
var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8))
Listens for the notification enable status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata8)\> | Yes| Callback used to return the result.|
**Example**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onEnabledNotificationChangedCallback(err, callbackData) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("bundle: ", callbackData.bundle);
console.info("uid: ", callbackData.uid);
console.info("enable: ", callbackData.enable);
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
var subscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback
};
// cancel callback
function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>");
}
WantAgent.cancel(wantAgent, cancelCallback)
Notification.subscribe(subscriber, subscribeCallback);
```
## SubscribeCallbackData
**System capability**: SystemCapability.Notification.Notification
## WantAgent.cancel(agent: WantAgent): Promise\<void\>
| 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
Cancels a **WantAgent** object. This method uses a promise 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 cancel.|
- Return value
## DoNotDisturbDate<sup>8+</sup>
Promise\<void\>
**System capability**: SystemCapability.Notification.Notification
- Example
| 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.|
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
## DoNotDisturbType<sup>8+</sup>
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
**System capability**: SystemCapability.Notification.Notification
WantAgent.cancel(wantAgent).then((data) => {
console.info("==========================>cancelCallback=======================>");
});
```
| 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). |
## WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>)
## ContentType
- Functionality
**System capability**: SystemCapability.Notification.Notification
Triggers a **WantAgent** object. This method uses a callback to return the result.
| 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.|
- Parameters
## SlotLevel
**System capability**: SystemCapability.Notification.Notification
| 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.|
| 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.|
- TriggerInfo
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | -------------------- | ---- | ----------- |
| code | Readable and writable| number | Yes| Result code.|
| want | Readable and writable| Want | No| Want.|
| permission | Readable and writable| string | No| Permission.|
| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.|
## BundleOption
- Return value
**System capability**: SystemCapability.Notification.Notification
void
| Name | Readable| Writable| Type | Mandatory| Description |
| ------ | ---- | --- | ------ | ---- | ------ |
| bundle | Yes | Yes | string | Yes | Bundle name. |
| uid | Yes | Yes | number | No | User ID.|
- Example
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
## NotificationKey
// 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]
}
**System capability**: SystemCapability.Notification.Notification
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | ---- | --- | ------ | ---- | -------- |
| id | Yes | Yes | number | Yes | Notification ID. |
| label | Yes | Yes | string | No | Notification label.|
//Trigger callback
function triggerCallback(err, data) {
console.info("==========================>triggerCallback=======================>");
}
var triggerInfo = {
code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)
```
## SlotType
**System capability**: SystemCapability.Notification.Notification
| Name | Value | Description |
| -------------------- | -------- | ---------- |
| UNKNOWN_TYPE | SlotType | Unknown type.|
| SOCIAL_COMMUNICATION | SlotType | Notification slot for social communication.|
| SERVICE_INFORMATION | SlotType | Notification slot for service information.|
| CONTENT_INFORMATION | SlotType | Notification slot for content consultation.|
| OTHER_TYPES | SlotType | Notification slot for other purposes.|
## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>)
- Functionality
## NotificationActionButton
Checks whether two **WantAgent** objects are equal. This method uses a callback 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|
| ---------- | -------- | ------------------------ | ---- | --------------------------------------- |
| 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.|
## NotificationBasicContent
- Return value
**System capability**: SystemCapability.Notification.Notification
void
| Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- |
| title | Yes | Yes | string | Yes | Notification title. |
| text | Yes | Yes | string | Yes | Notification content. |
| additionalText | Yes | Yes | string | No | Additional information of the notification.|
- Example
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
## NotificationLongTextContent
// WantAgent object
var wantAgent1;
var wantAgent2;
**System capability**: SystemCapability.Notification.Notification
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
| Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | ---- | --- | ------ | ---- | -------------------------------- |
| title | Yes | Yes | string | Yes | Notification title. |
| text | Yes | Yes | string | Yes | Notification content. |
| additionalText | Yes | Yes | string | No | Additional information of the notification.|
| longText | Yes | Yes | string | Yes | Long text of the notification. |
| briefText | Yes | Yes | string | Yes | Brief text of the notification.|
| expandedTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. |
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// equal callback
function equalCallback(err, data) {
console.info("==========================>equalCallback=======================>");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)
```
## NotificationMultiLineContent
**System capability**: SystemCapability.Notification.Notification
| Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | --- | --- | --------------- | ---- | -------------------------------- |
| title | Yes | Yes | string | Yes | Notification title. |
| text | Yes | Yes | string | Yes | Notification content. |
| additionalText | Yes | Yes | string | No | Additional information of the notification.|
| briefText | Yes | Yes | string | Yes | Brief text of the notification.|
| longTitle | Yes | Yes | string | Yes | Title of the notification in the expanded state. |
| lines | Yes | Yes | Array\<string\> | Yes | Multi-line text of the notification. |
## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
- Functionality
## NotificationPictureContent
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 | 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. |
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | --------- | ---- | ------------- |
| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.|
| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.|
## NotificationContent
- Return value
**System capability**: SystemCapability.Notification.Notification
Promise\<boolean\>
| 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. |
- Example
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
## NotificationFlagStatus<sup>8+</sup>
// WantAgent object
var wantAgent1;
var wantAgent2;
**System capability**: SystemCapability.Notification.Notification
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
| Name | 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. |
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent1 = data;
wantAgent2 = data;
});
WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
console.info("==========================>equalCallback=======================>");
});
```
## 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.
先完成此消息的编辑!
想要评论请 注册