js-apis-notificationManager.md 145.7 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.notificationManager (NotificationManager)
E
esterzhou 已提交
2 3 4 5 6 7 8 9 10

The **notificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status.

> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

## Modules to Import

E
ester.zhou 已提交
11 12
```ts
import notificationManager from '@ohos.notificationManager';
E
esterzhou 已提交
13 14
```

E
ester.zhou 已提交
15
## notificationManager.publish
E
esterzhou 已提交
16 17 18 19 20 21 22 23 24 25 26

publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void

Publishes a notification. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                                       | Mandatory| Description                                       |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
E
ester.zhou 已提交
27
| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
28 29 30 31
| callback | AsyncCallback\<void\>                       | Yes  | Callback used to return the result.                       |

**Error codes**

E
ester.zhou 已提交
32 33
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
34 35 36 37 38 39 40 41
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
42
| 1600012  | No memory space.                          |
E
esterzhou 已提交
43 44 45

**Example**

E
ester.zhou 已提交
46
```ts
E
esterzhou 已提交
47 48 49
// publish callback
function publishCallback(err) {
    if (err) {
E
ester.zhou 已提交
50
        console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
51 52 53 54 55
    } else {
        console.info("publish success");
    }
}
// NotificationRequest object
E
ester.zhou 已提交
56
let notificationRequest: notificationManager.NotificationRequest = {
E
esterzhou 已提交
57 58
    id: 1,
    content: {
E
ester.zhou 已提交
59
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
60 61 62 63 64 65
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
66 67
};
notificationManager.publish(notificationRequest, publishCallback);
E
esterzhou 已提交
68 69
```

E
ester.zhou 已提交
70
## notificationManager.publish
E
esterzhou 已提交
71 72 73 74 75 76 77 78 79 80 81

publish(request: NotificationRequest): Promise\<void\>

Publishes a notification. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                                       | Mandatory| Description                                       |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
E
ester.zhou 已提交
82
| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
83 84 85

**Error codes**

E
ester.zhou 已提交
86 87
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
88 89 90 91 92 93 94 95
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
96
| 1600012  | No memory space.                          |
E
esterzhou 已提交
97 98 99

**Example**

E
ester.zhou 已提交
100
```ts
E
esterzhou 已提交
101
// NotificationRequest object
E
ester.zhou 已提交
102
let notificationRequest: notificationManager.NotificationRequest = {
E
esterzhou 已提交
103 104
    notificationId: 1,
    content: {
E
ester.zhou 已提交
105
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
106 107 108 109 110 111
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
112 113
};
notificationManager.publish(notificationRequest).then(() => {
E
esterzhou 已提交
114 115 116 117 118
	console.info("publish success");
});

```

E
ester.zhou 已提交
119
## notificationManager.publish
E
esterzhou 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void

Publishes a notification to a specified user. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                                       | Mandatory| Description                                       |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
E
ester.zhou 已提交
135
| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
136 137 138 139 140
| userId   | number                                      | Yes  | User ID.                          |
| callback | AsyncCallback\<void\>                       | Yes  | Callback used to return the result.                          |

**Error codes**

E
ester.zhou 已提交
141 142
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
143 144 145 146 147 148 149 150 151
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600008  | The user is not exist.                    |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
152
| 1600012  | No memory space.                          |
E
esterzhou 已提交
153 154 155

**Example**

E
ester.zhou 已提交
156
```ts
E
esterzhou 已提交
157 158 159
// publish callback
function publishCallback(err) {
    if (err) {
E
ester.zhou 已提交
160
        console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
161 162 163 164 165
    } else {
        console.info("publish success");
    }
}
// User ID
E
ester.zhou 已提交
166
let userId = 1;
E
esterzhou 已提交
167
// NotificationRequest object
E
ester.zhou 已提交
168
let notificationRequest: notificationManager.NotificationRequest = {
E
esterzhou 已提交
169 170
    id: 1,
    content: {
E
ester.zhou 已提交
171
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
172 173 174 175 176 177
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
178 179
};
notificationManager.publish(notificationRequest, userId, publishCallback);
E
esterzhou 已提交
180 181
```

E
ester.zhou 已提交
182
## notificationManager.publish
E
esterzhou 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

publish(request: NotificationRequest, userId: number): Promise\<void\>

Publishes a notification to a specified user. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    |  Type                                       | Mandatory| Description                                       |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
E
ester.zhou 已提交
198
| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
199 200 201 202
| userId   | number                                      | Yes  | User ID.                          |

**Error codes**

E
ester.zhou 已提交
203 204
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
205 206 207 208 209 210 211 212 213
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600008  | The user is not exist.                    |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
214
| 1600012  | No memory space.                          |
E
esterzhou 已提交
215 216 217

**Example**

E
ester.zhou 已提交
218
```ts
E
ester.zhou 已提交
219
let notificationRequest: notificationManager.NotificationRequest = {
E
esterzhou 已提交
220 221
    notificationId: 1,
    content: {
E
ester.zhou 已提交
222
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
223 224 225 226 227 228
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
229
};
E
esterzhou 已提交
230

E
ester.zhou 已提交
231
let userId = 1;
E
esterzhou 已提交
232

E
ester.zhou 已提交
233
notificationManager.publish(notificationRequest, userId).then(() => {
E
esterzhou 已提交
234 235 236 237 238
	console.info("publish success");
});
```


E
ester.zhou 已提交
239
## notificationManager.cancel
E
esterzhou 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

cancel(id: number, label: string, callback: AsyncCallback\<void\>): void

Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
| id       | number                | Yes  | Notification ID.              |
| label    | string                | Yes  | Notification label.            |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
257 258
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
259 260 261 262 263 264 265 266 267
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |

**Example**

E
ester.zhou 已提交
268
```ts
E
esterzhou 已提交
269 270 271
// cancel callback
function cancelCallback(err) {
    if (err) {
E
ester.zhou 已提交
272
        console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
273 274 275 276
    } else {
        console.info("cancel success");
    }
}
E
ester.zhou 已提交
277
notificationManager.cancel(0, "label", cancelCallback);
E
esterzhou 已提交
278 279
```

E
ester.zhou 已提交
280
## notificationManager.cancel
E
esterzhou 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296

cancel(id: number, label?: string): Promise\<void\>

Cancels a notification with the specified ID and optional label. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name | Type  | Mandatory| Description    |
| ----- | ------ | ---- | -------- |
| id    | number | Yes  | Notification ID.  |
| label | string | No  | Notification label.|

**Error codes**

E
ester.zhou 已提交
297 298
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
299 300 301 302 303 304 305 306 307
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |

**Example**

E
ester.zhou 已提交
308 309
```ts
notificationManager.cancel(0).then(() => {
E
esterzhou 已提交
310 311 312 313
	console.info("cancel success");
});
```

E
ester.zhou 已提交
314
## notificationManager.cancel
E
esterzhou 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

cancel(id: number, callback: AsyncCallback\<void\>): void

Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
| id       | number                | Yes  | Notification ID.              |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
331 332
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
333 334 335 336 337 338 339 340 341
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |

**Example**

E
ester.zhou 已提交
342
```ts
E
esterzhou 已提交
343 344 345
// cancel callback
function cancelCallback(err) {
    if (err) {
E
ester.zhou 已提交
346
        console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
347 348 349 350
    } else {
        console.info("cancel success");
    }
}
E
ester.zhou 已提交
351
notificationManager.cancel(0, cancelCallback);
E
esterzhou 已提交
352 353
```

E
ester.zhou 已提交
354
## notificationManager.cancelAll
E
esterzhou 已提交
355 356 357 358 359 360 361 362 363

cancelAll(callback: AsyncCallback\<void\>): void

Cancels all notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Error codes**

E
ester.zhou 已提交
364 365
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Example**

E
ester.zhou 已提交
380
```ts
E
esterzhou 已提交
381 382 383
// cancel callback
function cancelAllCallback(err) {
    if (err) {
E
ester.zhou 已提交
384
        console.error(`cancelAll failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
385 386 387 388
    } else {
        console.info("cancelAll success");
    }
}
E
ester.zhou 已提交
389
notificationManager.cancelAll(cancelAllCallback);
E
esterzhou 已提交
390 391
```

E
ester.zhou 已提交
392
## notificationManager.cancelAll
E
esterzhou 已提交
393 394 395 396 397 398 399 400 401

cancelAll(): Promise\<void\>

Cancels all notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Error codes**

E
ester.zhou 已提交
402 403
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
404 405 406 407 408 409 410 411
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
412 413
```ts
notificationManager.cancelAll().then(() => {
E
esterzhou 已提交
414 415 416 417
	console.info("cancelAll success");
});
```

E
ester.zhou 已提交
418
## notificationManager.addSlot
E
esterzhou 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433

addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void

Adds a notification slot. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
E
ester.zhou 已提交
434
| slot     | [NotificationSlot](js-apis-inner-notification-notificationSlot.md)       | Yes  | Notification slot to add.|
E
esterzhou 已提交
435 436 437 438
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
439 440
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
441 442 443 444 445
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
446
| 1600012  | No memory space.                          |
E
esterzhou 已提交
447 448 449

**Example**

E
ester.zhou 已提交
450
```ts
E
esterzhou 已提交
451 452 453
// addSlot callback
function addSlotCallBack(err) {
    if (err) {
E
ester.zhou 已提交
454
        console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
455 456 457 458 459
    } else {
        console.info("addSlot success");
    }
}
// NotificationSlot object
E
ester.zhou 已提交
460 461 462 463
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.addSlot(notificationSlot, addSlotCallBack);
E
esterzhou 已提交
464 465
```

E
ester.zhou 已提交
466
## notificationManager.addSlot
E
esterzhou 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481

addSlot(slot: NotificationSlot): Promise\<void\>

Adds a notification slot. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type            | Mandatory| Description                |
| ---- | ---------------- | ---- | -------------------- |
E
ester.zhou 已提交
482
| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes  | Notification slot to add.|
E
esterzhou 已提交
483 484 485

**Error codes**

E
ester.zhou 已提交
486 487
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
488 489 490 491 492
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
493
| 1600012  | No memory space.                          |
E
esterzhou 已提交
494 495 496

**Example**

E
ester.zhou 已提交
497
```ts
E
esterzhou 已提交
498
// NotificationSlot object
E
ester.zhou 已提交
499 500 501 502
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.addSlot(notificationSlot).then(() => {
E
esterzhou 已提交
503 504 505 506
	console.info("addSlot success");
});
```

E
ester.zhou 已提交
507
## notificationManager.addSlot
E
esterzhou 已提交
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

addSlot(type: SlotType, callback: AsyncCallback\<void\>): void

Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                 | Mandatory| Description                  |
| -------- | --------------------- | ---- | ---------------------- |
| type     | [SlotType](#slottype)              | Yes  | Type of the notification slot to add.|
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.  |

**Error codes**

E
ester.zhou 已提交
524 525
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
526 527 528 529 530
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
531
| 1600012  | No memory space.                    |
E
esterzhou 已提交
532 533 534

**Example**

E
ester.zhou 已提交
535
```ts
E
esterzhou 已提交
536 537 538
// addSlot callback
function addSlotCallBack(err) {
    if (err) {
E
ester.zhou 已提交
539
        console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
540 541 542 543
    } else {
        console.info("addSlot success");
    }
}
E
ester.zhou 已提交
544
notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
E
esterzhou 已提交
545 546
```

E
ester.zhou 已提交
547
## notificationManager.addSlot
E
esterzhou 已提交
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562

addSlot(type: SlotType): Promise\<void\>

Adds a notification slot of a specified type. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name| Type    | Mandatory| Description                  |
| ---- | -------- | ---- | ---------------------- |
| type | [SlotType](#slottype) | Yes  | Type of the notification slot to add.|

**Error codes**

E
ester.zhou 已提交
563 564
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
565 566 567 568 569
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
570
| 1600012  | No memory space.                    |
E
esterzhou 已提交
571 572 573

**Example**

E
ester.zhou 已提交
574 575
```ts
notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION).then(() => {
E
esterzhou 已提交
576 577 578 579
	console.info("addSlot success");
});
```

E
ester.zhou 已提交
580
## notificationManager.addSlots
E
esterzhou 已提交
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595

addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void

Adds an array of notification slots. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
E
ester.zhou 已提交
596
| slots    | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes  | Notification slots to add.|
E
esterzhou 已提交
597 598 599 600
| callback | AsyncCallback\<void\>     | Yes  | Callback used to return the result.    |

**Error codes**

E
ester.zhou 已提交
601 602
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
603 604 605 606 607
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
608
| 1600012  | No memory space.                          |
E
esterzhou 已提交
609 610 611

**Example**

E
ester.zhou 已提交
612
```ts
E
esterzhou 已提交
613 614 615
// addSlots callback
function addSlotsCallBack(err) {
    if (err) {
E
ester.zhou 已提交
616
        console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
617 618 619 620 621
    } else {
        console.info("addSlots success");
    }
}
// NotificationSlot object
E
ester.zhou 已提交
622 623 624
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
E
esterzhou 已提交
625
// NotificationSlotArray object
E
ester.zhou 已提交
626
let notificationSlotArray = new Array();
E
esterzhou 已提交
627 628
notificationSlotArray[0] = notificationSlot;

E
ester.zhou 已提交
629
notificationManager.addSlots(notificationSlotArray, addSlotsCallBack);
E
esterzhou 已提交
630 631
```

E
ester.zhou 已提交
632
## notificationManager.addSlots
E
esterzhou 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647

addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>

Adds an array of notification slots. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name | Type                     | Mandatory| Description                    |
| ----- | ------------------------- | ---- | ------------------------ |
E
ester.zhou 已提交
648
| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes  | Notification slots to add.|
E
esterzhou 已提交
649 650 651

**Error codes**

E
ester.zhou 已提交
652 653
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
654 655 656 657 658
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
659
| 1600012  | No memory space.                          |
E
esterzhou 已提交
660 661 662

**Example**

E
ester.zhou 已提交
663
```ts
E
esterzhou 已提交
664
// NotificationSlot object
E
ester.zhou 已提交
665 666 667
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
E
esterzhou 已提交
668
// NotificationSlotArray object
E
ester.zhou 已提交
669
let notificationSlotArray = new Array();
E
esterzhou 已提交
670 671
notificationSlotArray[0] = notificationSlot;

E
ester.zhou 已提交
672
notificationManager.addSlots(notificationSlotArray).then(() => {
E
esterzhou 已提交
673 674 675 676
	console.info("addSlots success");
});
```

E
ester.zhou 已提交
677
## notificationManager.getSlot
E
esterzhou 已提交
678 679 680 681 682 683 684 685 686 687 688 689

getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void

Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                             | Mandatory| Description                                                       |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype)                          | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
E
ester.zhou 已提交
690
| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes  | Callback used to return the result.                                       |
E
esterzhou 已提交
691 692 693

**Error codes**

E
ester.zhou 已提交
694 695
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
696 697 698 699 700 701 702 703
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
704
```ts
E
esterzhou 已提交
705 706 707
// getSlot callback
function getSlotCallback(err,data) {
    if (err) {
E
ester.zhou 已提交
708
        console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
709 710 711 712
    } else {
        console.info("getSlot success");
    }
}
E
ester.zhou 已提交
713 714
let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.getSlot(slotType, getSlotCallback);
E
esterzhou 已提交
715 716
```

E
ester.zhou 已提交
717
## notificationManager.getSlot
E
esterzhou 已提交
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738

getSlot(slotType: SlotType): Promise\<NotificationSlot\>

Obtains a notification slot of a specified type. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type    | Mandatory| Description                                                       |
| -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<NotificationSlot\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
739 740
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
741 742 743 744 745 746 747 748
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
749 750 751
```ts
let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.getSlot(slotType).then((data) => {
E
esterzhou 已提交
752 753 754 755
	console.info("getSlot success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
756
## notificationManager.getSlots
E
esterzhou 已提交
757

E
ester.zhou 已提交
758
getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void
E
esterzhou 已提交
759 760 761 762 763 764 765

Obtains all notification slots of this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

E
ester.zhou 已提交
766 767
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
768 769
| Name    | Type                             | Mandatory| Description                |
| -------- | --------------------------------- | ---- | -------------------- |
E
ester.zhou 已提交
770
| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Yes  | Callback used to return all notification slots of the current application.|
E
esterzhou 已提交
771 772 773 774 775 776 777 778 779 780 781

**Error codes**

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
782
```ts
E
esterzhou 已提交
783 784 785
// getSlots callback
function getSlotsCallback(err,data) {
    if (err) {
E
ester.zhou 已提交
786
        console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
787 788 789 790
    } else {
        console.info("getSlots success");
    }
}
E
ester.zhou 已提交
791
notificationManager.getSlots(getSlotsCallback);
E
esterzhou 已提交
792 793
```

E
ester.zhou 已提交
794
## notificationManager.getSlots
E
esterzhou 已提交
795

E
ester.zhou 已提交
796
getSlots(): Promise\<Array\<NotificationSlot>>
E
esterzhou 已提交
797 798 799 800 801 802 803 804 805

Obtains all notification slots of this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
E
ester.zhou 已提交
806
| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Promise used to return all notification slots of the current application.|
E
esterzhou 已提交
807 808 809

**Error codes**

E
ester.zhou 已提交
810 811
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
812 813 814 815 816 817 818 819
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
820 821
```ts
notificationManager.getSlots().then((data) => {
E
esterzhou 已提交
822 823 824 825
	console.info("getSlots success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
826
## notificationManager.removeSlot
E
esterzhou 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842

removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void

Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                 | Mandatory| Description                                                       |
| -------- | --------------------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype)              | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                                       |

**Error codes**

E
ester.zhou 已提交
843 844
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
845 846 847 848 849 850 851 852
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
853
```ts
E
esterzhou 已提交
854 855 856
// removeSlot callback
function removeSlotCallback(err) {
    if (err) {
E
ester.zhou 已提交
857
        console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
858 859 860 861
    } else {
        console.info("removeSlot success");
    }
}
E
ester.zhou 已提交
862 863
let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.removeSlot(slotType,removeSlotCallback);
E
esterzhou 已提交
864 865
```

E
ester.zhou 已提交
866
## notificationManager.removeSlot
E
esterzhou 已提交
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881

removeSlot(slotType: SlotType): Promise\<void\>

Removes a notification slot of a specified type. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type    | Mandatory| Description                                                       |
| -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|

**Error codes**

E
ester.zhou 已提交
882 883
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
884 885 886 887 888 889 890 891
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
892 893 894
```ts
let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.removeSlot(slotType).then(() => {
E
esterzhou 已提交
895 896 897 898
	console.info("removeSlot success");
});
```

E
ester.zhou 已提交
899
## notificationManager.removeAllSlots
E
esterzhou 已提交
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914

removeAllSlots(callback: AsyncCallback\<void\>): void

Removes all notification slots. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
915 916
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
917 918 919 920 921 922 923 924
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
925
```ts
E
esterzhou 已提交
926 927
function removeAllCallBack(err) {
    if (err) {
E
ester.zhou 已提交
928
        console.error(`removeAllSlots failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
929 930 931 932
    } else {
        console.info("removeAllSlots success");
    }
}
E
ester.zhou 已提交
933
notificationManager.removeAllSlots(removeAllCallBack);
E
esterzhou 已提交
934 935
```

E
ester.zhou 已提交
936
## notificationManager.removeAllSlots
E
esterzhou 已提交
937 938 939 940 941 942 943 944 945

removeAllSlots(): Promise\<void\>

Removes all notification slots. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Error codes**

E
ester.zhou 已提交
946 947
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
948 949 950 951 952 953 954 955
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
956 957
```ts
notificationManager.removeAllSlots().then(() => {
E
esterzhou 已提交
958 959 960 961
	console.info("removeAllSlots success");
});
```

E
ester.zhou 已提交
962
## notificationManager.setNotificationEnable
E
esterzhou 已提交
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977

setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void

Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
E
ester.zhou 已提交
978
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)   | Yes  | Bundle of the application.       |
E
esterzhou 已提交
979 980 981 982 983
| enable   | boolean               | Yes  | Whether to enable notification.            |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
984 985
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
986 987 988 989 990 991 992 993 994
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
995
```ts
E
esterzhou 已提交
996 997
function setNotificationEnablenCallback(err) {
    if (err) {
E
ester.zhou 已提交
998
        console.error(`setNotificationEnablenCallback failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
999 1000 1001 1002
    } else {
        console.info("setNotificationEnablenCallback success");
    }
}
E
ester.zhou 已提交
1003
let bundle = {
E
esterzhou 已提交
1004
    bundle: "bundleName1",
E
ester.zhou 已提交
1005 1006
};
notificationManager.setNotificationEnable(bundle, false, setNotificationEnablenCallback);
E
esterzhou 已提交
1007 1008
```

E
ester.zhou 已提交
1009
## notificationManager.setNotificationEnable
E
esterzhou 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024

setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\>

Sets whether to enable notification for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1025
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1026 1027 1028 1029
| enable | boolean      | Yes  | Whether to enable notification.  |

**Error codes**

E
ester.zhou 已提交
1030 1031
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1032 1033 1034 1035 1036 1037 1038 1039 1040
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1041 1042
```ts
let bundle = {
E
esterzhou 已提交
1043
    bundle: "bundleName1",
E
ester.zhou 已提交
1044 1045
};
notificationManager.setNotificationEnable(bundle, false).then(() => {
E
esterzhou 已提交
1046 1047 1048 1049
	console.info("setNotificationEnable success");
});
```

E
ester.zhou 已提交
1050
## notificationManager.isNotificationEnabled
E
esterzhou 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065

isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void

Checks whether notification is enabled for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name    | Type                 | Mandatory| Description                    |
| -------- | --------------------- | ---- | ------------------------ |
E
ester.zhou 已提交
1066
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | Yes  | Bundle of the application.           |
E
ester.zhou 已提交
1067
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|
E
esterzhou 已提交
1068 1069 1070

**Error codes**

E
ester.zhou 已提交
1071 1072
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1082
```ts
E
esterzhou 已提交
1083 1084
function isNotificationEnabledCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1085
        console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1086 1087 1088 1089
    } else {
        console.info("isNotificationEnabled success");
    }
}
E
ester.zhou 已提交
1090
let bundle = {
E
esterzhou 已提交
1091
    bundle: "bundleName1",
E
ester.zhou 已提交
1092 1093
};
notificationManager.isNotificationEnabled(bundle, isNotificationEnabledCallback);
E
esterzhou 已提交
1094 1095
```

E
ester.zhou 已提交
1096
## notificationManager.isNotificationEnabled
E
esterzhou 已提交
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111

isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>

Checks whether notification is enabled for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1112
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1113 1114 1115 1116 1117 1118 1119 1120 1121

**Return value**

| Type              | Description                                               |
| ------------------ | --------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
1122 1123
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1124 1125 1126 1127 1128 1129 1130 1131 1132
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1133 1134
```ts
let bundle = {
E
esterzhou 已提交
1135
    bundle: "bundleName1",
E
ester.zhou 已提交
1136 1137
};
notificationManager.isNotificationEnabled(bundle).then((data) => {
E
esterzhou 已提交
1138 1139 1140 1141
	console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1142
## notificationManager.isNotificationEnabled
E
esterzhou 已提交
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157

isNotificationEnabled(callback: AsyncCallback\<boolean\>): void

Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                    |
| -------- | --------------------- | ---- | ------------------------ |
E
ester.zhou 已提交
1158
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|
E
esterzhou 已提交
1159 1160 1161

**Error codes**

E
ester.zhou 已提交
1162 1163
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1164 1165 1166 1167 1168 1169 1170 1171
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
1172
```ts
E
esterzhou 已提交
1173 1174
function isNotificationEnabledCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1175
        console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1176 1177 1178 1179 1180
    } else {
        console.info("isNotificationEnabled success");
    }
}

E
ester.zhou 已提交
1181
notificationManager.isNotificationEnabled(isNotificationEnabledCallback);
E
esterzhou 已提交
1182 1183
```

E
ester.zhou 已提交
1184
## notificationManager.isNotificationEnabled
E
esterzhou 已提交
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195

isNotificationEnabled(): Promise\<boolean\>

Checks whether notification is enabled for the current application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |

**Example**

```ts
notificationManager.isNotificationEnabled().then((data) => {
	console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
});
```

## notificationManager.isNotificationEnabled

isNotificationEnabled(userId: number, callback: AsyncCallback\<boolean\>): void

Checks whether notification is enabled for a specified user. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                    |
| -------- | --------------------- | ---- | ------------------------ |
| userId   | number                | Yes  | User ID.|
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|

**Error codes**

For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

```ts
function isNotificationEnabledCallback(err, data) {
    if (err) {
        console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("isNotificationEnabled success");
    }
}

let userId = 1;

notificationManager.isNotificationEnabled(userId, isNotificationEnabledCallback);
```

## notificationManager.isNotificationEnabled

isNotificationEnabled(userId: number): Promise\<boolean\>

Checks whether notification is enabled for a specified user. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

E
esterzhou 已提交
1278 1279 1280 1281
**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1282
| userId | number       | Yes  | User ID.|
E
esterzhou 已提交
1283 1284 1285 1286 1287 1288 1289 1290 1291

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
1292 1293
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1294 1295 1296 1297 1298
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
E
ester.zhou 已提交
1299
| 1600008  | The user is not exist..                  |
E
esterzhou 已提交
1300 1301 1302

**Example**

E
ester.zhou 已提交
1303
```ts
E
ester.zhou 已提交
1304 1305 1306
let userId = 1;

notificationManager.isNotificationEnabled(userId).then((data) => {
E
esterzhou 已提交
1307 1308 1309 1310
	console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1311
## notificationManager.displayBadge
E
esterzhou 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326

displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void

Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
E
ester.zhou 已提交
1327
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | Yes  | Bundle of the application.          |
E
esterzhou 已提交
1328 1329 1330 1331 1332
| enable   | boolean               | Yes  | Whether to enable notification.            |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
1333 1334
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1335 1336 1337 1338 1339 1340 1341 1342 1343
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1344
```ts
E
esterzhou 已提交
1345 1346
function displayBadgeCallback(err) {
    if (err) {
E
ester.zhou 已提交
1347
        console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1348 1349 1350 1351
    } else {
        console.info("displayBadge success");
    }
}
E
ester.zhou 已提交
1352
let bundle = {
E
esterzhou 已提交
1353
    bundle: "bundleName1",
E
ester.zhou 已提交
1354 1355
};
notificationManager.displayBadge(bundle, false, displayBadgeCallback);
E
esterzhou 已提交
1356 1357
```

E
ester.zhou 已提交
1358
## notificationManager.displayBadge
E
esterzhou 已提交
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373

displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>

Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1374
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1375 1376 1377 1378
| enable | boolean      | Yes  | Whether to enable notification.  |

**Error codes**

E
ester.zhou 已提交
1379 1380
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1381 1382 1383 1384 1385 1386 1387 1388 1389
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1390 1391
```ts
let bundle = {
E
esterzhou 已提交
1392
    bundle: "bundleName1",
E
ester.zhou 已提交
1393 1394
};
notificationManager.displayBadge(bundle, false).then(() => {
E
esterzhou 已提交
1395 1396 1397 1398
	console.info("displayBadge success");
});
```

E
ester.zhou 已提交
1399
## notificationManager.isBadgeDisplayed
E
esterzhou 已提交
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414

isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void

Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                    |
| -------- | --------------------- | ---- | ------------------------ |
E
ester.zhou 已提交
1415
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | Yes  | Bundle of the application.              |
E
esterzhou 已提交
1416 1417 1418 1419
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
1420 1421
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1422 1423 1424 1425 1426 1427 1428 1429 1430
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1431
```ts
E
esterzhou 已提交
1432 1433
function isBadgeDisplayedCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1434
        console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1435 1436 1437 1438
    } else {
        console.info("isBadgeDisplayed success");
    }
}
E
ester.zhou 已提交
1439
let bundle = {
E
esterzhou 已提交
1440
    bundle: "bundleName1",
E
ester.zhou 已提交
1441 1442
};
notificationManager.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
E
esterzhou 已提交
1443 1444
```

E
ester.zhou 已提交
1445
## notificationManager.isBadgeDisplayed
E
esterzhou 已提交
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460

isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>

Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1461
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1462 1463 1464 1465 1466 1467 1468 1469 1470

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
1471 1472
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1473 1474 1475 1476 1477 1478 1479 1480 1481
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1482 1483
```ts
let bundle = {
E
esterzhou 已提交
1484
    bundle: "bundleName1",
E
ester.zhou 已提交
1485 1486
};
notificationManager.isBadgeDisplayed(bundle).then((data) => {
E
esterzhou 已提交
1487 1488 1489 1490
	console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
## notificationManager.setBadgeNumber<sup>10+</sup>

setBadgeNumber(badgeNumber: number): Promise\<void\>

Sets the notification badge number. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name     | Type  | Mandatory| Description      |
| ----------- | ------ | ---- | ---------- |
| badgeNumber | number | Yes  | Notification badge number to set.|

**Error codes**

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
1512
| 1600012  | No memory space.                          |
E
ester.zhou 已提交
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546

**Example**

```ts
let badgeNumber = 10
notificationManager.setBadgeNumber(badgeNumber).then(() => {
	console.info("displayBadge success");
});
```

## notificationManager.setBadgeNumber<sup>10+</sup>

setBadgeNumber(badgeNumber: number, callback: AsyncCallback\<void\>): void

Sets the notification badge number. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name     | Type                 | Mandatory| Description              |
| ----------- | --------------------- | ---- | ------------------ |
| badgeNumber | number                | Yes  | Notification badge number to set.        |
| callback    | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
1547
| 1600012  | No memory space.                          |
E
ester.zhou 已提交
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563

**Example**

```ts
function setBadgeNumberCallback(err) {
    if (err) {
        console.info(`displayBadge failed code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("displayBadge success");
    }
}

let badgeNumber = 10
notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback);
```

E
ester.zhou 已提交
1564
## notificationManager.setSlotByBundle
E
esterzhou 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579

setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void

Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
E
ester.zhou 已提交
1580 1581
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | Yes  | Bundle of the application.          |
| slot     | [NotificationSlot](js-apis-inner-notification-notificationSlot.md)      | Yes  | Notification slot.            |
E
esterzhou 已提交
1582 1583 1584 1585
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
1586 1587
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1588 1589 1590 1591 1592 1593 1594 1595 1596
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1597
```ts
E
esterzhou 已提交
1598 1599
function setSlotByBundleCallback(err) {
    if (err) {
E
ester.zhou 已提交
1600
        console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1601 1602 1603 1604
    } else {
        console.info("setSlotByBundle success");
    }
}
E
ester.zhou 已提交
1605
let bundle = {
E
esterzhou 已提交
1606
    bundle: "bundleName1",
E
ester.zhou 已提交
1607 1608 1609 1610 1611
};
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
E
esterzhou 已提交
1612 1613
```

E
ester.zhou 已提交
1614
## notificationManager.setSlotByBundle
E
esterzhou 已提交
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629

setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>

Sets the notification slot for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1630 1631
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
| slot   | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes  | Notification slot.|
E
esterzhou 已提交
1632 1633 1634

**Error codes**

E
ester.zhou 已提交
1635 1636
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1637 1638 1639 1640 1641 1642 1643 1644 1645
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1646 1647
```ts
let bundle = {
E
esterzhou 已提交
1648
    bundle: "bundleName1",
E
ester.zhou 已提交
1649 1650 1651 1652 1653
};
let notificationSlot = {
    type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.setSlotByBundle(bundle, notificationSlot).then(() => {
E
esterzhou 已提交
1654 1655 1656 1657
	console.info("setSlotByBundle success");
});
```

E
ester.zhou 已提交
1658
## notificationManager.getSlotsByBundle
E
esterzhou 已提交
1659

E
ester.zhou 已提交
1660
getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<NotificationSlot>>): void
E
esterzhou 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673

Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                                    | Mandatory| Description                |
| -------- | ---------------------------------------- | ---- | -------------------- |
E
ester.zhou 已提交
1674
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)                             | Yes  | Bundle of the application.          |
E
ester.zhou 已提交
1675
| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)>> | Yes  | Callback used to return the result.|
E
esterzhou 已提交
1676 1677 1678

**Error codes**

E
ester.zhou 已提交
1679 1680
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1681 1682 1683 1684 1685 1686 1687 1688 1689
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1690
```ts
E
esterzhou 已提交
1691 1692
function getSlotsByBundleCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1693
        console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1694 1695 1696 1697
    } else {
        console.info("getSlotsByBundle success");
    }
}
E
ester.zhou 已提交
1698
let bundle = {
E
esterzhou 已提交
1699
    bundle: "bundleName1",
E
ester.zhou 已提交
1700 1701
};
notificationManager.getSlotsByBundle(bundle, getSlotsByBundleCallback);
E
esterzhou 已提交
1702 1703
```

E
ester.zhou 已提交
1704
## notificationManager.getSlotsByBundle
E
esterzhou 已提交
1705

E
ester.zhou 已提交
1706
getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>>
E
esterzhou 已提交
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719

Obtains the notification slots of a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1720
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1721 1722 1723 1724 1725

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
E
ester.zhou 已提交
1726
| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)>> | Promise used to return the result.|
E
esterzhou 已提交
1727 1728 1729

**Error codes**

E
ester.zhou 已提交
1730 1731
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1732 1733 1734 1735 1736 1737 1738 1739 1740
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1741 1742
```ts
let bundle = {
E
esterzhou 已提交
1743
    bundle: "bundleName1",
E
ester.zhou 已提交
1744 1745
};
notificationManager.getSlotsByBundle(bundle).then((data) => {
E
esterzhou 已提交
1746 1747 1748 1749
	console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1750
## notificationManager.getSlotNumByBundle
E
esterzhou 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765

getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void

Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                     | Mandatory| Description                  |
| -------- | ------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
1766
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)              | Yes  | Bundle of the application.            |
E
esterzhou 已提交
1767 1768 1769 1770
| callback | AsyncCallback\<number\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
1771 1772
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1782
```ts
E
esterzhou 已提交
1783 1784
function getSlotNumByBundleCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1785
        console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1786 1787 1788 1789
    } else {
        console.info("getSlotNumByBundle success");
    }
}
E
ester.zhou 已提交
1790
let bundle = {
E
esterzhou 已提交
1791
    bundle: "bundleName1",
E
ester.zhou 已提交
1792 1793
};
notificationManager.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
E
esterzhou 已提交
1794 1795
```

E
ester.zhou 已提交
1796
## notificationManager.getSlotNumByBundle
E
esterzhou 已提交
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811

getSlotNumByBundle(bundle: BundleOption): Promise\<number\>

Obtains the number of notification slots of a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
1812
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle of the application.|
E
esterzhou 已提交
1813 1814 1815 1816 1817 1818 1819 1820 1821

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
1822 1823
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1824 1825 1826 1827 1828 1829 1830 1831 1832
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
1833 1834
```ts
let bundle = {
E
esterzhou 已提交
1835
    bundle: "bundleName1",
E
ester.zhou 已提交
1836 1837
};
notificationManager.getSlotNumByBundle(bundle).then((data) => {
E
esterzhou 已提交
1838 1839 1840 1841 1842
	console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
1843
## notificationManager.getAllActiveNotifications
E
esterzhou 已提交
1844

E
ester.zhou 已提交
1845
getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void
E
esterzhou 已提交
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858

Obtains all active notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                |
| -------- | ------------------------------------------------------------ | ---- | -------------------- |
E
ester.zhou 已提交
1859
| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | Yes  | Callback used to return the result.|
E
esterzhou 已提交
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870

**Error codes**

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
1871
```ts
E
esterzhou 已提交
1872 1873
function getAllActiveNotificationsCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1874
        console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1875 1876 1877 1878 1879
    } else {
        console.info("getAllActiveNotifications success");
    }
}

E
ester.zhou 已提交
1880
notificationManager.getAllActiveNotifications(getAllActiveNotificationsCallback);
E
esterzhou 已提交
1881 1882
```

E
ester.zhou 已提交
1883
## notificationManager.getAllActiveNotifications
E
esterzhou 已提交
1884

E
ester.zhou 已提交
1885
getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\>
E
esterzhou 已提交
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898

Obtains all active notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
E
ester.zhou 已提交
1899
| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | Promise used to return the result.|
E
esterzhou 已提交
1900 1901 1902

**Error codes**

E
ester.zhou 已提交
1903 1904
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1905 1906 1907 1908 1909 1910 1911 1912
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
1913 1914
```ts
notificationManager.getAllActiveNotifications().then((data) => {
E
esterzhou 已提交
1915 1916 1917 1918
	console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1919
## notificationManager.getActiveNotificationCount
E
esterzhou 已提交
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934

getActiveNotificationCount(callback: AsyncCallback\<number\>): void

Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                  | Mandatory| Description                  |
| -------- | ---------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<number\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
1935 1936
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1937 1938 1939 1940 1941 1942 1943 1944
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
1945
```ts
E
esterzhou 已提交
1946 1947
function getActiveNotificationCountCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
1948
        console.error(`getActiveNotificationCount failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
1949 1950 1951 1952 1953
    } else {
        console.info("getActiveNotificationCount success");
    }
}

E
ester.zhou 已提交
1954
notificationManager.getActiveNotificationCount(getActiveNotificationCountCallback);
E
esterzhou 已提交
1955 1956
```

E
ester.zhou 已提交
1957
## notificationManager.getActiveNotificationCount
E
esterzhou 已提交
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972

getActiveNotificationCount(): Promise\<number\>

Obtains the number of active notifications of this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Return value**

| Type             | Description                                       |
| ----------------- | ------------------------------------------- |
| Promise\<number\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
1973 1974
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
1975 1976 1977 1978 1979 1980 1981 1982
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
1983 1984
```ts
notificationManager.getActiveNotificationCount().then((data) => {
E
esterzhou 已提交
1985 1986 1987 1988
	console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
1989
## notificationManager.getActiveNotifications
E
esterzhou 已提交
1990

E
ester.zhou 已提交
1991
getActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void
E
esterzhou 已提交
1992 1993 1994 1995 1996 1997 1998 1999 2000

Obtains active notifications of this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name    | Type                                                        | Mandatory| Description                          |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
E
ester.zhou 已提交
2001
| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | Yes  | Callback used to return the result.|
E
esterzhou 已提交
2002 2003 2004

**Error codes**

E
ester.zhou 已提交
2005 2006
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2007 2008 2009 2010 2011 2012 2013 2014
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2015
```ts
E
esterzhou 已提交
2016 2017
function getActiveNotificationsCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
2018
        console.error(`getActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2019 2020 2021 2022 2023
    } else {
        console.info("getActiveNotifications success");
    }
}

E
ester.zhou 已提交
2024
notificationManager.getActiveNotifications(getActiveNotificationsCallback);
E
esterzhou 已提交
2025 2026
```

E
ester.zhou 已提交
2027
## notificationManager.getActiveNotifications
E
esterzhou 已提交
2028

E
ester.zhou 已提交
2029
getActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\>
E
esterzhou 已提交
2030 2031 2032 2033 2034 2035 2036 2037 2038

Obtains active notifications of this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Return value**

| Type                                                        | Description                                   |
| ------------------------------------------------------------ | --------------------------------------- |
E
ester.zhou 已提交
2039
| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | Promise used to return the result.|
E
esterzhou 已提交
2040 2041 2042

**Error codes**

E
ester.zhou 已提交
2043 2044
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2045 2046 2047 2048 2049 2050 2051 2052
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2053 2054
```ts
notificationManager.getActiveNotifications().then((data) => {
E
esterzhou 已提交
2055 2056 2057 2058
	console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
2059
## notificationManager.cancelGroup
E
esterzhou 已提交
2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070

cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void

Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name     | Type                 | Mandatory| Description                        |
| --------- | --------------------- | ---- | ---------------------------- |
E
ester.zhou 已提交
2071
| groupName | string                | Yes  | Name of the notification group, which is specified through [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) when the notification is published.|
E
esterzhou 已提交
2072 2073 2074 2075
| callback  | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2076 2077
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2078 2079 2080 2081 2082 2083 2084 2085
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2086
```ts
E
esterzhou 已提交
2087 2088
function cancelGroupCallback(err) {
    if (err) {
E
ester.zhou 已提交
2089
        console.error(`cancelGroup failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2090 2091 2092 2093 2094
    } else {
        console.info("cancelGroup success");
    }
}

E
ester.zhou 已提交
2095
let groupName = "GroupName";
E
esterzhou 已提交
2096

E
ester.zhou 已提交
2097
notificationManager.cancelGroup(groupName, cancelGroupCallback);
E
esterzhou 已提交
2098 2099
```

E
ester.zhou 已提交
2100
## notificationManager.cancelGroup
E
esterzhou 已提交
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115

cancelGroup(groupName: string): Promise\<void\>

Cancels notifications under a notification group of this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name     | Type  | Mandatory| Description          |
| --------- | ------ | ---- | -------------- |
| groupName | string | Yes  | Name of the notification group.|

**Error codes**

E
ester.zhou 已提交
2116 2117
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2118 2119 2120 2121 2122 2123 2124 2125
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2126 2127 2128
```ts
let groupName = "GroupName";
notificationManager.cancelGroup(groupName).then(() => {
E
esterzhou 已提交
2129 2130 2131 2132
	console.info("cancelGroup success");
});
```

E
ester.zhou 已提交
2133
## notificationManager.removeGroupByBundle
E
esterzhou 已提交
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148

removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void

Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type                 | Mandatory| Description                        |
| --------- | --------------------- | ---- | ---------------------------- |
E
ester.zhou 已提交
2149
| bundle    | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | Yes  | Bundle information of the application.                  |
E
esterzhou 已提交
2150 2151 2152 2153 2154
| groupName | string                | Yes  | Name of the notification group.              |
| callback  | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2155 2156
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2157 2158 2159 2160 2161 2162 2163 2164 2165
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
2166
```ts
E
esterzhou 已提交
2167 2168
function removeGroupByBundleCallback(err) {
    if (err) {
E
ester.zhou 已提交
2169
        console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2170 2171 2172 2173 2174
    } else {
        console.info("removeGroupByBundle success");
    }
}

E
ester.zhou 已提交
2175 2176
let bundleOption = {bundle: "Bundle"};
let groupName = "GroupName";
E
esterzhou 已提交
2177

E
ester.zhou 已提交
2178
notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);
E
esterzhou 已提交
2179 2180
```

E
ester.zhou 已提交
2181
## notificationManager.removeGroupByBundle
E
esterzhou 已提交
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196

removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>

Removes notifications under a notification group of a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type        | Mandatory| Description          |
| --------- | ------------ | ---- | -------------- |
E
ester.zhou 已提交
2197
| bundle    | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle information of the application.    |
E
esterzhou 已提交
2198 2199 2200 2201
| groupName | string       | Yes  | Name of the notification group.|

**Error codes**

E
ester.zhou 已提交
2202 2203
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2204 2205 2206 2207 2208 2209 2210 2211 2212
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
2213 2214 2215 2216
```ts
let bundleOption = {bundle: "Bundle"};
let groupName = "GroupName";
notificationManager.removeGroupByBundle(bundleOption, groupName).then(() => {
E
esterzhou 已提交
2217 2218 2219 2220
	console.info("removeGroupByBundle success");
});
```

E
ester.zhou 已提交
2221
## notificationManager.setDoNotDisturbDate
E
esterzhou 已提交
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241

setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void

Sets the DND time. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                  |
| -------- | --------------------- | ---- | ---------------------- |
| date     | [DoNotDisturbDate](#donotdisturbdate)      | Yes  | DND time to set.        |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2242 2243
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2244 2245 2246 2247 2248
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
2249
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2250 2251 2252

**Example**

E
ester.zhou 已提交
2253
```ts
E
esterzhou 已提交
2254 2255
function setDoNotDisturbDateCallback(err) {
    if (err) {
E
ester.zhou 已提交
2256
        console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2257 2258 2259 2260 2261
    } else {
        console.info("setDoNotDisturbDate success");
    }
}

E
ester.zhou 已提交
2262 2263
let doNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
E
esterzhou 已提交
2264 2265
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
E
ester.zhou 已提交
2266
};
E
esterzhou 已提交
2267

E
ester.zhou 已提交
2268
notificationManager.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
E
esterzhou 已提交
2269 2270
```

E
ester.zhou 已提交
2271
## notificationManager.setDoNotDisturbDate
E
esterzhou 已提交
2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290

setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>

Sets the DND time. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type            | Mandatory| Description          |
| ---- | ---------------- | ---- | -------------- |
| date | [DoNotDisturbDate](#donotdisturbdate) | Yes  | DND time to set.|

**Error codes**

E
ester.zhou 已提交
2291 2292
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2293 2294 2295 2296 2297
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
2298
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2299 2300 2301

**Example**

E
ester.zhou 已提交
2302 2303 2304
```ts
let doNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
E
esterzhou 已提交
2305 2306
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
E
ester.zhou 已提交
2307 2308
};
notificationManager.setDoNotDisturbDate(doNotDisturbDate).then(() => {
E
esterzhou 已提交
2309 2310 2311 2312 2313
	console.info("setDoNotDisturbDate success");
});
```


E
ester.zhou 已提交
2314
## notificationManager.setDoNotDisturbDate
E
esterzhou 已提交
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335

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

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                  |
| -------- | --------------------- | ---- | ---------------------- |
| date     | [DoNotDisturbDate](#donotdisturbdate)      | Yes  | DND time to set.        |
| userId   | number                | Yes  | ID of the user for whom you want to set the DND time.|
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2336 2337
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2338 2339 2340 2341 2342 2343
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |
E
ester.zhou 已提交
2344
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2345 2346 2347

**Example**

E
ester.zhou 已提交
2348
```ts
E
esterzhou 已提交
2349 2350
function setDoNotDisturbDateCallback(err) {
    if (err) {
E
ester.zhou 已提交
2351
        console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2352 2353 2354 2355 2356
    } else {
        console.info("setDoNotDisturbDate success");
    }
}

E
ester.zhou 已提交
2357 2358
let doNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
E
esterzhou 已提交
2359 2360
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
E
ester.zhou 已提交
2361
};
E
esterzhou 已提交
2362

E
ester.zhou 已提交
2363
let userId = 1;
E
esterzhou 已提交
2364

E
ester.zhou 已提交
2365
notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);
E
esterzhou 已提交
2366 2367
```

E
ester.zhou 已提交
2368
## notificationManager.setDoNotDisturbDate
E
esterzhou 已提交
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388

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

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type            | Mandatory| Description          |
| ------ | ---------------- | ---- | -------------- |
| date   | [DoNotDisturbDate](#donotdisturbdate) | Yes  | DND time to set.|
| userId | number           | Yes  | ID of the user for whom you want to set the DND time.|

**Error codes**

E
ester.zhou 已提交
2389 2390
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2391 2392 2393 2394 2395 2396
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |
E
ester.zhou 已提交
2397
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2398 2399 2400

**Example**

E
ester.zhou 已提交
2401 2402 2403
```ts
let doNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
E
esterzhou 已提交
2404 2405
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
E
ester.zhou 已提交
2406
};
E
esterzhou 已提交
2407

E
ester.zhou 已提交
2408
let userId = 1;
E
esterzhou 已提交
2409

E
ester.zhou 已提交
2410
notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
E
esterzhou 已提交
2411 2412 2413 2414 2415
	console.info("setDoNotDisturbDate success");
});
```


E
ester.zhou 已提交
2416
## notificationManager.getDoNotDisturbDate
E
esterzhou 已提交
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435

getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void

Obtains the DND time. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                             | Mandatory| Description                  |
| -------- | --------------------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2436 2437
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2438 2439 2440 2441 2442
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
2443
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2444 2445 2446

**Example**

E
ester.zhou 已提交
2447
```ts
E
esterzhou 已提交
2448 2449
function getDoNotDisturbDateCallback(err,data) {
    if (err) {
E
ester.zhou 已提交
2450
        console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2451 2452 2453 2454 2455
    } else {
        console.info("getDoNotDisturbDate success");
    }
}

E
ester.zhou 已提交
2456
notificationManager.getDoNotDisturbDate(getDoNotDisturbDateCallback);
E
esterzhou 已提交
2457 2458
```

E
ester.zhou 已提交
2459
## notificationManager.getDoNotDisturbDate
E
esterzhou 已提交
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478

getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>

Obtains the DND time. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Return value**

| Type                                            | Description                                     |
| ------------------------------------------------ | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
2479 2480
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2481 2482 2483 2484 2485
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
E
ester.zhou 已提交
2486
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2487 2488 2489

**Example**

E
ester.zhou 已提交
2490 2491
```ts
notificationManager.getDoNotDisturbDate().then((data) => {
E
esterzhou 已提交
2492 2493 2494 2495 2496
	console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
2497
## notificationManager.getDoNotDisturbDate
E
esterzhou 已提交
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517

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

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                             | Mandatory| Description                  |
| -------- | --------------------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes  | Callback used to return the result.|
| userId   | number                            | Yes  | User ID.|

**Error codes**

E
ester.zhou 已提交
2518 2519
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2520 2521 2522 2523 2524 2525
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |
E
ester.zhou 已提交
2526
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2527 2528 2529

**Example**

E
ester.zhou 已提交
2530
```ts
E
esterzhou 已提交
2531 2532
function getDoNotDisturbDateCallback(err,data) {
    if (err) {
E
ester.zhou 已提交
2533
        console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2534 2535 2536 2537 2538
    } else {
        console.info("getDoNotDisturbDate success");
    }
}

E
ester.zhou 已提交
2539
let userId = 1;
E
esterzhou 已提交
2540

E
ester.zhou 已提交
2541
notificationManager.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback);
E
esterzhou 已提交
2542 2543
```

E
ester.zhou 已提交
2544
## notificationManager.getDoNotDisturbDate
E
esterzhou 已提交
2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569

getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>

Obtains the DND time of a specified user. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                             | Mandatory| Description                  |
| -------- | --------------------------------- | ---- | ---------------------- |
| userId   | number                            | Yes  | User ID.|

**Return value**

| Type                                            | Description                                     |
| ------------------------------------------------ | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
2570 2571
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2572 2573 2574 2575 2576 2577
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |
E
ester.zhou 已提交
2578
| 1600012  | No memory space.                          |
E
esterzhou 已提交
2579 2580 2581

**Example**

E
ester.zhou 已提交
2582 2583
```ts
let userId = 1;
E
esterzhou 已提交
2584

E
ester.zhou 已提交
2585
notificationManager.getDoNotDisturbDate(userId).then((data) => {
E
esterzhou 已提交
2586 2587 2588 2589 2590
	console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
2591
## notificationManager.isSupportDoNotDisturbMode
E
esterzhou 已提交
2592

E
ester.zhou 已提交
2593
 isSupportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void
E
esterzhou 已提交
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618

Checks whether DND mode is supported. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                    | Mandatory| Description                            |
| -------- | ------------------------ | ---- | -------------------------------- |
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|

**Error codes**

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2619
```ts
E
ester.zhou 已提交
2620
function isSupportDoNotDisturbModeCallback(err,data) {
E
esterzhou 已提交
2621
    if (err) {
E
ester.zhou 已提交
2622
        console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2623
    } else {
E
ester.zhou 已提交
2624
        console.info("isSupportDoNotDisturbMode success");
E
esterzhou 已提交
2625 2626 2627
    }
}

E
ester.zhou 已提交
2628
notificationManager.isSupportDoNotDisturbMode(isSupportDoNotDisturbModeCallback);
E
esterzhou 已提交
2629 2630
```

E
ester.zhou 已提交
2631
## notificationManager.isSupportDoNotDisturbMode
E
esterzhou 已提交
2632

E
ester.zhou 已提交
2633
isSupportDoNotDisturbMode(): Promise\<boolean\>
E
esterzhou 已提交
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650

Checks whether DND mode is supported. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
2651 2652
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2653 2654 2655 2656 2657 2658 2659 2660
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

E
ester.zhou 已提交
2661
```ts
E
ester.zhou 已提交
2662
notificationManager.isSupportDoNotDisturbMode().then((data) => {
E
esterzhou 已提交
2663 2664 2665 2666
	console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
2667
## notificationManager.isSupportTemplate
E
esterzhou 已提交
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683

isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void

Checks whether a specified template is supported. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name      | Type                    | Mandatory| Description                      |
| ------------ | ------------------------ | ---- | -------------------------- |
| templateName | string                   | Yes  | Template name.                  |
| callback     | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2684 2685
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2686 2687 2688 2689 2690 2691 2692 2693 2694
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
E
ester.zhou 已提交
2695
let templateName = 'process';
E
esterzhou 已提交
2696 2697
function isSupportTemplateCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
2698
        console.error(`isSupportTemplate failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2699 2700 2701 2702 2703
    } else {
        console.info("isSupportTemplate success");
    }
}

E
ester.zhou 已提交
2704
notificationManager.isSupportTemplate(templateName, isSupportTemplateCallback);
E
esterzhou 已提交
2705 2706
```

E
ester.zhou 已提交
2707
## notificationManager.isSupportTemplate
E
esterzhou 已提交
2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728

isSupportTemplate(templateName: string): Promise\<boolean\>

Checks whether a specified template is supported. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name      | Type  | Mandatory| Description    |
| ------------ | ------ | ---- | -------- |
| templateName | string | Yes  | Template name.|

**Return value**

| Type              | Description           |
| ------------------ | --------------- |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
2729 2730
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2731 2732 2733 2734 2735 2736 2737 2738 2739
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
E
ester.zhou 已提交
2740
let templateName = 'process';
E
esterzhou 已提交
2741

E
ester.zhou 已提交
2742
notificationManager.isSupportTemplate(templateName).then((data) => {
E
esterzhou 已提交
2743 2744 2745 2746
    console.info("isSupportTemplate success, data: " + JSON.stringify(data));
});
```

E
ester.zhou 已提交
2747
## notificationManager.requestEnableNotification
E
esterzhou 已提交
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762

requestEnableNotification(callback: AsyncCallback\<void\>): void

Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2763 2764
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
function requestEnableNotificationCallback(err) {
    if (err) {
E
ester.zhou 已提交
2776
        console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2777 2778 2779 2780 2781
    } else {
        console.info("requestEnableNotification success");
    }
};

E
ester.zhou 已提交
2782
notificationManager.requestEnableNotification(requestEnableNotificationCallback);
E
esterzhou 已提交
2783 2784
```

E
ester.zhou 已提交
2785
## notificationManager.requestEnableNotification
E
esterzhou 已提交
2786 2787 2788 2789 2790 2791 2792 2793 2794

requestEnableNotification(): Promise\<void\>

Requests notification to be enabled for this application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Error codes**

E
ester.zhou 已提交
2795 2796
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2797 2798 2799 2800 2801 2802 2803 2804 2805
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
E
ester.zhou 已提交
2806
notificationManager.requestEnableNotification().then(() => {
E
esterzhou 已提交
2807 2808 2809 2810 2811 2812
    console.info("requestEnableNotification success");
});
```



E
ester.zhou 已提交
2813
## notificationManager.setDistributedEnable
E
esterzhou 已提交
2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833

setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void

Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
| enable   | boolean                  | Yes  | Whether the device supports distributed notifications.|
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2834 2835
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600010  | Distributed operation failed.       |

**Example**

```javascript
E
ester.zhou 已提交
2846
function setDistributedEnableCallback(err) {
E
esterzhou 已提交
2847
    if (err) {
E
ester.zhou 已提交
2848
        console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2849 2850 2851 2852 2853
    } else {
        console.info("setDistributedEnable success");
    }
};

E
ester.zhou 已提交
2854
let enable = true;
E
esterzhou 已提交
2855

E
ester.zhou 已提交
2856
notificationManager.setDistributedEnable(enable, setDistributedEnableCallback);
E
esterzhou 已提交
2857 2858
```

E
ester.zhou 已提交
2859
## notificationManager.setDistributedEnable
E
esterzhou 已提交
2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878

setDistributedEnable(enable: boolean): Promise\<void>

Sets whether this device supports distributed notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
| enable   | boolean                  | Yes  | Whether the device supports distributed notifications.|

**Error codes**

E
ester.zhou 已提交
2879 2880
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2881 2882 2883 2884 2885 2886 2887 2888 2889 2890
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600010  | Distributed operation failed.       |

**Example**

```javascript
E
ester.zhou 已提交
2891
let enable = true;
E
esterzhou 已提交
2892

E
ester.zhou 已提交
2893
notificationManager.setDistributedEnable(enable).then(() => {
E
esterzhou 已提交
2894 2895 2896 2897 2898
        console.info("setDistributedEnable success");
    });
```


E
ester.zhou 已提交
2899
## notificationManager.isDistributedEnabled
E
esterzhou 已提交
2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914

isDistributedEnabled(callback: AsyncCallback\<boolean>): void

Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2915 2916
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600010  | Distributed operation failed.       |

**Example**

```javascript
function isDistributedEnabledCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
2929
        console.error(`isDistributedEnabled failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
2930 2931 2932 2933 2934
    } else {
        console.info("isDistributedEnabled success " + JSON.stringify(data));
    }
};

E
ester.zhou 已提交
2935
notificationManager.isDistributedEnabled(isDistributedEnabledCallback);
E
esterzhou 已提交
2936 2937 2938 2939
```



E
ester.zhou 已提交
2940
## notificationManager.isDistributedEnabled
E
esterzhou 已提交
2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955

isDistributedEnabled(): Promise\<boolean>

Checks whether this device supports distributed notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Return value**

| Type              | Description                                         |
| ------------------ | --------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
2956 2957
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600010  | Distributed operation failed.       |

**Example**

```javascript
E
ester.zhou 已提交
2968
notificationManager.isDistributedEnabled()
E
esterzhou 已提交
2969 2970 2971 2972 2973 2974
    .then((data) => {
        console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
    });
```


E
ester.zhou 已提交
2975
## notificationManager.setDistributedEnableByBundle
E
esterzhou 已提交
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990

setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void

Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
E
ester.zhou 已提交
2991
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | Yes  | Bundle information of the application.                  |
E
ester.zhou 已提交
2992
| enable   | boolean                  | Yes  | Whether the device supports distributed notifications.                      |
E
esterzhou 已提交
2993 2994 2995 2996
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
2997 2998
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600010  | Distributed operation failed.            |
| 17700001 | The specified bundle name was not found. |

**Example**

```javascript
function setDistributedEnableByBundleCallback(err) {
    if (err) {
E
ester.zhou 已提交
3012
        console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3013 3014 3015 3016 3017
    } else {
        console.info("enableDistributedByBundle success");
    }
};

E
ester.zhou 已提交
3018
let bundle = {
E
esterzhou 已提交
3019
    bundle: "bundleName1",
E
ester.zhou 已提交
3020
};
E
esterzhou 已提交
3021

E
ester.zhou 已提交
3022
let enable = true
E
esterzhou 已提交
3023

E
ester.zhou 已提交
3024
notificationManager.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback);
E
esterzhou 已提交
3025 3026 3027 3028
```



E
ester.zhou 已提交
3029
## notificationManager.setDistributedEnableByBundle
E
esterzhou 已提交
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044

setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<void>

Sets whether a specified application supports distributed notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
E
ester.zhou 已提交
3045
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | Yes  | Bundle information of the application.               |
E
ester.zhou 已提交
3046
| enable   | boolean                  | Yes  | Whether the device supports distributed notifications.                 |
E
esterzhou 已提交
3047 3048 3049

**Error codes**

E
ester.zhou 已提交
3050 3051
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600010  | Distributed operation failed.            |
| 17700001 | The specified bundle name was not found. |

**Example**

```javascript
E
ester.zhou 已提交
3063
let bundle = {
E
esterzhou 已提交
3064
    bundle: "bundleName1",
E
ester.zhou 已提交
3065
};
E
esterzhou 已提交
3066

E
ester.zhou 已提交
3067
let enable = true
E
esterzhou 已提交
3068

E
ester.zhou 已提交
3069 3070 3071
notificationManager.setDistributedEnableByBundle(bundle, enable).then(() => {
    console.info("setDistributedEnableByBundle success");
});
E
esterzhou 已提交
3072 3073
```

E
ester.zhou 已提交
3074
## notificationManager.isDistributedEnabledByBundle
E
esterzhou 已提交
3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089

isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void

Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
E
ester.zhou 已提交
3090
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | Yes  | Bundle information of the application.                    |
E
esterzhou 已提交
3091 3092 3093 3094
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3095 3096
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600010  | Distributed operation failed.            |
| 17700001 | The specified bundle name was not found. |

**Example**

```javascript
E
ester.zhou 已提交
3108
function isDistributedEnabledByBundleCallback(err, data) {
E
esterzhou 已提交
3109
    if (err) {
E
ester.zhou 已提交
3110
        console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3111 3112 3113 3114 3115
    } else {
        console.info("isDistributedEnabledByBundle success" + JSON.stringify(data));
    }
};

E
ester.zhou 已提交
3116
let bundle = {
E
esterzhou 已提交
3117
    bundle: "bundleName1",
E
ester.zhou 已提交
3118
};
E
esterzhou 已提交
3119

E
ester.zhou 已提交
3120
notificationManager.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback);
E
esterzhou 已提交
3121 3122
```

E
ester.zhou 已提交
3123
## notificationManager.isDistributedEnabledByBundle
E
esterzhou 已提交
3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138

isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>

Checks whether a specified application supports distributed notifications. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                    | Mandatory| Description                      |
| -------- | ------------------------ | ---- | -------------------------- |
E
ester.zhou 已提交
3139
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | Yes  | Bundle information of the application.               |
E
esterzhou 已提交
3140 3141 3142 3143 3144 3145 3146 3147 3148

**Return value**

| Type              | Description                                             |
| ------------------ | ------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
3149 3150
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600010  | Distributed operation failed.            |
| 17700001 | The specified bundle name was not found. |

**Example**

```javascript
E
ester.zhou 已提交
3162
let bundle = {
E
esterzhou 已提交
3163
    bundle: "bundleName1",
E
ester.zhou 已提交
3164
};
E
esterzhou 已提交
3165

E
ester.zhou 已提交
3166
notificationManager.isDistributedEnabledByBundle(bundle).then((data) => {
E
esterzhou 已提交
3167 3168 3169 3170 3171
    console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
3172
## notificationManager.getDeviceRemindType
E
esterzhou 已提交
3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191

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

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type                              | Mandatory| Description                      |
| -------- | --------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3192 3193
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
function getDeviceRemindTypeCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
3205
        console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3206 3207 3208 3209 3210
    } else {
        console.info("getDeviceRemindType success");
    }
};

E
ester.zhou 已提交
3211
notificationManager.getDeviceRemindType(getDeviceRemindTypeCallback);
E
esterzhou 已提交
3212 3213
```

E
ester.zhou 已提交
3214
## notificationManager.getDeviceRemindType
E
esterzhou 已提交
3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233

getDeviceRemindType(): Promise\<DeviceRemindType\>

Obtains the notification reminder type. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Return value**

| Type              | Description           |
| ------------------ | --------------- |
| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
3234 3235
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3236 3237 3238 3239 3240 3241 3242 3243 3244
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```javascript
E
ester.zhou 已提交
3245
notificationManager.getDeviceRemindType().then((data) => {
E
esterzhou 已提交
3246 3247 3248 3249 3250
    console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
3251
## notificationManager.publishAsBundle
E
esterzhou 已提交
3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266

publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void

Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name              | Type                                       | Mandatory| Description                                    |
| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
3267
| request              | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
3268 3269 3270 3271 3272 3273
| representativeBundle | string                                      | Yes  | Bundle name of the application whose notification function is taken over by the reminder agent.                      |
| userId               | number                                      | Yes  | User ID.                                |
| callback             | AsyncCallback                               | Yes  | Callback used to return the result.                |

**Error codes**

E
ester.zhou 已提交
3274 3275
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3276 3277 3278 3279 3280 3281 3282 3283 3284
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600008  | The user is not exist.                    |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
3285
| 1600012  | No memory space.                          |
E
esterzhou 已提交
3286 3287 3288

**Example**

E
ester.zhou 已提交
3289
```ts
E
esterzhou 已提交
3290 3291 3292
// publishAsBundle callback
function callback(err) {
    if (err) {
E
ester.zhou 已提交
3293
        console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3294 3295 3296 3297 3298
    } else {
        console.info("publishAsBundle success");
    }
}
// Bundle name of the application whose notification function is taken over by the reminder agent
E
ester.zhou 已提交
3299
let representativeBundle = "com.example.demo";
E
esterzhou 已提交
3300
// User ID
E
ester.zhou 已提交
3301
let userId = 100;
E
esterzhou 已提交
3302 3303 3304 3305
// NotificationRequest object
let request = {
    id: 1,
    content: {
E
ester.zhou 已提交
3306
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
3307 3308 3309 3310 3311 3312
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
3313
};
E
esterzhou 已提交
3314

E
ester.zhou 已提交
3315
notificationManager.publishAsBundle(request, representativeBundle, userId, callback);
E
esterzhou 已提交
3316 3317
```

E
ester.zhou 已提交
3318
## notificationManager.publishAsBundle
E
esterzhou 已提交
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334

publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\>

Publishes a notification through the reminder agent. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**


| Name              | Type                                       | Mandatory| Description                                         |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
E
ester.zhou 已提交
3335
| request              | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
E
esterzhou 已提交
3336 3337 3338 3339 3340
| representativeBundle | string                                      | Yes  | Bundle name of the application whose notification function is taken over by the reminder agent.                           |
| userId               | number                                      | Yes  | User ID.                           |

**Error codes**

E
ester.zhou 已提交
3341 3342
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3343 3344 3345 3346 3347 3348 3349 3350 3351
| ID| Error Message                                 |
| -------- | ----------------------------------------- |
| 1600001  | Internal error.                           |
| 1600002  | Marshalling or unmarshalling error.       |
| 1600003  | Failed to connect service.                |
| 1600004  | Notification is not enabled.              |
| 1600005  | Notification slot is not enabled.         |
| 1600008  | The user is not exist.                    |
| 1600009  | Over max number notifications per second. |
E
ester.zhou 已提交
3352
| 1600012  | No memory space.                          |
E
esterzhou 已提交
3353 3354 3355

**Example**

E
ester.zhou 已提交
3356
```ts
E
esterzhou 已提交
3357
// Bundle name of the application whose notification function is taken over by the reminder agent
E
ester.zhou 已提交
3358
let representativeBundle = "com.example.demo";
E
esterzhou 已提交
3359
// User ID
E
ester.zhou 已提交
3360
let userId = 100;
E
esterzhou 已提交
3361
// NotificationRequest object
E
ester.zhou 已提交
3362
let request = {
E
esterzhou 已提交
3363 3364
    id: 1,
    content: {
E
ester.zhou 已提交
3365
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
E
esterzhou 已提交
3366 3367 3368 3369 3370 3371
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
E
ester.zhou 已提交
3372
};
E
esterzhou 已提交
3373

E
ester.zhou 已提交
3374
notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => {
E
esterzhou 已提交
3375 3376 3377 3378
	console.info("publishAsBundle success");
});
```

E
ester.zhou 已提交
3379
## notificationManager.cancelAsBundle
E
esterzhou 已提交
3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403

cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void

Cancels a notification published by the reminder agent. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name              | Type         | Mandatory| Description                    |
| -------------------- | ------------- | ---- | ------------------------ |
| id                   | number        | Yes  | Notification ID.                |
| representativeBundle | string        | Yes  | Bundle name of the application whose notification function is taken over by the reminder agent.      |
| userId               | number        | Yes  | User ID.      |
| callback             | AsyncCallback | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3404 3405
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3406 3407 3408 3409 3410 3411 3412 3413 3414 3415
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3416
```ts
E
esterzhou 已提交
3417 3418 3419
// cancelAsBundle
function cancelAsBundleCallback(err) {
    if (err) {
E
ester.zhou 已提交
3420
        console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3421 3422 3423 3424 3425
    } else {
        console.info("cancelAsBundle success");
    }
}
// Bundle name of the application whose notification function is taken over by the reminder agent
E
ester.zhou 已提交
3426
let representativeBundle = "com.example.demo";
E
esterzhou 已提交
3427
// User ID
E
ester.zhou 已提交
3428
let userId = 100;
E
esterzhou 已提交
3429

E
ester.zhou 已提交
3430
notificationManager.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback);
E
esterzhou 已提交
3431 3432
```

E
ester.zhou 已提交
3433
## notificationManager.cancelAsBundle
E
esterzhou 已提交
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456

cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\>

Cancels a notification published by the reminder agent. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name              | Type  | Mandatory| Description              |
| -------------------- | ------ | ---- | ------------------ |
| id                   | number | Yes  | Notification ID.          |
| representativeBundle | string | Yes  | Bundle name of the application whose notification function is taken over by the reminder agent.|
| userId               | number | Yes  | User ID.|

**Error codes**

E
ester.zhou 已提交
3457 3458
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3459 3460 3461 3462 3463 3464 3465 3466 3467 3468
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3469
```ts
E
esterzhou 已提交
3470
// Bundle name of the application whose notification function is taken over by the reminder agent
E
ester.zhou 已提交
3471
let representativeBundle = "com.example.demo";
E
esterzhou 已提交
3472
// User ID
E
ester.zhou 已提交
3473
let userId = 100;
E
esterzhou 已提交
3474

E
ester.zhou 已提交
3475
notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => {
E
esterzhou 已提交
3476 3477 3478 3479
	console.info("cancelAsBundle success");
});
```

E
ester.zhou 已提交
3480
## notificationManager.setNotificationEnableSlot 
E
esterzhou 已提交
3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495

setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void

Sets whether to enable a specified notification slot type for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name  | Type                         | Mandatory| Description                  |
| -------- | ----------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
3496
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle information of the application.          |
E
esterzhou 已提交
3497
| type     | [SlotType](#slottype)         | Yes  | Notification slot type.        |
E
ester.zhou 已提交
3498
| enable   | boolean                       | Yes  | Whether to enable notification.            |
E
esterzhou 已提交
3499 3500 3501 3502
| callback | AsyncCallback\<void\>         | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3503 3504
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3505 3506 3507 3508 3509 3510 3511 3512 3513
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
3514
```ts
E
esterzhou 已提交
3515 3516 3517
// setNotificationEnableSlot
function setNotificationEnableSlotCallback(err) {
    if (err) {
E
ester.zhou 已提交
3518
        console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3519 3520 3521 3522 3523
    } else {
        console.info("setNotificationEnableSlot success");
    }
};

E
ester.zhou 已提交
3524
notificationManager.setNotificationEnableSlot(
E
esterzhou 已提交
3525
    { bundle: "ohos.samples.notification", },
E
ester.zhou 已提交
3526
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
E
esterzhou 已提交
3527 3528 3529 3530
    true,
    setNotificationEnableSlotCallback);
```

E
ester.zhou 已提交
3531
## notificationManager.setNotificationEnableSlot
E
esterzhou 已提交
3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546

setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void> 

Sets whether to enable a specified notification slot type for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
E
ester.zhou 已提交
3547
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle information of the application.  |
E
esterzhou 已提交
3548
| type   | [SlotType](#slottype)         | Yes  | Notification slot type.|
E
ester.zhou 已提交
3549
| enable | boolean                       | Yes  | Whether to enable notification.    |
E
esterzhou 已提交
3550 3551 3552

**Error codes**

E
ester.zhou 已提交
3553 3554
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3555 3556 3557 3558 3559 3560 3561 3562 3563
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
3564
```ts
E
esterzhou 已提交
3565
// setNotificationEnableSlot
E
ester.zhou 已提交
3566
notificationManager.setNotificationEnableSlot(
E
esterzhou 已提交
3567
    { bundle: "ohos.samples.notification", },
E
ester.zhou 已提交
3568
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
E
esterzhou 已提交
3569 3570 3571 3572 3573
    true).then(() => {
        console.info("setNotificationEnableSlot success");
    });
```

E
ester.zhou 已提交
3574
## notificationManager.isNotificationSlotEnabled
E
esterzhou 已提交
3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589

isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void

Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name  | Type                         | Mandatory| Description                  |
| -------- | ----------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
3590
| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle information of the application.          |
E
esterzhou 已提交
3591 3592 3593 3594 3595
| type     | [SlotType](#slottype)         | Yes  | Notification slot type.        |
| callback | AsyncCallback\<boolean\>         | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3596 3597
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3598 3599 3600 3601 3602 3603 3604 3605 3606
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
3607
```ts
E
esterzhou 已提交
3608 3609 3610
// isNotificationSlotEnabled
function getEnableSlotCallback(err, data) {
    if (err) {
E
ester.zhou 已提交
3611
        console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3612 3613 3614 3615 3616
    } else {
        console.info("isNotificationSlotEnabled success");
    }
};

E
ester.zhou 已提交
3617
notificationManager.isNotificationSlotEnabled(
E
esterzhou 已提交
3618
    { bundle: "ohos.samples.notification", },
E
ester.zhou 已提交
3619
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
E
esterzhou 已提交
3620 3621 3622
    getEnableSlotCallback);
```

E
ester.zhou 已提交
3623
## notificationManager.isNotificationSlotEnabled
E
esterzhou 已提交
3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638

isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\>  

Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
E
ester.zhou 已提交
3639
| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes  | Bundle information of the application.  |
E
esterzhou 已提交
3640 3641 3642 3643 3644 3645 3646 3647 3648 3649
| type   | [SlotType](#slottype)         | Yes  | Notification slot type.|

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
3650 3651
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3652 3653 3654 3655 3656 3657 3658 3659 3660
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

E
ester.zhou 已提交
3661
```ts
E
esterzhou 已提交
3662
// isNotificationSlotEnabled
E
ester.zhou 已提交
3663 3664
notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data) => {
E
esterzhou 已提交
3665 3666 3667 3668 3669
    console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
});
```


E
ester.zhou 已提交
3670
## notificationManager.setSyncNotificationEnabledWithoutApp
E
esterzhou 已提交
3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691

setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void

Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes  | User ID.  |
| enable | boolean | Yes  | Whether the feature is enabled.  |
| callback | AsyncCallback\<void\>    | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3692 3693
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3694 3695 3696 3697 3698 3699 3700 3701 3702
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3703
```ts
E
esterzhou 已提交
3704 3705 3706 3707 3708
let userId = 100;
let enable = true;

function callback(err) {
    if (err) {
E
ester.zhou 已提交
3709
        console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3710 3711 3712 3713 3714
    } else {
        console.info("setSyncNotificationEnabledWithoutApp success");
    }
}

E
ester.zhou 已提交
3715
notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable, callback);
E
esterzhou 已提交
3716 3717 3718
```


E
ester.zhou 已提交
3719
## notificationManager.setSyncNotificationEnabledWithoutApp
E
esterzhou 已提交
3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745

setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void>

Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes  | User ID.  |
| enable | boolean | Yes  | Whether the feature is enabled.  |

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<void\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
3746 3747
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3748 3749 3750 3751 3752 3753 3754 3755 3756
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3757
```ts
E
esterzhou 已提交
3758 3759 3760
let userId = 100;
let enable = true;

E
ester.zhou 已提交
3761
notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
E
esterzhou 已提交
3762 3763
    console.info('setSyncNotificationEnabledWithoutApp success');
}).catch((err) => {
E
ester.zhou 已提交
3764
    console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
E
esterzhou 已提交
3765 3766 3767 3768
});
```


E
ester.zhou 已提交
3769
## notificationManager.getSyncNotificationEnabledWithoutApp
E
esterzhou 已提交
3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789

getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void

Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes  | User ID.  |
| callback | AsyncCallback\<boolean\>         | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
3790 3791
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3792 3793 3794 3795 3796 3797 3798 3799 3800
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3801
```ts
E
esterzhou 已提交
3802 3803 3804 3805 3806 3807 3808 3809 3810 3811
let userId = 100;

function getSyncNotificationEnabledWithoutAppCallback(err, data) {
    if (err) {
        console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err);
    } else {
        console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data);
    }
}

E
ester.zhou 已提交
3812
notificationManager.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback);
E
esterzhou 已提交
3813 3814 3815
```


E
ester.zhou 已提交
3816
## notificationManager.getSyncNotificationEnabledWithoutApp
E
esterzhou 已提交
3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841

getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean>

Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes  | User ID.  |

**Return value**

| Type              | Description                                                        |
| ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Error codes**

E
ester.zhou 已提交
3842 3843
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

E
esterzhou 已提交
3844 3845 3846 3847 3848 3849 3850 3851 3852
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

E
ester.zhou 已提交
3853
```ts
E
esterzhou 已提交
3854
let userId = 100;
E
ester.zhou 已提交
3855
notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) => {
E
esterzhou 已提交
3856 3857 3858 3859 3860 3861
    console.info('getSyncNotificationEnabledWithoutApp, data:' + data);
}).catch((err) => {
    console.info('getSyncNotificationEnabledWithoutApp, err:' + err);
});
```

E
ester.zhou 已提交
3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942
## notificationManager.on<sup>10+</sup>

on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;

Subscribes to notification events. The notification service sends the notification information in the callback to the verification program. The verification program returns the verification result to determine whether to publish the notification, for example, controlling the publish frequency of marketing notifications.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| type | string | Yes  | Event type. The value is fixed to **'checkNotification'**.|
| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) =>  [NotificationCheckResult](#notificationcheckresult10)    | Yes  | Pointer to the notification verification function.|

**Error codes**

For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |

**Example**

```ts
try{
    notificationManager.on("checkNotification", OnCheckNotification);
} catch (error){
    console.info(`notificationManager.on error: ${JSON.stringify(error)}`);
}
function OnCheckNotification(info : notificationManager.NotificationCheckInfo) {
    console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`);
    if(info.notificationId == 1){
        return { code: 1, message: "testMsg1"}
    } else {
        return { code: 0, message: "testMsg0"}
    }
}
```

## notificationManager.off<sup>10+</sup>

off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;

Unsubscribes from notification events.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

**Parameters**

| Name| Type                         | Mandatory| Description          |
| ------ | ----------------------------- | ---- | -------------- |
| type | string                                                       | Yes  | Event type. The value is fixed to **'checkNotification'**.|
| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) =>  [NotificationCheckResult](#notificationcheckresult10)  | No  | Pointer to the notification verification function.|

**Error codes**

For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |

**Example**

```ts
try{
    notificationManager.off("checkNotification");
} catch (error){
    console.info(`notificationManager.off error: ${JSON.stringify(error)}`);
}
```
E
esterzhou 已提交
3943 3944 3945 3946 3947 3948 3949

## DoNotDisturbDate

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
3950
| Name | Type                                 | Read-only| Mandatory| Description                  |
E
esterzhou 已提交
3951
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
E
ester.zhou 已提交
3952 3953 3954
| type  | [DoNotDisturbType](#donotdisturbtype) | No  | Yes  | DND time type.|
| begin | Date                                  | No  | Yes  | DND start time.|
| end   | Date                                  | No  | Yes  | DND end time.|
E
esterzhou 已提交
3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034

## DoNotDisturbType

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

| Name        | Value              | Description                                      |
| ------------ | ---------------- | ------------------------------------------ |
| TYPE_NONE    | 0 | Non-DND.                          |
| TYPE_ONCE    | 1 | One-shot DND at the specified time segment (only considering the hour and minute).|
| TYPE_DAILY   | 2 | Daily DND at the specified time segment (only considering the hour and minute).|
| TYPE_CLEARLY | 3 | DND at the specified time segment (considering the year, month, day, hour, and minute).    |


## ContentType

**System capability**: SystemCapability.Notification.Notification

| Name                             | Value         | Description              |
| --------------------------------- | ----------- | ------------------ |
| NOTIFICATION_CONTENT_BASIC_TEXT   | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification.    |
| NOTIFICATION_CONTENT_LONG_TEXT    | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification.  |
| NOTIFICATION_CONTENT_PICTURE      | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification.    |
| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification.    |
| NOTIFICATION_CONTENT_MULTILINE    | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.|

## SlotLevel

**System capability**: SystemCapability.Notification.Notification

| Name                             | Value         | Description              |
| --------------------------------- | ----------- | ------------------ |
| LEVEL_NONE                        | 0           | Notification is disabled.    |
| LEVEL_MIN                         | 1           | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.|
| LEVEL_LOW                         | 2           | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.|
| LEVEL_DEFAULT                     | 3           | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.|
| LEVEL_HIGH                        | 4           | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.|


## SlotType

**System capability**: SystemCapability.Notification.Notification

| Name                | Value      | Description      |
| -------------------- | -------- | ---------- |
| UNKNOWN_TYPE         | 0 | Unknown type.|
| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication.|
| SERVICE_INFORMATION  | 2 | Notification slot for service information.|
| CONTENT_INFORMATION  | 3 | Notification slot for content consultation.|
| OTHER_TYPES          | 0xFFFF | Notification slot for other purposes.|




## DeviceRemindType

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

| 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.                |


## SourceType

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

| Name                | Value | Description                 |
| -------------------- | --- | -------------------- |
| TYPE_NORMAL          | 0   | Normal notification.           |
| TYPE_CONTINUOUS      | 1   | Continuous notification.           |
| TYPE_TIMER           | 2   | Timed notification.           |
E
ester.zhou 已提交
4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061

## NotificationCheckInfo<sup>10+</sup>

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

| Name | Type                                 | Read-only| Mandatory| Description                  |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| bundleName  | string                          | No  | Yes  | Bundle name.|
| notificationId | number                       | No  | Yes  | Notification ID.    |
| contentType   | [ContentType](#contenttype)   | No  | Yes  | Notification type.  |

## NotificationCheckResult<sup>10+</sup>

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

| Name | Type                                 | Read-only| Mandatory| Description                  |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| code  | number                          | No  | Yes  | Result code.<br>**0**: display.<br>**1**: no display.|
| message | string                       | No  | Yes  | Result.   |