1# @ohos.notificationManager (NotificationManager) 2 3The **notificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status. 4 5> **NOTE** 6> 7> 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. 8 9## Modules to Import 10 11```ts 12import notificationManager from '@ohos.notificationManager'; 13``` 14 15## notificationManager.publish 16 17publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void 18 19Publishes a notification. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.Notification.Notification 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| -------- | ------------------------------------------- | ---- | ------------------------------------------- | 27| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 28| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 29 30**Error codes** 31 32For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 33 34| ID| Error Message | 35| -------- | ----------------------------------------- | 36| 1600001 | Internal error. | 37| 1600002 | Marshalling or unmarshalling error. | 38| 1600003 | Failed to connect service. | 39| 1600004 | Notification is not enabled. | 40| 1600005 | Notification slot is not enabled. | 41| 1600009 | Over max number notifications per second. | 42| 1600012 | No memory space. | 43 44**Example** 45 46```ts 47import Base from '@ohos.base'; 48 49// publish callback 50let publishCallback = (err: Base.BusinessError): void => { 51 if (err) { 52 console.error(`publish failed, code is ${err.code}, message is ${err.message}`); 53 } else { 54 console.info("publish success"); 55 } 56} 57// NotificationRequest object 58let notificationRequest: notificationManager.NotificationRequest = { 59 id: 1, 60 content: { 61 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 62 normal: { 63 title: "test_title", 64 text: "test_text", 65 additionalText: "test_additionalText" 66 } 67 } 68}; 69notificationManager.publish(notificationRequest, publishCallback); 70``` 71 72## notificationManager.publish 73 74publish(request: NotificationRequest): Promise\<void\> 75 76Publishes a notification. This API uses a promise to return the result. 77 78**System capability**: SystemCapability.Notification.Notification 79 80**Parameters** 81 82| Name | Type | Mandatory| Description | 83| -------- | ------------------------------------------- | ---- | ------------------------------------------- | 84| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 85 86**Error codes** 87 88For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 89 90| ID| Error Message | 91| -------- | ----------------------------------------- | 92| 1600001 | Internal error. | 93| 1600002 | Marshalling or unmarshalling error. | 94| 1600003 | Failed to connect service. | 95| 1600004 | Notification is not enabled. | 96| 1600005 | Notification slot is not enabled. | 97| 1600009 | Over max number notifications per second. | 98| 1600012 | No memory space. | 99 100**Example** 101 102```ts 103import Base from '@ohos.base'; 104 105// NotificationRequest object 106let notificationRequest: notificationManager.NotificationRequest = { 107 id: 1, 108 content: { 109 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 110 normal: { 111 title: "test_title", 112 text: "test_text", 113 additionalText: "test_additionalText" 114 } 115 } 116}; 117notificationManager.publish(notificationRequest).then(() => { 118 console.info("publish success"); 119}).catch((err: Base.BusinessError) => { 120 console.error(`publish fail: ${JSON.stringify(err)}`); 121}); 122 123``` 124 125## notificationManager.publish 126 127publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void 128 129Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. 130 131**System capability**: SystemCapability.Notification.Notification 132 133**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 134 135**System API**: This is a system API and cannot be called by third-party applications. 136 137**Parameters** 138 139| Name | Type | Mandatory| Description | 140| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 141| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 142| userId | number | Yes | User ID. | 143| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 144 145**Error codes** 146 147For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 148 149| ID| Error Message | 150| -------- | ----------------------------------------- | 151| 1600001 | Internal error. | 152| 1600002 | Marshalling or unmarshalling error. | 153| 1600003 | Failed to connect service. | 154| 1600004 | Notification is not enabled. | 155| 1600005 | Notification slot is not enabled. | 156| 1600008 | The user is not exist. | 157| 1600009 | Over max number notifications per second. | 158| 1600012 | No memory space. | 159 160**Example** 161 162```ts 163import Base from '@ohos.base'; 164 165// publish callback 166let publishCallback = (err: Base.BusinessError): void => { 167 if (err) { 168 console.error(`publish failed, code is ${err.code}, message is ${err.message}`); 169 } else { 170 console.info("publish success"); 171 } 172} 173// User ID 174let userId: number = 1; 175// NotificationRequest object 176let notificationRequest: notificationManager.NotificationRequest = { 177 id: 1, 178 content: { 179 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 180 normal: { 181 title: "test_title", 182 text: "test_text", 183 additionalText: "test_additionalText" 184 } 185 } 186}; 187notificationManager.publish(notificationRequest, userId, publishCallback); 188``` 189 190## notificationManager.publish 191 192publish(request: NotificationRequest, userId: number): Promise\<void\> 193 194Publishes a notification to a specified user. This API uses a promise to return the result. 195 196**System capability**: SystemCapability.Notification.Notification 197 198**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 199 200**System API**: This is a system API and cannot be called by third-party applications. 201 202**Parameters** 203 204| Name | Type | Mandatory| Description | 205| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 206| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 207| userId | number | Yes | User ID. | 208 209**Error codes** 210 211For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 212 213| ID| Error Message | 214| -------- | ----------------------------------------- | 215| 1600001 | Internal error. | 216| 1600002 | Marshalling or unmarshalling error. | 217| 1600003 | Failed to connect service. | 218| 1600004 | Notification is not enabled. | 219| 1600005 | Notification slot is not enabled. | 220| 1600008 | The user is not exist. | 221| 1600009 | Over max number notifications per second. | 222| 1600012 | No memory space. | 223 224**Example** 225 226```ts 227import Base from '@ohos.base'; 228 229let notificationRequest: notificationManager.NotificationRequest = { 230 id: 1, 231 content: { 232 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 233 normal: { 234 title: "test_title", 235 text: "test_text", 236 additionalText: "test_additionalText" 237 } 238 } 239}; 240 241let userId: number = 1; 242 243notificationManager.publish(notificationRequest, userId).then(() => { 244 console.info("publish success"); 245}).catch((err: Base.BusinessError) => { 246 console.error(`publish fail: ${JSON.stringify(err)}`); 247}); 248``` 249 250 251## notificationManager.cancel 252 253cancel(id: number, label: string, callback: AsyncCallback\<void\>): void 254 255Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result. 256 257**System capability**: SystemCapability.Notification.Notification 258 259**Parameters** 260 261| Name | Type | Mandatory| Description | 262| -------- | --------------------- | ---- | -------------------- | 263| id | number | Yes | Notification ID. | 264| label | string | Yes | Notification label. | 265| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 266 267**Error codes** 268 269For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 270 271| ID| Error Message | 272| -------- | ----------------------------------- | 273| 1600001 | Internal error. | 274| 1600002 | Marshalling or unmarshalling error. | 275| 1600003 | Failed to connect service. | 276| 1600007 | The notification is not exist. | 277 278**Example** 279 280```ts 281import Base from '@ohos.base'; 282 283// cancel callback 284let cancelCallback = (err: Base.BusinessError): void => { 285 if (err) { 286 console.error(`cancel failed, code is ${err.code}, message is ${err.message}`); 287 } else { 288 console.info("cancel success"); 289 } 290} 291notificationManager.cancel(0, "label", cancelCallback); 292``` 293 294## notificationManager.cancel 295 296cancel(id: number, label?: string): Promise\<void\> 297 298Cancels a notification with the specified ID and optional label. This API uses a promise to return the result. 299 300**System capability**: SystemCapability.Notification.Notification 301 302**Parameters** 303 304| Name | Type | Mandatory| Description | 305| ----- | ------ | ---- | -------- | 306| id | number | Yes | Notification ID. | 307| label | string | No | Notification label. This parameter is left empty by default.| 308 309**Error codes** 310 311For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 312 313| ID| Error Message | 314| -------- | ----------------------------------- | 315| 1600001 | Internal error. | 316| 1600002 | Marshalling or unmarshalling error. | 317| 1600003 | Failed to connect service. | 318| 1600007 | The notification is not exist. | 319 320**Example** 321 322```ts 323import Base from '@ohos.base'; 324 325notificationManager.cancel(0).then(() => { 326 console.info("cancel success"); 327}).catch((err: Base.BusinessError) => { 328 console.error(`cancel fail: ${JSON.stringify(err)}`); 329}); 330``` 331 332## notificationManager.cancel 333 334cancel(id: number, callback: AsyncCallback\<void\>): void 335 336Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result. 337 338**System capability**: SystemCapability.Notification.Notification 339 340**Parameters** 341 342| Name | Type | Mandatory| Description | 343| -------- | --------------------- | ---- | -------------------- | 344| id | number | Yes | Notification ID. | 345| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 346 347**Error codes** 348 349For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 350 351| ID| Error Message | 352| -------- | ----------------------------------- | 353| 1600001 | Internal error. | 354| 1600002 | Marshalling or unmarshalling error. | 355| 1600003 | Failed to connect service. | 356| 1600007 | The notification is not exist. | 357 358**Example** 359 360```ts 361import Base from '@ohos.base'; 362 363// cancel callback 364let cancelCallback = (err: Base.BusinessError): void => { 365 if (err) { 366 console.error(`cancel failed, code is ${err.code}, message is ${err.message}`); 367 } else { 368 console.info("cancel success"); 369 } 370} 371notificationManager.cancel(0, cancelCallback); 372``` 373 374## notificationManager.cancelAll 375 376cancelAll(callback: AsyncCallback\<void\>): void 377 378Cancels all notifications. This API uses an asynchronous callback to return the result. 379 380**System capability**: SystemCapability.Notification.Notification 381 382**Error codes** 383 384For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 385 386| ID| Error Message | 387| -------- | ----------------------------------- | 388| 1600001 | Internal error. | 389| 1600002 | Marshalling or unmarshalling error. | 390| 1600003 | Failed to connect service. | 391 392**Parameters** 393 394| Name | Type | Mandatory| Description | 395| -------- | --------------------- | ---- | -------------------- | 396| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 397 398**Example** 399 400```ts 401import Base from '@ohos.base'; 402 403// cancel callback 404let cancelAllCallback = (err: Base.BusinessError): void => { 405 if (err) { 406 console.error(`cancelAll failed, code is ${err.code}, message is ${err.message}`); 407 } else { 408 console.info("cancelAll success"); 409 } 410} 411notificationManager.cancelAll(cancelAllCallback); 412``` 413 414## notificationManager.cancelAll 415 416cancelAll(): Promise\<void\> 417 418Cancels all notifications. This API uses a promise to return the result. 419 420**System capability**: SystemCapability.Notification.Notification 421 422**Error codes** 423 424For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 425 426| ID| Error Message | 427| -------- | ----------------------------------- | 428| 1600001 | Internal error. | 429| 1600002 | Marshalling or unmarshalling error. | 430| 1600003 | Failed to connect service. | 431 432**Example** 433 434```ts 435import Base from '@ohos.base'; 436 437notificationManager.cancelAll().then(() => { 438 console.info("cancelAll success"); 439}).catch((err: Base.BusinessError) => { 440 console.error(`cancelAll fail: ${JSON.stringify(err)}`); 441}); 442``` 443 444## notificationManager.addSlot 445 446addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void 447 448Adds a notification slot. This API uses an asynchronous callback to return the result. 449 450**System capability**: SystemCapability.Notification.Notification 451 452**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 453 454**System API**: This is a system API and cannot be called by third-party applications. 455 456**Parameters** 457 458| Name | Type | Mandatory| Description | 459| -------- | --------------------- | ---- | -------------------- | 460| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes | Notification slot to add.| 461| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 462 463**Error codes** 464 465For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 466 467| ID| Error Message | 468| -------- | ----------------------------------- | 469| 1600001 | Internal error. | 470| 1600002 | Marshalling or unmarshalling error. | 471| 1600003 | Failed to connect service. | 472| 1600012 | No memory space. | 473 474**Example** 475 476```ts 477import Base from '@ohos.base'; 478 479// addSlot callback 480let addSlotCallBack = (err: Base.BusinessError): void => { 481 if (err) { 482 console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); 483 } else { 484 console.info("addSlot success"); 485 } 486} 487// NotificationSlot object 488let notificationSlot: notificationManager.NotificationSlot = { 489 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 490}; 491notificationManager.addSlot(notificationSlot, addSlotCallBack); 492``` 493 494## notificationManager.addSlot 495 496addSlot(slot: NotificationSlot): Promise\<void\> 497 498Adds a notification slot. This API uses a promise to return the result. 499 500**System capability**: SystemCapability.Notification.Notification 501 502**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 503 504**System API**: This is a system API and cannot be called by third-party applications. 505 506**Parameters** 507 508| Name| Type | Mandatory| Description | 509| ---- | ---------------- | ---- | -------------------- | 510| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes | Notification slot to add.| 511 512**Error codes** 513 514For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 515 516| ID| Error Message | 517| -------- | ----------------------------------- | 518| 1600001 | Internal error. | 519| 1600002 | Marshalling or unmarshalling error. | 520| 1600003 | Failed to connect service. | 521| 1600012 | No memory space. | 522 523**Example** 524 525```ts 526import Base from '@ohos.base'; 527 528// NotificationSlot object 529let notificationSlot: notificationManager.NotificationSlot = { 530 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 531}; 532notificationManager.addSlot(notificationSlot).then(() => { 533 console.info("addSlot success"); 534}).catch((err: Base.BusinessError) => { 535 console.error(`addSlot fail: ${JSON.stringify(err)}`); 536}); 537``` 538 539## notificationManager.addSlot 540 541addSlot(type: SlotType, callback: AsyncCallback\<void\>): void 542 543Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result. 544 545**System capability**: SystemCapability.Notification.Notification 546 547**Parameters** 548 549| Name | Type | Mandatory| Description | 550| -------- | --------------------- | ---- | ---------------------- | 551| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| 552| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 553 554**Error codes** 555 556For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 557 558| ID| Error Message | 559| -------- | ----------------------------------- | 560| 1600001 | Internal error. | 561| 1600002 | Marshalling or unmarshalling error. | 562| 1600003 | Failed to connect service. | 563| 1600012 | No memory space. | 564 565**Example** 566 567```ts 568import Base from '@ohos.base'; 569 570// addSlot callback 571let addSlotCallBack = (err: Base.BusinessError): void => { 572 if (err) { 573 console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); 574 } else { 575 console.info("addSlot success"); 576 } 577} 578notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack); 579``` 580 581## notificationManager.addSlot 582 583addSlot(type: SlotType): Promise\<void\> 584 585Adds a notification slot of a specified type. This API uses a promise to return the result. 586 587**System capability**: SystemCapability.Notification.Notification 588 589**Parameters** 590 591| Name| Type | Mandatory| Description | 592| ---- | -------- | ---- | ---------------------- | 593| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| 594 595**Error codes** 596 597For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 598 599| ID| Error Message | 600| -------- | ----------------------------------- | 601| 1600001 | Internal error. | 602| 1600002 | Marshalling or unmarshalling error. | 603| 1600003 | Failed to connect service. | 604| 1600012 | No memory space. | 605 606**Example** 607 608```ts 609import Base from '@ohos.base'; 610 611notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION).then(() => { 612 console.info("addSlot success"); 613}).catch((err: Base.BusinessError) => { 614 console.error(`addSlot fail: ${JSON.stringify(err)}`); 615}); 616``` 617 618## notificationManager.addSlots 619 620addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void 621 622Adds an array of notification slots. This API uses an asynchronous callback to return the result. 623 624**System capability**: SystemCapability.Notification.Notification 625 626**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 627 628**System API**: This is a system API and cannot be called by third-party applications. 629 630**Parameters** 631 632| Name | Type | Mandatory| Description | 633| -------- | ------------------------- | ---- | ------------------------ | 634| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes | Notification slots to add.| 635| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 636 637**Error codes** 638 639For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 640 641| ID| Error Message | 642| -------- | ----------------------------------- | 643| 1600001 | Internal error. | 644| 1600002 | Marshalling or unmarshalling error. | 645| 1600003 | Failed to connect service. | 646| 1600012 | No memory space. | 647 648**Example** 649 650```ts 651import Base from '@ohos.base'; 652 653// addSlots callback 654let addSlotsCallBack = (err: Base.BusinessError): void => { 655 if (err) { 656 console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`); 657 } else { 658 console.info("addSlots success"); 659 } 660} 661// NotificationSlot object 662let notificationSlot: notificationManager.NotificationSlot = { 663 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 664}; 665// NotificationSlotArray object 666let notificationSlotArray: notificationManager.NotificationSlot[] = new Array(); 667notificationSlotArray[0] = notificationSlot; 668 669notificationManager.addSlots(notificationSlotArray, addSlotsCallBack); 670``` 671 672## notificationManager.addSlots 673 674addSlots(slots: Array\<NotificationSlot\>): Promise\<void\> 675 676Adds an array of notification slots. This API uses a promise to return the result. 677 678**System capability**: SystemCapability.Notification.Notification 679 680**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 681 682**System API**: This is a system API and cannot be called by third-party applications. 683 684**Parameters** 685 686| Name | Type | Mandatory| Description | 687| ----- | ------------------------- | ---- | ------------------------ | 688| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes | Notification slots to add.| 689 690**Error codes** 691 692For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 693 694| ID| Error Message | 695| -------- | ----------------------------------- | 696| 1600001 | Internal error. | 697| 1600002 | Marshalling or unmarshalling error. | 698| 1600003 | Failed to connect service. | 699| 1600012 | No memory space. | 700 701**Example** 702 703```ts 704import Base from '@ohos.base'; 705 706// NotificationSlot object 707let notificationSlot: notificationManager.NotificationSlot = { 708 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 709}; 710// NotificationSlotArray object 711let notificationSlotArray: notificationManager.NotificationSlot[] = new Array(); 712notificationSlotArray[0] = notificationSlot; 713 714notificationManager.addSlots(notificationSlotArray).then(() => { 715 console.info("addSlots success"); 716}).catch((err: Base.BusinessError) => { 717 console.error(`addSlot fail: ${JSON.stringify(err)}`); 718}); 719``` 720 721## notificationManager.getSlot 722 723getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void 724 725Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result. 726 727**System capability**: SystemCapability.Notification.Notification 728 729**Parameters** 730 731| Name | Type | Mandatory| Description | 732| -------- | --------------------------------- | ---- | ----------------------------------------------------------- | 733| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| 734| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes | Callback used to return the result. | 735 736**Error codes** 737 738For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 739 740| ID| Error Message | 741| -------- | ----------------------------------- | 742| 1600001 | Internal error. | 743| 1600002 | Marshalling or unmarshalling error. | 744| 1600003 | Failed to connect service. | 745 746**Example** 747 748```ts 749import Base from '@ohos.base'; 750 751// getSlot callback 752let getSlotCallback = (err: Base.BusinessError, data: notificationManager.NotificationSlot): void => { 753 if (err) { 754 console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`); 755 } else { 756 console.info(`getSlot success, data is ${JSON.stringify(data)}`); 757 } 758} 759let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 760notificationManager.getSlot(slotType, getSlotCallback); 761``` 762 763## notificationManager.getSlot 764 765getSlot(slotType: SlotType): Promise\<NotificationSlot\> 766 767Obtains a notification slot of a specified type. This API uses a promise to return the result. 768 769**System capability**: SystemCapability.Notification.Notification 770 771**Parameters** 772 773| Name | Type | Mandatory| Description | 774| -------- | -------- | ---- | ----------------------------------------------------------- | 775| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| 776 777**Return value** 778 779| Type | Description | 780| ----------------------------------------------------------- | ------------------------------------------------------------ | 781| Promise\<NotificationSlot\> | Promise used to return the result.| 782 783**Error codes** 784 785For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 786 787| ID| Error Message | 788| -------- | ----------------------------------- | 789| 1600001 | Internal error. | 790| 1600002 | Marshalling or unmarshalling error. | 791| 1600003 | Failed to connect service. | 792 793**Example** 794 795```ts 796import Base from '@ohos.base'; 797 798let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 799 800notificationManager.getSlot(slotType).then((data: notificationManager.NotificationSlot) => { 801 console.info("getSlot success, data: " + JSON.stringify(data)); 802}).catch((err: Base.BusinessError) => { 803 console.error(`getSlot fail: ${JSON.stringify(err)}`); 804}); 805``` 806 807## notificationManager.getSlots 808 809getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void 810 811Obtains all notification slots of this application. This API uses an asynchronous callback to return the result. 812 813**System capability**: SystemCapability.Notification.Notification 814 815**Parameters** 816 817For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 818 819| Name | Type | Mandatory| Description | 820| -------- | --------------------------------- | ---- | -------------------- | 821| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Yes | Callback used to return all notification slots of the current application.| 822 823**Error codes** 824 825| ID| Error Message | 826| -------- | ----------------------------------- | 827| 1600001 | Internal error. | 828| 1600002 | Marshalling or unmarshalling error. | 829| 1600003 | Failed to connect service. | 830 831**Example** 832 833```ts 834import Base from '@ohos.base'; 835 836// getSlots callback 837let getSlotsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>): void => { 838 if (err) { 839 console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`); 840 } else { 841 console.info(`getSlots success, data is ${JSON.stringify(data)}`); 842 } 843} 844notificationManager.getSlots(getSlotsCallback); 845``` 846 847## notificationManager.getSlots 848 849getSlots(): Promise\<Array\<NotificationSlot>> 850 851Obtains all notification slots of this application. This API uses a promise to return the result. 852 853**System capability**: SystemCapability.Notification.Notification 854 855**Return value** 856 857| Type | Description | 858| ----------------------------------------------------------- | ------------------------------------------------------------ | 859| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Promise used to return all notification slots of the current application.| 860 861**Error codes** 862 863For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 864 865| ID| Error Message | 866| -------- | ----------------------------------- | 867| 1600001 | Internal error. | 868| 1600002 | Marshalling or unmarshalling error. | 869| 1600003 | Failed to connect service. | 870 871**Example** 872 873```ts 874import Base from '@ohos.base'; 875 876notificationManager.getSlots().then((data: Array<notificationManager.NotificationSlot>) => { 877 console.info("getSlots success, data: " + JSON.stringify(data)); 878}).catch((err: Base.BusinessError) => { 879 console.error(`getSlots fail: ${JSON.stringify(err)}`); 880}); 881``` 882 883## notificationManager.removeSlot 884 885removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void 886 887Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. 888 889**System capability**: SystemCapability.Notification.Notification 890 891**Parameters** 892 893| Name | Type | Mandatory| Description | 894| -------- | --------------------- | ---- | ----------------------------------------------------------- | 895| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| 896| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 897 898**Error codes** 899 900For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 901 902| ID| Error Message | 903| -------- | ----------------------------------- | 904| 1600001 | Internal error. | 905| 1600002 | Marshalling or unmarshalling error. | 906| 1600003 | Failed to connect service. | 907 908**Example** 909 910```ts 911import Base from '@ohos.base'; 912 913// removeSlot callback 914let removeSlotCallback = (err: Base.BusinessError): void => { 915 if (err) { 916 console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`); 917 } else { 918 console.info("removeSlot success"); 919 } 920} 921let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 922notificationManager.removeSlot(slotType, removeSlotCallback); 923``` 924 925## notificationManager.removeSlot 926 927removeSlot(slotType: SlotType): Promise\<void\> 928 929Removes a notification slot of a specified type. This API uses a promise to return the result. 930 931**System capability**: SystemCapability.Notification.Notification 932 933**Parameters** 934 935| Name | Type | Mandatory| Description | 936| -------- | -------- | ---- | ----------------------------------------------------------- | 937| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| 938 939**Error codes** 940 941For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 942 943| ID| Error Message | 944| -------- | ----------------------------------- | 945| 1600001 | Internal error. | 946| 1600002 | Marshalling or unmarshalling error. | 947| 1600003 | Failed to connect service. | 948 949**Example** 950 951```ts 952import Base from '@ohos.base'; 953 954let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 955notificationManager.removeSlot(slotType).then(() => { 956 console.info("removeSlot success"); 957}).catch((err: Base.BusinessError) => { 958 console.error(`removeSlot fail: ${JSON.stringify(err)}`); 959}); 960``` 961 962## notificationManager.removeAllSlots 963 964removeAllSlots(callback: AsyncCallback\<void\>): void 965 966Removes all notification slots. This API uses an asynchronous callback to return the result. 967 968**System capability**: SystemCapability.Notification.Notification 969 970**Parameters** 971 972| Name | Type | Mandatory| Description | 973| -------- | --------------------- | ---- | -------------------- | 974| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 975 976**Error codes** 977 978For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 979 980| ID| Error Message | 981| -------- | ----------------------------------- | 982| 1600001 | Internal error. | 983| 1600002 | Marshalling or unmarshalling error. | 984| 1600003 | Failed to connect service. | 985 986**Example** 987 988```ts 989import Base from '@ohos.base'; 990 991let removeAllCallBack = (err: Base.BusinessError): void => { 992 if (err) { 993 console.error(`removeAllSlots failed, code is ${err.code}, message is ${err.message}`); 994 } else { 995 console.info("removeAllSlots success"); 996 } 997} 998notificationManager.removeAllSlots(removeAllCallBack); 999``` 1000 1001## notificationManager.removeAllSlots 1002 1003removeAllSlots(): Promise\<void\> 1004 1005Removes all notification slots. This API uses a promise to return the result. 1006 1007**System capability**: SystemCapability.Notification.Notification 1008 1009**Error codes** 1010 1011For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1012 1013| ID| Error Message | 1014| -------- | ----------------------------------- | 1015| 1600001 | Internal error. | 1016| 1600002 | Marshalling or unmarshalling error. | 1017| 1600003 | Failed to connect service. | 1018 1019**Example** 1020 1021```ts 1022import Base from '@ohos.base'; 1023 1024notificationManager.removeAllSlots().then(() => { 1025 console.info("removeAllSlots success"); 1026}).catch((err: Base.BusinessError) => { 1027 console.error(`removeAllSlots fail: ${JSON.stringify(err)}`); 1028}); 1029``` 1030 1031## notificationManager.setNotificationEnable 1032 1033setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 1034 1035Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. 1036 1037**System capability**: SystemCapability.Notification.Notification 1038 1039**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1040 1041**System API**: This is a system API and cannot be called by third-party applications. 1042 1043**Parameters** 1044 1045| Name | Type | Mandatory| Description | 1046| -------- | --------------------- | ---- | -------------------- | 1047| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1048| enable | boolean | Yes | Whether to enable notification. | 1049| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1050 1051**Error codes** 1052 1053For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1054 1055| ID| Error Message | 1056| -------- | ---------------------------------------- | 1057| 1600001 | Internal error. | 1058| 1600002 | Marshalling or unmarshalling error. | 1059| 1600003 | Failed to connect service. | 1060| 17700001 | The specified bundle name was not found. | 1061 1062**Example** 1063 1064```ts 1065import Base from '@ohos.base'; 1066 1067let setNotificationEnableCallback = (err: Base.BusinessError): void => { 1068 if (err) { 1069 console.error(`setNotificationEnableCallback failed, code is ${err.code}, message is ${err.message}`); 1070 } else { 1071 console.info("setNotificationEnableCallback success"); 1072 } 1073} 1074let bundle: notificationManager.BundleOption = { 1075 bundle: "bundleName1", 1076}; 1077notificationManager.setNotificationEnable(bundle, false, setNotificationEnableCallback); 1078``` 1079 1080## notificationManager.setNotificationEnable 1081 1082setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\> 1083 1084Sets whether to enable notification for a specified application. This API uses a promise to return the result. 1085 1086**System capability**: SystemCapability.Notification.Notification 1087 1088**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1089 1090**System API**: This is a system API and cannot be called by third-party applications. 1091 1092**Parameters** 1093 1094| Name | Type | Mandatory| Description | 1095| ------ | ------------ | ---- | ---------- | 1096| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1097| enable | boolean | Yes | Whether to enable notification. | 1098 1099**Error codes** 1100 1101For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1102 1103| ID| Error Message | 1104| -------- | ---------------------------------------- | 1105| 1600001 | Internal error. | 1106| 1600002 | Marshalling or unmarshalling error. | 1107| 1600003 | Failed to connect service. | 1108| 17700001 | The specified bundle name was not found. | 1109 1110**Example** 1111 1112```ts 1113import Base from '@ohos.base'; 1114 1115let bundle: notificationManager.BundleOption = { 1116 bundle: "bundleName1", 1117}; 1118notificationManager.setNotificationEnable(bundle, false).then(() => { 1119 console.info("setNotificationEnable success"); 1120}).catch((err: Base.BusinessError) => { 1121 console.error(`setNotificationEnable fail: ${JSON.stringify(err)}`); 1122}); 1123``` 1124 1125## notificationManager.isNotificationEnabled 1126 1127isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 1128 1129Checks whether notification is enabled for a specified application. This API uses an asynchronous callback to return the result. 1130 1131**System capability**: SystemCapability.Notification.Notification 1132 1133**System API**: This is a system API and cannot be called by third-party applications. 1134 1135**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1136 1137**Parameters** 1138 1139| Name | Type | Mandatory| Description | 1140| -------- | --------------------- | ---- | ------------------------ | 1141| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1142| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 1143 1144**Error codes** 1145 1146For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1147 1148| ID| Error Message | 1149| -------- | ---------------------------------------- | 1150| 1600001 | Internal error. | 1151| 1600002 | Marshalling or unmarshalling error. | 1152| 1600003 | Failed to connect service. | 1153| 17700001 | The specified bundle name was not found. | 1154 1155**Example** 1156 1157```ts 1158import Base from '@ohos.base'; 1159 1160let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean): void => { 1161 if (err) { 1162 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 1163 } else { 1164 console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 1165 } 1166} 1167 1168let bundle: notificationManager.BundleOption = { 1169 bundle: "bundleName1", 1170}; 1171 1172notificationManager.isNotificationEnabled(bundle, isNotificationEnabledCallback); 1173``` 1174 1175## notificationManager.isNotificationEnabled 1176 1177isNotificationEnabled(bundle: BundleOption): Promise\<boolean\> 1178 1179Checks whether notification is enabled for a specified application. This API uses a promise to return the result. 1180 1181**System capability**: SystemCapability.Notification.Notification 1182 1183**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1184 1185**System API**: This is a system API and cannot be called by third-party applications. 1186 1187**Parameters** 1188 1189| Name | Type | Mandatory| Description | 1190| ------ | ------------ | ---- | ---------- | 1191| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1192 1193**Return value** 1194 1195| Type | Description | 1196| ------------------ | --------------------------------------------------- | 1197| Promise\<boolean\> | Promise used to return the result.| 1198 1199**Error codes** 1200 1201For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1202 1203| ID| Error Message | 1204| -------- | ---------------------------------------- | 1205| 1600001 | Internal error. | 1206| 1600002 | Marshalling or unmarshalling error. | 1207| 1600003 | Failed to connect service. | 1208| 17700001 | The specified bundle name was not found. | 1209 1210**Example** 1211 1212```ts 1213import Base from '@ohos.base'; 1214 1215let bundle: notificationManager.BundleOption = { 1216 bundle: "bundleName1", 1217}; 1218notificationManager.isNotificationEnabled(bundle).then((data: boolean) => { 1219 console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 1220}).catch((err: Base.BusinessError) => { 1221 console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`); 1222}); 1223``` 1224 1225## notificationManager.isNotificationEnabled 1226 1227isNotificationEnabled(callback: AsyncCallback\<boolean\>): void 1228 1229Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result. 1230 1231**System capability**: SystemCapability.Notification.Notification 1232 1233**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1234 1235**System API**: This is a system API and cannot be called by third-party applications. 1236 1237**Parameters** 1238 1239| Name | Type | Mandatory| Description | 1240| -------- | --------------------- | ---- | ------------------------ | 1241| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 1242 1243**Error codes** 1244 1245For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1246 1247| ID| Error Message | 1248| -------- | ----------------------------------- | 1249| 1600001 | Internal error. | 1250| 1600002 | Marshalling or unmarshalling error. | 1251| 1600003 | Failed to connect service. | 1252 1253**Example** 1254 1255```ts 1256import Base from '@ohos.base'; 1257 1258let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean): void => { 1259 if (err) { 1260 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 1261 } else { 1262 console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 1263 } 1264} 1265 1266notificationManager.isNotificationEnabled(isNotificationEnabledCallback); 1267``` 1268 1269## notificationManager.isNotificationEnabled 1270 1271isNotificationEnabled(): Promise\<boolean\> 1272 1273Checks whether notification is enabled for the current application. This API uses a promise to return the result. 1274 1275**System capability**: SystemCapability.Notification.Notification 1276 1277**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1278 1279**System API**: This is a system API and cannot be called by third-party applications. 1280 1281**Return value** 1282 1283| Type | Description | 1284| ----------------------------------------------------------- | ------------------------------------------------------------ | 1285| Promise\<boolean\> | Promise used to return the result.| 1286 1287**Error codes** 1288 1289For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1290 1291| ID| Error Message | 1292| -------- | ---------------------------------------- | 1293| 1600001 | Internal error. | 1294| 1600002 | Marshalling or unmarshalling error. | 1295| 1600003 | Failed to connect service. | 1296 1297**Example** 1298 1299```ts 1300import Base from '@ohos.base'; 1301 1302notificationManager.isNotificationEnabled().then((data: boolean) => { 1303 console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 1304}).catch((err: Base.BusinessError) => { 1305 console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`); 1306}); 1307``` 1308 1309## notificationManager.isNotificationEnabled 1310 1311isNotificationEnabled(userId: number, callback: AsyncCallback\<boolean\>): void 1312 1313Checks whether notification is enabled for a specified user. This API uses an asynchronous callback to return the result. 1314 1315**System capability**: SystemCapability.Notification.Notification 1316 1317**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1318 1319**System API**: This is a system API and cannot be called by third-party applications. 1320 1321**Parameters** 1322 1323| Name | Type | Mandatory| Description | 1324| -------- | --------------------- | ---- | ------------------------ | 1325| userId | number | Yes | User ID.| 1326| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 1327 1328**Error codes** 1329 1330For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1331 1332| ID| Error Message | 1333| -------- | ----------------------------------- | 1334| 1600001 | Internal error. | 1335| 1600002 | Marshalling or unmarshalling error. | 1336| 1600003 | Failed to connect service. | 1337| 1600008 | The user is not exist. | 1338 1339**Example** 1340 1341```ts 1342import Base from '@ohos.base'; 1343 1344let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean): void => { 1345 if (err) { 1346 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 1347 } else { 1348 console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 1349 } 1350} 1351 1352let userId: number = 1; 1353 1354notificationManager.isNotificationEnabled(userId, isNotificationEnabledCallback); 1355``` 1356 1357## notificationManager.isNotificationEnabled 1358 1359isNotificationEnabled(userId: number): Promise\<boolean\> 1360 1361Checks whether notification is enabled for a specified user. This API uses a promise to return the result. 1362 1363**System capability**: SystemCapability.Notification.Notification 1364 1365**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1366 1367**System API**: This is a system API and cannot be called by third-party applications. 1368 1369**Parameters** 1370 1371| Name | Type | Mandatory| Description | 1372| ------ | ------------ | ---- | ---------- | 1373| userId | number | Yes | User ID.| 1374 1375**Return value** 1376 1377| Type | Description | 1378| ----------------------------------------------------------- | ------------------------------------------------------------ | 1379| Promise\<boolean\> | Promise used to return the result.| 1380 1381**Error codes** 1382 1383For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1384 1385| ID| Error Message | 1386| -------- | ---------------------------------------- | 1387| 1600001 | Internal error. | 1388| 1600002 | Marshalling or unmarshalling error. | 1389| 1600003 | Failed to connect service. | 1390| 1600008 | The user is not exist.. | 1391 1392**Example** 1393 1394```ts 1395import Base from '@ohos.base'; 1396 1397let userId: number = 1; 1398 1399notificationManager.isNotificationEnabled(userId).then((data: boolean) => { 1400 console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 1401}).catch((err: Base.BusinessError) => { 1402 console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`); 1403}); 1404``` 1405 1406## notificationManager.displayBadge 1407 1408displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 1409 1410Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. 1411 1412**System capability**: SystemCapability.Notification.Notification 1413 1414**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1415 1416**System API**: This is a system API and cannot be called by third-party applications. 1417 1418**Parameters** 1419 1420| Name | Type | Mandatory| Description | 1421| -------- | --------------------- | ---- | -------------------- | 1422| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1423| enable | boolean | Yes | Whether to enable notification. | 1424| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1425 1426**Error codes** 1427 1428For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1429 1430| ID| Error Message | 1431| -------- | ---------------------------------------- | 1432| 1600001 | Internal error. | 1433| 1600002 | Marshalling or unmarshalling error. | 1434| 1600003 | Failed to connect service. | 1435| 17700001 | The specified bundle name was not found. | 1436 1437**Example** 1438 1439```ts 1440import Base from '@ohos.base'; 1441 1442let displayBadgeCallback = (err: Base.BusinessError): void => { 1443 if (err) { 1444 console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`); 1445 } else { 1446 console.info("displayBadge success"); 1447 } 1448} 1449let bundle: notificationManager.BundleOption = { 1450 bundle: "bundleName1", 1451}; 1452notificationManager.displayBadge(bundle, false, displayBadgeCallback); 1453``` 1454 1455## notificationManager.displayBadge 1456 1457displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\> 1458 1459Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. 1460 1461**System capability**: SystemCapability.Notification.Notification 1462 1463**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1464 1465**System API**: This is a system API and cannot be called by third-party applications. 1466 1467**Parameters** 1468 1469| Name | Type | Mandatory| Description | 1470| ------ | ------------ | ---- | ---------- | 1471| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1472| enable | boolean | Yes | Whether to enable notification. | 1473 1474**Error codes** 1475 1476For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1477 1478| ID| Error Message | 1479| -------- | ---------------------------------------- | 1480| 1600001 | Internal error. | 1481| 1600002 | Marshalling or unmarshalling error. | 1482| 1600003 | Failed to connect service. | 1483| 17700001 | The specified bundle name was not found. | 1484 1485**Example** 1486 1487```ts 1488import Base from '@ohos.base'; 1489 1490let bundle: notificationManager.BundleOption = { 1491 bundle: "bundleName1", 1492}; 1493notificationManager.displayBadge(bundle, false).then(() => { 1494 console.info("displayBadge success"); 1495}).catch((err: Base.BusinessError) => { 1496 console.error(`displayBadge fail: ${JSON.stringify(err)}`); 1497}); 1498``` 1499 1500## notificationManager.isBadgeDisplayed 1501 1502isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 1503 1504Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. 1505 1506**System capability**: SystemCapability.Notification.Notification 1507 1508**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1509 1510**System API**: This is a system API and cannot be called by third-party applications. 1511 1512**Parameters** 1513 1514| Name | Type | Mandatory| Description | 1515| -------- | --------------------- | ---- | ------------------------ | 1516| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1517| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 1518 1519**Error codes** 1520 1521For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1522 1523| ID| Error Message | 1524| -------- | ---------------------------------------- | 1525| 1600001 | Internal error. | 1526| 1600002 | Marshalling or unmarshalling error. | 1527| 1600003 | Failed to connect service. | 1528| 17700001 | The specified bundle name was not found. | 1529 1530**Example** 1531 1532```ts 1533import Base from '@ohos.base'; 1534 1535let isBadgeDisplayedCallback = (err: Base.BusinessError, data: boolean): void => { 1536 if (err) { 1537 console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`); 1538 } else { 1539 console.info(`isBadgeDisplayed success, data is ${JSON.stringify(data)}`); 1540 } 1541} 1542let bundle: notificationManager.BundleOption = { 1543 bundle: "bundleName1", 1544}; 1545notificationManager.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); 1546``` 1547 1548## notificationManager.isBadgeDisplayed 1549 1550isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\> 1551 1552Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. 1553 1554**System capability**: SystemCapability.Notification.Notification 1555 1556**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1557 1558**System API**: This is a system API and cannot be called by third-party applications. 1559 1560**Parameters** 1561 1562| Name | Type | Mandatory| Description | 1563| ------ | ------------ | ---- | ---------- | 1564| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1565 1566**Return value** 1567 1568| Type | Description | 1569| ----------------------------------------------------------- | ------------------------------------------------------------ | 1570| Promise\<boolean\> | Promise used to return the result.| 1571 1572**Error codes** 1573 1574For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1575 1576| ID| Error Message | 1577| -------- | ---------------------------------------- | 1578| 1600001 | Internal error. | 1579| 1600002 | Marshalling or unmarshalling error. | 1580| 1600003 | Failed to connect service. | 1581| 17700001 | The specified bundle name was not found. | 1582 1583**Example** 1584 1585```ts 1586import Base from '@ohos.base'; 1587 1588let bundle: notificationManager.BundleOption = { 1589 bundle: "bundleName1", 1590}; 1591 1592notificationManager.isBadgeDisplayed(bundle).then((data: boolean) => { 1593 console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); 1594}).catch((err: Base.BusinessError) => { 1595 console.error(`isBadgeDisplayed fail: ${JSON.stringify(err)}`); 1596}); 1597``` 1598 1599## notificationManager.setBadgeNumber<sup>10+</sup> 1600 1601setBadgeNumber(badgeNumber: number): Promise\<void\> 1602 1603Sets the notification badge number. This API uses a promise to return the result. 1604 1605**System capability**: SystemCapability.Notification.Notification 1606 1607**Parameters** 1608 1609| Name | Type | Mandatory| Description | 1610| ----------- | ------ | ---- | ---------- | 1611| badgeNumber | number | Yes | Notification badge number to set.| 1612 1613**Error codes** 1614 1615| ID| Error Message | 1616| -------- | ----------------------------------- | 1617| 1600001 | Internal error. | 1618| 1600002 | Marshalling or unmarshalling error. | 1619| 1600003 | Failed to connect service. | 1620| 1600012 | No memory space. | 1621 1622**Example** 1623 1624```ts 1625import Base from '@ohos.base'; 1626 1627let badgeNumber: number = 10; 1628 1629notificationManager.setBadgeNumber(badgeNumber).then(() => { 1630 console.info("displayBadge success"); 1631}).catch((err: Base.BusinessError) => { 1632 console.error(`displayBadge fail: ${JSON.stringify(err)}`); 1633}); 1634``` 1635 1636## notificationManager.setBadgeNumber<sup>10+</sup> 1637 1638setBadgeNumber(badgeNumber: number, callback: AsyncCallback\<void\>): void 1639 1640Sets the notification badge number. This API uses an asynchronous callback to return the result. 1641 1642**System capability**: SystemCapability.Notification.Notification 1643 1644**Parameters** 1645 1646| Name | Type | Mandatory| Description | 1647| ----------- | --------------------- | ---- | ------------------ | 1648| badgeNumber | number | Yes | Notification badge number to set. | 1649| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1650 1651**Error codes** 1652 1653For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1654 1655| ID| Error Message | 1656| -------- | ----------------------------------- | 1657| 1600001 | Internal error. | 1658| 1600002 | Marshalling or unmarshalling error. | 1659| 1600003 | Failed to connect service. | 1660| 1600012 | No memory space. | 1661 1662**Example** 1663 1664```ts 1665import Base from '@ohos.base'; 1666 1667let setBadgeNumberCallback = (err: Base.BusinessError): void => { 1668 if (err) { 1669 console.info(`displayBadge failed code is ${err.code}, message is ${err.message}`); 1670 } else { 1671 console.info("displayBadge success"); 1672 } 1673} 1674 1675let badgeNumber: number = 10; 1676notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback); 1677``` 1678 1679## notificationManager.setSlotByBundle 1680 1681setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void 1682 1683Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. 1684 1685**System capability**: SystemCapability.Notification.Notification 1686 1687**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1688 1689**System API**: This is a system API and cannot be called by third-party applications. 1690 1691**Parameters** 1692 1693| Name | Type | Mandatory| Description | 1694| -------- | --------------------- | ---- | -------------------- | 1695| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1696| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes | Notification slot. | 1697| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1698 1699**Error codes** 1700 1701For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1702 1703| ID| Error Message | 1704| -------- | ---------------------------------------- | 1705| 1600001 | Internal error. | 1706| 1600002 | Marshalling or unmarshalling error. | 1707| 1600003 | Failed to connect service. | 1708| 17700001 | The specified bundle name was not found. | 1709 1710**Example** 1711 1712```ts 1713import Base from '@ohos.base'; 1714 1715let setSlotByBundleCallback = (err: Base.BusinessError): void => { 1716 if (err) { 1717 console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 1718 } else { 1719 console.info("setSlotByBundle success"); 1720 } 1721} 1722let bundle: notificationManager.BundleOption = { 1723 bundle: "bundleName1", 1724}; 1725let notificationSlot: notificationManager.NotificationSlot = { 1726 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 1727}; 1728notificationManager.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); 1729``` 1730 1731## notificationManager.setSlotByBundle 1732 1733setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\> 1734 1735Sets the notification slot for a specified application. This API uses a promise to return the result. 1736 1737**System capability**: SystemCapability.Notification.Notification 1738 1739**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1740 1741**System API**: This is a system API and cannot be called by third-party applications. 1742 1743**Parameters** 1744 1745| Name | Type | Mandatory| Description | 1746| ------ | ------------ | ---- | ---------- | 1747| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1748| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | Yes | Notification slot.| 1749 1750**Error codes** 1751 1752For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1753 1754| ID| Error Message | 1755| -------- | ---------------------------------------- | 1756| 1600001 | Internal error. | 1757| 1600002 | Marshalling or unmarshalling error. | 1758| 1600003 | Failed to connect service. | 1759| 17700001 | The specified bundle name was not found. | 1760 1761**Example** 1762 1763```ts 1764import Base from '@ohos.base'; 1765 1766let bundle: notificationManager.BundleOption = { 1767 bundle: "bundleName1", 1768}; 1769 1770let notificationSlot: notificationManager.NotificationSlot = { 1771 type: notificationManager.SlotType.SOCIAL_COMMUNICATION 1772}; 1773 1774notificationManager.setSlotByBundle(bundle, notificationSlot).then(() => { 1775 console.info("setSlotByBundle success"); 1776}).catch((err: Base.BusinessError) => { 1777 console.error(`setSlotByBundle fail: ${JSON.stringify(err)}`); 1778}); 1779``` 1780 1781## notificationManager.getSlotsByBundle 1782 1783getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<NotificationSlot>>): void 1784 1785Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. 1786 1787**System capability**: SystemCapability.Notification.Notification 1788 1789**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1790 1791**System API**: This is a system API and cannot be called by third-party applications. 1792 1793**Parameters** 1794 1795| Name | Type | Mandatory| Description | 1796| -------- | ---------------------------------------- | ---- | -------------------- | 1797| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1798| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)>> | Yes | Callback used to return the result.| 1799 1800**Error codes** 1801 1802For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1803 1804| ID| Error Message | 1805| -------- | ---------------------------------------- | 1806| 1600001 | Internal error. | 1807| 1600002 | Marshalling or unmarshalling error. | 1808| 1600003 | Failed to connect service. | 1809| 17700001 | The specified bundle name was not found. | 1810 1811**Example** 1812 1813```ts 1814import Base from '@ohos.base'; 1815 1816let getSlotsByBundleCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>): void => { 1817 if (err) { 1818 console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 1819 } else { 1820 console.info(`getSlotsByBundle success, data is ${JSON.stringify(data)}`); 1821 } 1822} 1823let bundle: notificationManager.BundleOption = { 1824 bundle: "bundleName1", 1825}; 1826notificationManager.getSlotsByBundle(bundle, getSlotsByBundleCallback); 1827``` 1828 1829## notificationManager.getSlotsByBundle 1830 1831getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>> 1832 1833Obtains the notification slots of a specified application. This API uses a promise to return the result. 1834 1835**System capability**: SystemCapability.Notification.Notification 1836 1837**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1838 1839**System API**: This is a system API and cannot be called by third-party applications. 1840 1841**Parameters** 1842 1843| Name | Type | Mandatory| Description | 1844| ------ | ------------ | ---- | ---------- | 1845| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1846 1847**Return value** 1848 1849| Type | Description | 1850| ----------------------------------------------------------- | ------------------------------------------------------------ | 1851| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)>> | Promise used to return the result.| 1852 1853**Error codes** 1854 1855For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1856 1857| ID| Error Message | 1858| -------- | ---------------------------------------- | 1859| 1600001 | Internal error. | 1860| 1600002 | Marshalling or unmarshalling error. | 1861| 1600003 | Failed to connect service. | 1862| 17700001 | The specified bundle name was not found. | 1863 1864**Example** 1865 1866```ts 1867import Base from '@ohos.base'; 1868 1869let bundle: notificationManager.BundleOption = { 1870 bundle: "bundleName1", 1871}; 1872 1873notificationManager.getSlotsByBundle(bundle).then((data: Array<notificationManager.NotificationSlot>) => { 1874 console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); 1875}).catch((err: Base.BusinessError) => { 1876 console.error(`getSlotsByBundle fail: ${JSON.stringify(err)}`); 1877}); 1878``` 1879 1880## notificationManager.getSlotNumByBundle 1881 1882getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void 1883 1884Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. 1885 1886**System capability**: SystemCapability.Notification.Notification 1887 1888**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1889 1890**System API**: This is a system API and cannot be called by third-party applications. 1891 1892**Parameters** 1893 1894| Name | Type | Mandatory| Description | 1895| -------- | ------------------------- | ---- | ---------------------- | 1896| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 1897| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.| 1898 1899**Error codes** 1900 1901For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1902 1903| ID| Error Message | 1904| -------- | ---------------------------------------- | 1905| 1600001 | Internal error. | 1906| 1600002 | Marshalling or unmarshalling error. | 1907| 1600003 | Failed to connect service. | 1908| 17700001 | The specified bundle name was not found. | 1909 1910**Example** 1911 1912```ts 1913import Base from '@ohos.base'; 1914 1915let getSlotNumByBundleCallback = (err: Base.BusinessError, data: number): void => { 1916 if (err) { 1917 console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 1918 } else { 1919 console.info(`getSlotNumByBundle success data is ${JSON.stringify(data)}`); 1920 } 1921} 1922 1923let bundle: notificationManager.BundleOption = { 1924 bundle: "bundleName1", 1925}; 1926 1927notificationManager.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); 1928``` 1929 1930## notificationManager.getSlotNumByBundle 1931 1932getSlotNumByBundle(bundle: BundleOption): Promise\<number\> 1933 1934Obtains the number of notification slots of a specified application. This API uses a promise to return the result. 1935 1936**System capability**: SystemCapability.Notification.Notification 1937 1938**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1939 1940**System API**: This is a system API and cannot be called by third-party applications. 1941 1942**Parameters** 1943 1944| Name | Type | Mandatory| Description | 1945| ------ | ------------ | ---- | ---------- | 1946| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application.| 1947 1948**Return value** 1949 1950| Type | Description | 1951| ----------------------------------------------------------- | ------------------------------------------------------------ | 1952| Promise\<number\> | Promise used to return the result.| 1953 1954**Error codes** 1955 1956For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 1957 1958| ID| Error Message | 1959| -------- | ---------------------------------------- | 1960| 1600001 | Internal error. | 1961| 1600002 | Marshalling or unmarshalling error. | 1962| 1600003 | Failed to connect service. | 1963| 17700001 | The specified bundle name was not found. | 1964 1965**Example** 1966 1967```ts 1968import Base from '@ohos.base'; 1969 1970let bundle: notificationManager.BundleOption = { 1971 bundle: "bundleName1", 1972}; 1973 1974notificationManager.getSlotNumByBundle(bundle).then((data: number) => { 1975 console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); 1976}).catch((err: Base.BusinessError) => { 1977 console.error(`getSlotsByBundle fail: ${JSON.stringify(err)}`); 1978}); 1979``` 1980 1981 1982## notificationManager.getAllActiveNotifications 1983 1984getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void 1985 1986Obtains all active notifications. This API uses an asynchronous callback to return the result. 1987 1988**System capability**: SystemCapability.Notification.Notification 1989 1990**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1991 1992**System API**: This is a system API and cannot be called by third-party applications. 1993 1994**Parameters** 1995 1996| Name | Type | Mandatory| Description | 1997| -------- | ------------------------------------------------------------ | ---- | -------------------- | 1998| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | Yes | Callback used to return the result.| 1999 2000**Error codes** 2001 2002| ID| Error Message | 2003| -------- | ----------------------------------- | 2004| 1600001 | Internal error. | 2005| 1600002 | Marshalling or unmarshalling error. | 2006| 1600003 | Failed to connect service. | 2007 2008**Example** 2009 2010```ts 2011import Base from '@ohos.base'; 2012 2013let getAllActiveNotificationsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>): void => { 2014 if (err) { 2015 console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`); 2016 } else { 2017 console.info(`getAllActiveNotifications success, data is ${JSON.stringify(data)}`); 2018 } 2019} 2020 2021notificationManager.getAllActiveNotifications(getAllActiveNotificationsCallback); 2022``` 2023 2024## notificationManager.getAllActiveNotifications 2025 2026getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> 2027 2028Obtains all active notifications. This API uses a promise to return the result. 2029 2030**System capability**: SystemCapability.Notification.Notification 2031 2032**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2033 2034**System API**: This is a system API and cannot be called by third-party applications. 2035 2036**Return value** 2037 2038| Type | Description | 2039| ----------------------------------------------------------- | ------------------------------------------------------------ | 2040| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | Promise used to return the result.| 2041 2042**Error codes** 2043 2044For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2045 2046| ID| Error Message | 2047| -------- | ----------------------------------- | 2048| 1600001 | Internal error. | 2049| 1600002 | Marshalling or unmarshalling error. | 2050| 1600003 | Failed to connect service. | 2051 2052**Example** 2053 2054```ts 2055import Base from '@ohos.base'; 2056 2057notificationManager.getAllActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => { 2058 console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); 2059}).catch((err: Base.BusinessError) => { 2060 console.error(`getAllActiveNotifications fail: ${JSON.stringify(err)}`); 2061}); 2062``` 2063 2064## notificationManager.getActiveNotificationCount 2065 2066getActiveNotificationCount(callback: AsyncCallback\<number\>): void 2067 2068Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result. 2069 2070**System capability**: SystemCapability.Notification.Notification 2071 2072**Parameters** 2073 2074| Name | Type | Mandatory| Description | 2075| -------- | ---------------------- | ---- | ---------------------- | 2076| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.| 2077 2078**Error codes** 2079 2080For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2081 2082| ID| Error Message | 2083| -------- | ----------------------------------- | 2084| 1600001 | Internal error. | 2085| 1600002 | Marshalling or unmarshalling error. | 2086| 1600003 | Failed to connect service. | 2087 2088**Example** 2089 2090```ts 2091import Base from '@ohos.base'; 2092 2093let getActiveNotificationCountCallback = (err: Base.BusinessError, data: number): void => { 2094 if (err) { 2095 console.error(`getActiveNotificationCount failed, code is ${err.code}, message is ${err.message}`); 2096 } else { 2097 console.info(`getActiveNotificationCount success, data is ${JSON.stringify(data)}`); 2098 } 2099} 2100 2101notificationManager.getActiveNotificationCount(getActiveNotificationCountCallback); 2102``` 2103 2104## notificationManager.getActiveNotificationCount 2105 2106getActiveNotificationCount(): Promise\<number\> 2107 2108Obtains the number of active notifications of this application. This API uses a promise to return the result. 2109 2110**System capability**: SystemCapability.Notification.Notification 2111 2112**Return value** 2113 2114| Type | Description | 2115| ----------------- | ------------------------------------------- | 2116| Promise\<number\> | Promise used to return the result.| 2117 2118**Error codes** 2119 2120For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2121 2122| ID| Error Message | 2123| -------- | ----------------------------------- | 2124| 1600001 | Internal error. | 2125| 1600002 | Marshalling or unmarshalling error. | 2126| 1600003 | Failed to connect service. | 2127 2128**Example** 2129 2130```ts 2131import Base from '@ohos.base'; 2132 2133notificationManager.getActiveNotificationCount().then((data: number) => { 2134 console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); 2135}).catch((err: Base.BusinessError) => { 2136 console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`); 2137}); 2138``` 2139 2140## notificationManager.getActiveNotifications 2141 2142getActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void 2143 2144Obtains active notifications of this application. This API uses an asynchronous callback to return the result. 2145 2146**System capability**: SystemCapability.Notification.Notification 2147 2148**Parameters** 2149 2150| Name | Type | Mandatory| Description | 2151| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 2152| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | Yes | Callback used to return the result.| 2153 2154**Error codes** 2155 2156For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2157 2158| ID| Error Message | 2159| -------- | ----------------------------------- | 2160| 1600001 | Internal error. | 2161| 1600002 | Marshalling or unmarshalling error. | 2162| 1600003 | Failed to connect service. | 2163 2164**Example** 2165 2166```ts 2167import Base from '@ohos.base'; 2168 2169let getActiveNotificationsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>): void => { 2170 if (err) { 2171 console.error(`getActiveNotifications failed, code is ${err.code}, message is ${err.message}`); 2172 } else { 2173 console.info("getActiveNotifications success"); 2174 } 2175} 2176 2177notificationManager.getActiveNotifications(getActiveNotificationsCallback); 2178``` 2179 2180## notificationManager.getActiveNotifications 2181 2182getActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> 2183 2184Obtains active notifications of this application. This API uses a promise to return the result. 2185 2186**System capability**: SystemCapability.Notification.Notification 2187 2188**Return value** 2189 2190| Type | Description | 2191| ------------------------------------------------------------ | --------------------------------------- | 2192| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | Promise used to return the result.| 2193 2194**Error codes** 2195 2196For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2197 2198| ID| Error Message | 2199| -------- | ----------------------------------- | 2200| 1600001 | Internal error. | 2201| 1600002 | Marshalling or unmarshalling error. | 2202| 1600003 | Failed to connect service. | 2203 2204**Example** 2205 2206```ts 2207import Base from '@ohos.base'; 2208 2209notificationManager.getActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => { 2210 console.info("removeGroupByBundle success, data: " + JSON.stringify(data)); 2211}).catch((err: Base.BusinessError) => { 2212 console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`); 2213}); 2214``` 2215 2216## notificationManager.cancelGroup 2217 2218cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void 2219 2220Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result. 2221 2222**System capability**: SystemCapability.Notification.Notification 2223 2224**Parameters** 2225 2226| Name | Type | Mandatory| Description | 2227| --------- | --------------------- | ---- | ---------------------------- | 2228| 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.| 2229| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2230 2231**Error codes** 2232 2233For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2234 2235| ID| Error Message | 2236| -------- | ----------------------------------- | 2237| 1600001 | Internal error. | 2238| 1600002 | Marshalling or unmarshalling error. | 2239| 1600003 | Failed to connect service. | 2240 2241**Example** 2242 2243```ts 2244import Base from '@ohos.base'; 2245 2246let cancelGroupCallback = (err: Base.BusinessError): void => { 2247 if (err) { 2248 console.error(`cancelGroup failed, code is ${err.code}, message is ${err.message}`); 2249 } else { 2250 console.info("cancelGroup success"); 2251 } 2252} 2253 2254let groupName: string = "GroupName"; 2255 2256notificationManager.cancelGroup(groupName, cancelGroupCallback); 2257``` 2258 2259## notificationManager.cancelGroup 2260 2261cancelGroup(groupName: string): Promise\<void\> 2262 2263Cancels notifications under a notification group of this application. This API uses a promise to return the result. 2264 2265**System capability**: SystemCapability.Notification.Notification 2266 2267**Parameters** 2268 2269| Name | Type | Mandatory| Description | 2270| --------- | ------ | ---- | -------------- | 2271| groupName | string | Yes | Name of the notification group.| 2272 2273**Error codes** 2274 2275For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2276 2277| ID| Error Message | 2278| -------- | ----------------------------------- | 2279| 1600001 | Internal error. | 2280| 1600002 | Marshalling or unmarshalling error. | 2281| 1600003 | Failed to connect service. | 2282 2283**Example** 2284 2285```ts 2286import Base from '@ohos.base'; 2287 2288let groupName: string = "GroupName"; 2289notificationManager.cancelGroup(groupName).then(() => { 2290 console.info("cancelGroup success"); 2291}).catch((err: Base.BusinessError) => { 2292 console.error(`cancelGroup fail: ${JSON.stringify(err)}`); 2293}); 2294``` 2295 2296## notificationManager.removeGroupByBundle 2297 2298removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void 2299 2300Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result. 2301 2302**System capability**: SystemCapability.Notification.Notification 2303 2304**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2305 2306**System API**: This is a system API and cannot be called by third-party applications. 2307 2308**Parameters** 2309 2310| Name | Type | Mandatory| Description | 2311| --------- | --------------------- | ---- | ---------------------------- | 2312| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 2313| groupName | string | Yes | Name of the notification group. | 2314| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2315 2316**Error codes** 2317 2318For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2319 2320| ID| Error Message | 2321| -------- | ---------------------------------------- | 2322| 1600001 | Internal error. | 2323| 1600002 | Marshalling or unmarshalling error. | 2324| 1600003 | Failed to connect service. | 2325| 17700001 | The specified bundle name was not found. | 2326 2327**Example** 2328 2329```ts 2330import Base from '@ohos.base'; 2331 2332let removeGroupByBundleCallback = (err: Base.BusinessError): void => { 2333 if (err) { 2334 console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); 2335 } else { 2336 console.info("removeGroupByBundle success"); 2337 } 2338} 2339 2340let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" }; 2341let groupName: string = "GroupName"; 2342 2343notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); 2344``` 2345 2346## notificationManager.removeGroupByBundle 2347 2348removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\> 2349 2350Removes notifications under a notification group of a specified application. This API uses a promise to return the result. 2351 2352**System capability**: SystemCapability.Notification.Notification 2353 2354**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2355 2356**System API**: This is a system API and cannot be called by third-party applications. 2357 2358**Parameters** 2359 2360| Name | Type | Mandatory| Description | 2361| --------- | ------------ | ---- | -------------- | 2362| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 2363| groupName | string | Yes | Name of the notification group.| 2364 2365**Error codes** 2366 2367For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2368 2369| ID| Error Message | 2370| -------- | ---------------------------------------- | 2371| 1600001 | Internal error. | 2372| 1600002 | Marshalling or unmarshalling error. | 2373| 1600003 | Failed to connect service. | 2374| 17700001 | The specified bundle name was not found. | 2375 2376**Example** 2377 2378```ts 2379import Base from '@ohos.base'; 2380 2381let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" }; 2382let groupName: string = "GroupName"; 2383 2384notificationManager.removeGroupByBundle(bundleOption, groupName).then(() => { 2385 console.info("removeGroupByBundle success"); 2386}).catch((err: Base.BusinessError) => { 2387 console.error(`removeGroupByBundle fail: ${JSON.stringify(err)}`); 2388}); 2389``` 2390 2391## notificationManager.setDoNotDisturbDate 2392 2393setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void 2394 2395Sets the DND time. This API uses an asynchronous callback to return the result. 2396 2397**System capability**: SystemCapability.Notification.Notification 2398 2399**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2400 2401**System API**: This is a system API and cannot be called by third-party applications. 2402 2403**Parameters** 2404 2405| Name | Type | Mandatory| Description | 2406| -------- | --------------------- | ---- | ---------------------- | 2407| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | 2408| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2409 2410**Error codes** 2411 2412For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2413 2414| ID| Error Message | 2415| -------- | ----------------------------------- | 2416| 1600001 | Internal error. | 2417| 1600002 | Marshalling or unmarshalling error. | 2418| 1600003 | Failed to connect service. | 2419| 1600012 | No memory space. | 2420 2421**Example** 2422 2423```ts 2424import Base from '@ohos.base'; 2425 2426let setDoNotDisturbDateCallback = (err: Base.BusinessError): void => { 2427 if (err) { 2428 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2429 } else { 2430 console.info("setDoNotDisturbDate success"); 2431 } 2432} 2433 2434let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 2435 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 2436 begin: new Date(), 2437 end: new Date(2021, 11, 15, 18, 0) 2438}; 2439 2440notificationManager.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); 2441``` 2442 2443## notificationManager.setDoNotDisturbDate 2444 2445setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\> 2446 2447Sets the DND time. This API uses a promise to return the result. 2448 2449**System capability**: SystemCapability.Notification.Notification 2450 2451**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2452 2453**System API**: This is a system API and cannot be called by third-party applications. 2454 2455**Parameters** 2456 2457| Name| Type | Mandatory| Description | 2458| ---- | ---------------- | ---- | -------------- | 2459| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| 2460 2461**Error codes** 2462 2463For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2464 2465| ID| Error Message | 2466| -------- | ----------------------------------- | 2467| 1600001 | Internal error. | 2468| 1600002 | Marshalling or unmarshalling error. | 2469| 1600003 | Failed to connect service. | 2470| 1600012 | No memory space. | 2471 2472**Example** 2473 2474```ts 2475import Base from '@ohos.base'; 2476 2477let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 2478 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 2479 begin: new Date(), 2480 end: new Date(2021, 11, 15, 18, 0) 2481}; 2482notificationManager.setDoNotDisturbDate(doNotDisturbDate).then(() => { 2483 console.info("setDoNotDisturbDate success"); 2484}).catch((err: Base.BusinessError) => { 2485 console.error(`setDoNotDisturbDate fail: ${JSON.stringify(err)}`); 2486}); 2487``` 2488 2489 2490## notificationManager.setDoNotDisturbDate 2491 2492setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): void 2493 2494Sets the DND time for a specified user. This API uses an asynchronous callback to return the result. 2495 2496**System capability**: SystemCapability.Notification.Notification 2497 2498**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2499 2500**System API**: This is a system API and cannot be called by third-party applications. 2501 2502**Parameters** 2503 2504| Name | Type | Mandatory| Description | 2505| -------- | --------------------- | ---- | ---------------------- | 2506| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | 2507| userId | number | Yes | ID of the user for whom you want to set the DND time.| 2508| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2509 2510**Error codes** 2511 2512For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2513 2514| ID| Error Message | 2515| -------- | ----------------------------------- | 2516| 1600001 | Internal error. | 2517| 1600002 | Marshalling or unmarshalling error. | 2518| 1600003 | Failed to connect service. | 2519| 1600008 | The user is not exist. | 2520| 1600012 | No memory space. | 2521 2522**Example** 2523 2524```ts 2525import Base from '@ohos.base'; 2526 2527let setDoNotDisturbDateCallback = (err: Base.BusinessError): void => { 2528 if (err) { 2529 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2530 } else { 2531 console.info("setDoNotDisturbDate success"); 2532 } 2533} 2534 2535let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 2536 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 2537 begin: new Date(), 2538 end: new Date(2021, 11, 15, 18, 0) 2539}; 2540 2541let userId: number = 1; 2542 2543notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); 2544``` 2545 2546## notificationManager.setDoNotDisturbDate 2547 2548setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\> 2549 2550Sets the DND time for a specified user. This API uses a promise to return the result. 2551 2552**System capability**: SystemCapability.Notification.Notification 2553 2554**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2555 2556**System API**: This is a system API and cannot be called by third-party applications. 2557 2558**Parameters** 2559 2560| Name | Type | Mandatory| Description | 2561| ------ | ---------------- | ---- | -------------- | 2562| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| 2563| userId | number | Yes | ID of the user for whom you want to set the DND time.| 2564 2565**Error codes** 2566 2567For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2568 2569| ID| Error Message | 2570| -------- | ----------------------------------- | 2571| 1600001 | Internal error. | 2572| 1600002 | Marshalling or unmarshalling error. | 2573| 1600003 | Failed to connect service. | 2574| 1600008 | The user is not exist. | 2575| 1600012 | No memory space. | 2576 2577**Example** 2578 2579```ts 2580import Base from '@ohos.base'; 2581 2582let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 2583 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 2584 begin: new Date(), 2585 end: new Date(2021, 11, 15, 18, 0) 2586}; 2587 2588let userId: number = 1; 2589 2590notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { 2591 console.info("setDoNotDisturbDate success"); 2592}).catch((err: Base.BusinessError) => { 2593 console.error(`setDoNotDisturbDate fail: ${JSON.stringify(err)}`); 2594}); 2595``` 2596 2597 2598## notificationManager.getDoNotDisturbDate 2599 2600getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void 2601 2602Obtains the DND time. This API uses an asynchronous callback to return the result. 2603 2604**System capability**: SystemCapability.Notification.Notification 2605 2606**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2607 2608**System API**: This is a system API and cannot be called by third-party applications. 2609 2610**Parameters** 2611 2612| Name | Type | Mandatory| Description | 2613| -------- | --------------------------------- | ---- | ---------------------- | 2614| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| 2615 2616**Error codes** 2617 2618For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2619 2620| ID| Error Message | 2621| -------- | ----------------------------------- | 2622| 1600001 | Internal error. | 2623| 1600002 | Marshalling or unmarshalling error. | 2624| 1600003 | Failed to connect service. | 2625| 1600012 | No memory space. | 2626 2627**Example** 2628 2629```ts 2630import Base from '@ohos.base'; 2631 2632let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: notificationManager.DoNotDisturbDate): void => { 2633 if (err) { 2634 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2635 } else { 2636 console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`); 2637 } 2638} 2639 2640notificationManager.getDoNotDisturbDate(getDoNotDisturbDateCallback); 2641``` 2642 2643## notificationManager.getDoNotDisturbDate 2644 2645getDoNotDisturbDate(): Promise\<DoNotDisturbDate\> 2646 2647Obtains the DND time. This API uses a promise to return the result. 2648 2649**System capability**: SystemCapability.Notification.Notification 2650 2651**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2652 2653**System API**: This is a system API and cannot be called by third-party applications. 2654 2655**Return value** 2656 2657| Type | Description | 2658| ------------------------------------------------ | ----------------------------------------- | 2659| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| 2660 2661**Error codes** 2662 2663For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2664 2665| ID| Error Message | 2666| -------- | ----------------------------------- | 2667| 1600001 | Internal error. | 2668| 1600002 | Marshalling or unmarshalling error. | 2669| 1600003 | Failed to connect service. | 2670| 1600012 | No memory space. | 2671 2672**Example** 2673 2674```ts 2675import Base from '@ohos.base'; 2676 2677notificationManager.getDoNotDisturbDate().then((data: notificationManager.DoNotDisturbDate) => { 2678 console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); 2679}).catch((err: Base.BusinessError) => { 2680 console.error(`getDoNotDisturbDate fail: ${JSON.stringify(err)}`); 2681}); 2682``` 2683 2684 2685## notificationManager.getDoNotDisturbDate 2686 2687getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): void 2688 2689Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result. 2690 2691**System capability**: SystemCapability.Notification.Notification 2692 2693**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2694 2695**System API**: This is a system API and cannot be called by third-party applications. 2696 2697**Parameters** 2698 2699| Name | Type | Mandatory| Description | 2700| -------- | --------------------------------- | ---- | ---------------------- | 2701| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| 2702| userId | number | Yes | User ID.| 2703 2704**Error codes** 2705 2706For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2707 2708| ID| Error Message | 2709| -------- | ----------------------------------- | 2710| 1600001 | Internal error. | 2711| 1600002 | Marshalling or unmarshalling error. | 2712| 1600003 | Failed to connect service. | 2713| 1600008 | The user is not exist. | 2714| 1600012 | No memory space. | 2715 2716**Example** 2717 2718```ts 2719import Base from '@ohos.base'; 2720 2721let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: notificationManager.DoNotDisturbDate): void => { 2722 if (err) { 2723 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2724 } else { 2725 console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`); 2726 } 2727} 2728 2729let userId: number = 1; 2730 2731notificationManager.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); 2732``` 2733 2734## notificationManager.getDoNotDisturbDate 2735 2736getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\> 2737 2738Obtains the DND time of a specified user. This API uses a promise to return the result. 2739 2740**System capability**: SystemCapability.Notification.Notification 2741 2742**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2743 2744**System API**: This is a system API and cannot be called by third-party applications. 2745 2746**Parameters** 2747 2748| Name | Type | Mandatory| Description | 2749| -------- | --------------------------------- | ---- | ---------------------- | 2750| userId | number | Yes | User ID.| 2751 2752**Return value** 2753 2754| Type | Description | 2755| ------------------------------------------------ | ----------------------------------------- | 2756| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| 2757 2758**Error codes** 2759 2760For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2761 2762| ID| Error Message | 2763| -------- | ----------------------------------- | 2764| 1600001 | Internal error. | 2765| 1600002 | Marshalling or unmarshalling error. | 2766| 1600003 | Failed to connect service. | 2767| 1600008 | The user is not exist. | 2768| 1600012 | No memory space. | 2769 2770**Example** 2771 2772```ts 2773import Base from '@ohos.base'; 2774 2775let userId: number = 1; 2776 2777notificationManager.getDoNotDisturbDate(userId).then((data: notificationManager.DoNotDisturbDate) => { 2778 console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); 2779}).catch((err: Base.BusinessError) => { 2780 console.error(`getDoNotDisturbDate fail: ${JSON.stringify(err)}`); 2781}); 2782``` 2783 2784 2785## notificationManager.isSupportDoNotDisturbMode 2786 2787 isSupportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void 2788 2789Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. 2790 2791**System capability**: SystemCapability.Notification.Notification 2792 2793**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2794 2795**System API**: This is a system API and cannot be called by third-party applications. 2796 2797**Parameters** 2798 2799| Name | Type | Mandatory| Description | 2800| -------- | ------------------------ | ---- | -------------------------------- | 2801| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 2802 2803**Error codes** 2804 2805| ID| Error Message | 2806| -------- | ----------------------------------- | 2807| 1600001 | Internal error. | 2808| 1600002 | Marshalling or unmarshalling error. | 2809| 1600003 | Failed to connect service. | 2810 2811**Example** 2812 2813```ts 2814import Base from '@ohos.base'; 2815 2816let isSupportDoNotDisturbModeCallback = (err: Base.BusinessError, data: boolean): void => { 2817 if (err) { 2818 console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`); 2819 } else { 2820 console.info("isSupportDoNotDisturbMode success"); 2821 } 2822} 2823 2824notificationManager.isSupportDoNotDisturbMode(isSupportDoNotDisturbModeCallback); 2825``` 2826 2827## notificationManager.isSupportDoNotDisturbMode 2828 2829isSupportDoNotDisturbMode(): Promise\<boolean\> 2830 2831Checks whether DND mode is supported. This API uses a promise to return the result. 2832 2833**System capability**: SystemCapability.Notification.Notification 2834 2835**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2836 2837**System API**: This is a system API and cannot be called by third-party applications. 2838 2839**Return value** 2840 2841| Type | Description | 2842| ----------------------------------------------------------- | ------------------------------------------------------------ | 2843| Promise\<boolean\> | Promise used to return the result.| 2844 2845**Error codes** 2846 2847For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2848 2849| ID| Error Message | 2850| -------- | ----------------------------------- | 2851| 1600001 | Internal error. | 2852| 1600002 | Marshalling or unmarshalling error. | 2853| 1600003 | Failed to connect service. | 2854 2855**Example** 2856 2857```ts 2858import Base from '@ohos.base'; 2859 2860notificationManager.isSupportDoNotDisturbMode().then((data: boolean) => { 2861 console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); 2862}).catch((err: Base.BusinessError) => { 2863 console.error(`supportDoNotDisturbMode fail: ${JSON.stringify(err)}`); 2864}); 2865``` 2866 2867## notificationManager.isSupportTemplate 2868 2869isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void 2870 2871Checks whether a specified template is supported. This API uses an asynchronous callback to return the result. 2872 2873**System capability**: SystemCapability.Notification.Notification 2874 2875**Parameters** 2876 2877| Name | Type | Mandatory| Description | 2878| ------------ | ------------------------ | ---- | -------------------------- | 2879| templateName | string | Yes | Template name. | 2880| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 2881 2882**Error codes** 2883 2884For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2885 2886| ID| Error Message | 2887| -------- | ----------------------------------- | 2888| 1600001 | Internal error. | 2889| 1600002 | Marshalling or unmarshalling error. | 2890| 1600003 | Failed to connect service. | 2891 2892**Example** 2893 2894```ts 2895import Base from '@ohos.base'; 2896 2897let templateName: string = 'process'; 2898let isSupportTemplateCallback = (err: Base.BusinessError, data: boolean): void => { 2899 if (err) { 2900 console.error(`isSupportTemplate failed, code is ${err.code}, message is ${err.message}`); 2901 } else { 2902 console.info("isSupportTemplate success"); 2903 } 2904} 2905 2906notificationManager.isSupportTemplate(templateName, isSupportTemplateCallback); 2907``` 2908 2909## notificationManager.isSupportTemplate 2910 2911isSupportTemplate(templateName: string): Promise\<boolean\> 2912 2913Checks whether a specified template is supported. This API uses a promise to return the result. 2914 2915**System capability**: SystemCapability.Notification.Notification 2916 2917**Parameters** 2918 2919| Name | Type | Mandatory| Description | 2920| ------------ | ------ | ---- | -------- | 2921| templateName | string | Yes | Template name.| 2922 2923**Return value** 2924 2925| Type | Description | 2926| ------------------ | --------------- | 2927| Promise\<boolean\> | Promise used to return the result.| 2928 2929**Error codes** 2930 2931For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2932 2933| ID| Error Message | 2934| -------- | ----------------------------------- | 2935| 1600001 | Internal error. | 2936| 1600002 | Marshalling or unmarshalling error. | 2937| 1600003 | Failed to connect service. | 2938 2939**Example** 2940 2941```ts 2942import Base from '@ohos.base'; 2943 2944let templateName: string = 'process'; 2945 2946notificationManager.isSupportTemplate(templateName).then((data: boolean) => { 2947 console.info("isSupportTemplate success, data: " + JSON.stringify(data)); 2948}).catch((err: Base.BusinessError) => { 2949 console.error(`isSupportTemplate fail: ${JSON.stringify(err)}`); 2950}); 2951``` 2952 2953## notificationManager.requestEnableNotification 2954 2955requestEnableNotification(callback: AsyncCallback\<void\>): void 2956 2957Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result. 2958 2959**System capability**: SystemCapability.Notification.Notification 2960 2961**Parameters** 2962 2963| Name | Type | Mandatory| Description | 2964| -------- | ------------------------ | ---- | -------------------------- | 2965| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2966 2967**Error codes** 2968 2969For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 2970 2971| ID| Error Message | 2972| -------- | ----------------------------------- | 2973| 1600001 | Internal error. | 2974| 1600002 | Marshalling or unmarshalling error. | 2975| 1600003 | Failed to connect service. | 2976 2977**Example** 2978 2979```ts 2980import Base from '@ohos.base'; 2981 2982let requestEnableNotificationCallback = (err: Base.BusinessError): void => { 2983 if (err) { 2984 console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); 2985 } else { 2986 console.info("requestEnableNotification success"); 2987 } 2988}; 2989 2990notificationManager.requestEnableNotification(requestEnableNotificationCallback); 2991``` 2992 2993## notificationManager.requestEnableNotification 2994 2995requestEnableNotification(): Promise\<void\> 2996 2997Requests notification to be enabled for this application. This API uses a promise to return the result. 2998 2999**System capability**: SystemCapability.Notification.Notification 3000 3001**Error codes** 3002 3003For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3004 3005| ID| Error Message | 3006| -------- | ----------------------------------- | 3007| 1600001 | Internal error. | 3008| 1600002 | Marshalling or unmarshalling error. | 3009| 1600003 | Failed to connect service. | 3010 3011**Example** 3012 3013```ts 3014import Base from '@ohos.base'; 3015 3016notificationManager.requestEnableNotification().then(() => { 3017 console.info("requestEnableNotification success"); 3018}).catch((err: Base.BusinessError) => { 3019 console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`); 3020}); 3021``` 3022 3023## notificationManager.requestEnableNotification<sup>10+<sup> 3024 3025requestEnableNotification(context: UIAbilityContext, callback: AsyncCallback\<void\>): void 3026 3027Requests notification to be enabled for this application in a modal. This API uses an asynchronous callback to return the result. 3028 3029**Model restriction**: This API can be used only in the stage model. 3030 3031**System capability**: SystemCapability.Notification.Notification 3032 3033**Parameters** 3034 3035| Name | Type | Mandatory| Description | 3036| -------- | ------------------------ | ---- |--------------------| 3037| context | UIAbilityContext | Yes | Ability context bound to the notification dialog box.| 3038| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 3039 3040**Error codes** 3041 3042For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3043 3044| ID| Error Message | 3045| -------- | ----------------------------------- | 3046| 1600001 | Internal error. | 3047| 1600002 | Marshalling or unmarshalling error. | 3048| 1600003 | Failed to connect service. | 3049 3050**Example** 3051 3052```ts 3053import Base from '@ohos.base'; 3054import UIAbility from '@ohos.app.ability.UIAbility'; 3055import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 3056import Want from '@ohos.app.ability.Want'; 3057 3058class MyAbility extends UIAbility { 3059 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 3060 let requestEnableNotificationCallback = (err: Base.BusinessError): void => { 3061 if (err) { 3062 console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); 3063 } else { 3064 console.info("requestEnableNotification success"); 3065 } 3066 }; 3067 3068 notificationManager.requestEnableNotification(this.context, requestEnableNotificationCallback); 3069 } 3070} 3071``` 3072 3073## notificationManager.requestEnableNotification<sup>10+<sup> 3074 3075requestEnableNotification(context: UIAbilityContext): Promise\<void\> 3076 3077Requests notification to be enabled for this application in a modal. This API uses a promise to return the result. 3078 3079**Model restriction**: This API can be used only in the stage model. 3080 3081**System capability**: SystemCapability.Notification.Notification 3082 3083**Parameters** 3084 3085| Name | Type | Mandatory| Description | 3086| -------- | ------------------------ | ---- |--------------------| 3087| context | UIAbilityContext | Yes | Ability context bound to the notification dialog box.| 3088 3089**Error codes** 3090 3091For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3092 3093| ID| Error Message | 3094| -------- | ----------------------------------- | 3095| 1600001 | Internal error. | 3096| 1600002 | Marshalling or unmarshalling error. | 3097| 1600003 | Failed to connect service. | 3098 3099**Example** 3100 3101```ts 3102import Base from '@ohos.base'; 3103import UIAbility from '@ohos.app.ability.UIAbility'; 3104import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 3105import Want from '@ohos.app.ability.Want'; 3106 3107class MyAbility extends UIAbility { 3108 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 3109 notificationManager.requestEnableNotification(this.context).then(() => { 3110 console.info("requestEnableNotification success"); 3111 }).catch((err: Base.BusinessError) => { 3112 console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`); 3113 }); 3114 } 3115} 3116``` 3117 3118## notificationManager.setDistributedEnable 3119 3120setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void 3121 3122Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. 3123 3124**System capability**: SystemCapability.Notification.Notification 3125 3126**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3127 3128**System API**: This is a system API and cannot be called by third-party applications. 3129 3130**Parameters** 3131 3132| Name | Type | Mandatory| Description | 3133| -------- | ------------------------ | ---- | -------------------------- | 3134| enable | boolean | Yes | Whether the device supports distributed notifications.| 3135| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3136 3137**Error codes** 3138 3139For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3140 3141| ID| Error Message | 3142| -------- | ----------------------------------- | 3143| 1600001 | Internal error. | 3144| 1600002 | Marshalling or unmarshalling error. | 3145| 1600003 | Failed to connect service. | 3146| 1600010 | Distributed operation failed. | 3147 3148**Example** 3149 3150```ts 3151import Base from '@ohos.base'; 3152 3153let setDistributedEnableCallback = (err: Base.BusinessError): void => { 3154 if (err) { 3155 console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`); 3156 } else { 3157 console.info("setDistributedEnable success"); 3158 } 3159}; 3160 3161let enable: boolean = true; 3162 3163notificationManager.setDistributedEnable(enable, setDistributedEnableCallback); 3164``` 3165 3166## notificationManager.setDistributedEnable 3167 3168setDistributedEnable(enable: boolean): Promise\<void> 3169 3170Sets whether this device supports distributed notifications. This API uses a promise to return the result. 3171 3172**System capability**: SystemCapability.Notification.Notification 3173 3174**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3175 3176**System API**: This is a system API and cannot be called by third-party applications. 3177 3178**Parameters** 3179 3180| Name | Type | Mandatory| Description | 3181| -------- | ------------------------ | ---- | -------------------------- | 3182| enable | boolean | Yes | Whether the device supports distributed notifications.| 3183 3184**Error codes** 3185 3186For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3187 3188| ID| Error Message | 3189| -------- | ----------------------------------- | 3190| 1600001 | Internal error. | 3191| 1600002 | Marshalling or unmarshalling error. | 3192| 1600003 | Failed to connect service. | 3193| 1600010 | Distributed operation failed. | 3194 3195**Example** 3196 3197```ts 3198import Base from '@ohos.base'; 3199 3200let enable: boolean = true; 3201 3202notificationManager.setDistributedEnable(enable).then(() => { 3203 console.info("setDistributedEnable success"); 3204}).catch((err: Base.BusinessError) => { 3205 console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`); 3206}); 3207``` 3208 3209## notificationManager.requestEnableNotification<sup>10+<sup> 3210 3211## notificationManager.isDistributedEnabled 3212 3213isDistributedEnabled(callback: AsyncCallback\<boolean>): void 3214 3215Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. 3216 3217**System capability**: SystemCapability.Notification.Notification 3218 3219**Parameters** 3220 3221| Name | Type | Mandatory| Description | 3222| -------- | ------------------------ | ---- | -------------------------- | 3223| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 3224 3225**Error codes** 3226 3227For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3228 3229| ID| Error Message | 3230| -------- | ----------------------------------- | 3231| 1600001 | Internal error. | 3232| 1600002 | Marshalling or unmarshalling error. | 3233| 1600003 | Failed to connect service. | 3234| 1600010 | Distributed operation failed. | 3235 3236**Example** 3237 3238```ts 3239import Base from '@ohos.base'; 3240 3241let isDistributedEnabledCallback = (err: Base.BusinessError, data: boolean): void => { 3242 if (err) { 3243 console.error(`isDistributedEnabled failed, code is ${err.code}, message is ${err.message}`); 3244 } else { 3245 console.info("isDistributedEnabled success " + JSON.stringify(data)); 3246 } 3247}; 3248 3249notificationManager.isDistributedEnabled(isDistributedEnabledCallback); 3250``` 3251 3252 3253 3254## notificationManager.isDistributedEnabled 3255 3256isDistributedEnabled(): Promise\<boolean> 3257 3258Checks whether this device supports distributed notifications. This API uses a promise to return the result. 3259 3260**System capability**: SystemCapability.Notification.Notification 3261 3262**Return value** 3263 3264| Type | Description | 3265| ------------------ | --------------------------------------------- | 3266| Promise\<boolean\> | Promise used to return the result.| 3267 3268**Error codes** 3269 3270For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3271 3272| ID| Error Message | 3273| -------- | ----------------------------------- | 3274| 1600001 | Internal error. | 3275| 1600002 | Marshalling or unmarshalling error. | 3276| 1600003 | Failed to connect service. | 3277| 1600010 | Distributed operation failed. | 3278 3279**Example** 3280 3281```ts 3282import Base from '@ohos.base'; 3283 3284notificationManager.isDistributedEnabled() 3285.then((data: boolean) => { 3286 console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); 3287}).catch((err: Base.BusinessError) => { 3288 console.error(`isDistributedEnabled fail: ${JSON.stringify(err)}`); 3289}); 3290``` 3291 3292 3293## notificationManager.setDistributedEnableByBundle 3294 3295setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void 3296 3297Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. 3298 3299**System capability**: SystemCapability.Notification.Notification 3300 3301**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3302 3303**System API**: This is a system API and cannot be called by third-party applications. 3304 3305**Parameters** 3306 3307| Name | Type | Mandatory| Description | 3308| -------- | ------------------------ | ---- | -------------------------- | 3309| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3310| enable | boolean | Yes | Whether the device supports distributed notifications. | 3311| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3312 3313**Error codes** 3314 3315For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3316 3317| ID| Error Message | 3318| -------- | ---------------------------------------- | 3319| 1600001 | Internal error. | 3320| 1600002 | Marshalling or unmarshalling error. | 3321| 1600003 | Failed to connect service. | 3322| 1600010 | Distributed operation failed. | 3323| 17700001 | The specified bundle name was not found. | 3324 3325**Example** 3326 3327```ts 3328import Base from '@ohos.base'; 3329 3330let setDistributedEnableByBundleCallback = (err: Base.BusinessError): void => { 3331 if (err) { 3332 console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`); 3333 } else { 3334 console.info("enableDistributedByBundle success"); 3335 } 3336}; 3337 3338let bundle: notificationManager.BundleOption = { 3339 bundle: "bundleName1", 3340}; 3341 3342let enable: boolean = true; 3343 3344notificationManager.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback); 3345``` 3346 3347 3348 3349## notificationManager.setDistributedEnableByBundle 3350 3351setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<void> 3352 3353Sets whether a specified application supports distributed notifications. This API uses a promise to return the result. 3354 3355**System capability**: SystemCapability.Notification.Notification 3356 3357**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3358 3359**System API**: This is a system API and cannot be called by third-party applications. 3360 3361**Parameters** 3362 3363| Name | Type | Mandatory| Description | 3364| -------- | ------------------------ | ---- | -------------------------- | 3365| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3366| enable | boolean | Yes | Whether the device supports distributed notifications. | 3367 3368**Error codes** 3369 3370For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3371 3372| ID| Error Message | 3373| -------- | ---------------------------------------- | 3374| 1600001 | Internal error. | 3375| 1600002 | Marshalling or unmarshalling error. | 3376| 1600003 | Failed to connect service. | 3377| 1600010 | Distributed operation failed. | 3378| 17700001 | The specified bundle name was not found. | 3379 3380**Example** 3381 3382```ts 3383import Base from '@ohos.base'; 3384 3385let bundle: notificationManager.BundleOption = { 3386 bundle: "bundleName1", 3387}; 3388 3389let enable: boolean = true; 3390 3391notificationManager.setDistributedEnableByBundle(bundle, enable).then(() => { 3392 console.info("setDistributedEnableByBundle success"); 3393}).catch((err: Base.BusinessError) => { 3394 console.error(`setDistributedEnableByBundle fail: ${JSON.stringify(err)}`); 3395}); 3396``` 3397 3398## notificationManager.isDistributedEnabledByBundle 3399 3400isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void 3401 3402Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. 3403 3404**System capability**: SystemCapability.Notification.Notification 3405 3406**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3407 3408**System API**: This is a system API and cannot be called by third-party applications. 3409 3410**Parameters** 3411 3412| Name | Type | Mandatory| Description | 3413| -------- | ------------------------ | ---- | -------------------------- | 3414| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3415| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 3416 3417**Error codes** 3418 3419For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3420 3421| ID| Error Message | 3422| -------- | ---------------------------------------- | 3423| 1600001 | Internal error. | 3424| 1600002 | Marshalling or unmarshalling error. | 3425| 1600003 | Failed to connect service. | 3426| 1600010 | Distributed operation failed. | 3427| 17700001 | The specified bundle name was not found. | 3428 3429**Example** 3430 3431```ts 3432import Base from '@ohos.base'; 3433 3434let isDistributedEnabledByBundleCallback = (err: Base.BusinessError, data: boolean): void => { 3435 if (err) { 3436 console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`); 3437 } else { 3438 console.info("isDistributedEnabledByBundle success" + JSON.stringify(data)); 3439 } 3440}; 3441 3442let bundle: notificationManager.BundleOption = { 3443 bundle: "bundleName1", 3444}; 3445 3446notificationManager.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback); 3447``` 3448 3449## notificationManager.isDistributedEnabledByBundle 3450 3451isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean> 3452 3453Checks whether a specified application supports distributed notifications. This API uses a promise to return the result. 3454 3455**System capability**: SystemCapability.Notification.Notification 3456 3457**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3458 3459**System API**: This is a system API and cannot be called by third-party applications. 3460 3461**Parameters** 3462 3463| Name | Type | Mandatory| Description | 3464| -------- | ------------------------ | ---- | -------------------------- | 3465| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3466 3467**Return value** 3468 3469| Type | Description | 3470| ------------------ | ------------------------------------------------- | 3471| Promise\<boolean\> | Promise used to return the result.| 3472 3473**Error codes** 3474 3475For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3476 3477| ID| Error Message | 3478| -------- | ---------------------------------------- | 3479| 1600001 | Internal error. | 3480| 1600002 | Marshalling or unmarshalling error. | 3481| 1600003 | Failed to connect service. | 3482| 1600010 | Distributed operation failed. | 3483| 17700001 | The specified bundle name was not found. | 3484 3485**Example** 3486 3487```ts 3488import Base from '@ohos.base'; 3489 3490let bundle: notificationManager.BundleOption = { 3491 bundle: "bundleName1", 3492}; 3493 3494notificationManager.isDistributedEnabledByBundle(bundle).then((data: boolean) => { 3495 console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); 3496}).catch((err: Base.BusinessError) => { 3497 console.error(`isDistributedEnabledByBundle fail: ${JSON.stringify(err)}`); 3498}); 3499``` 3500 3501 3502## notificationManager.getDeviceRemindType 3503 3504getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void 3505 3506Obtains the notification reminder type. This API uses an asynchronous callback to return the result. 3507 3508**System capability**: SystemCapability.Notification.Notification 3509 3510**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3511 3512**System API**: This is a system API and cannot be called by third-party applications. 3513 3514**Parameters** 3515 3516| Name | Type | Mandatory| Description | 3517| -------- | --------------------------------- | ---- | -------------------------- | 3518| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes | Callback used to return the result.| 3519 3520**Error codes** 3521 3522For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3523 3524| ID| Error Message | 3525| -------- | ----------------------------------- | 3526| 1600001 | Internal error. | 3527| 1600002 | Marshalling or unmarshalling error. | 3528| 1600003 | Failed to connect service. | 3529 3530**Example** 3531 3532```ts 3533import Base from '@ohos.base'; 3534 3535let getDeviceRemindTypeCallback = (err: Base.BusinessError, data: notificationManager.DeviceRemindType): void => { 3536 if (err) { 3537 console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`); 3538 } else { 3539 console.info(`getDeviceRemindType success, data is ${JSON.stringify(data)}`); 3540 } 3541}; 3542 3543notificationManager.getDeviceRemindType(getDeviceRemindTypeCallback); 3544``` 3545 3546## notificationManager.getDeviceRemindType 3547 3548getDeviceRemindType(): Promise\<DeviceRemindType\> 3549 3550Obtains the notification reminder type. This API uses a promise to return the result. 3551 3552**System capability**: SystemCapability.Notification.Notification 3553 3554**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3555 3556**System API**: This is a system API and cannot be called by third-party applications. 3557 3558**Return value** 3559 3560| Type | Description | 3561| ------------------ | --------------- | 3562| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.| 3563 3564**Error codes** 3565 3566For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3567 3568| ID| Error Message | 3569| -------- | ----------------------------------- | 3570| 1600001 | Internal error. | 3571| 1600002 | Marshalling or unmarshalling error. | 3572| 1600003 | Failed to connect service. | 3573 3574**Example** 3575 3576```ts 3577import Base from '@ohos.base'; 3578 3579notificationManager.getDeviceRemindType().then((data: notificationManager.DeviceRemindType) => { 3580 console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); 3581}).catch((err: Base.BusinessError) => { 3582 console.error(`getDeviceRemindType fail: ${JSON.stringify(err)}`); 3583}); 3584``` 3585 3586 3587## notificationManager.publishAsBundle 3588 3589publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void 3590 3591Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result. 3592 3593**System capability**: SystemCapability.Notification.Notification 3594 3595**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3596 3597**System API**: This is a system API and cannot be called by third-party applications. 3598 3599**Parameters** 3600 3601| Name | Type | Mandatory| Description | 3602| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | 3603| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 3604| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 3605| userId | number | Yes | User ID. | 3606| callback | AsyncCallback | Yes | Callback used to return the result. | 3607 3608**Error codes** 3609 3610For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3611 3612| ID| Error Message | 3613| -------- | ----------------------------------------- | 3614| 1600001 | Internal error. | 3615| 1600002 | Marshalling or unmarshalling error. | 3616| 1600003 | Failed to connect service. | 3617| 1600004 | Notification is not enabled. | 3618| 1600005 | Notification slot is not enabled. | 3619| 1600008 | The user is not exist. | 3620| 1600009 | Over max number notifications per second. | 3621| 1600012 | No memory space. | 3622 3623**Example** 3624 3625```ts 3626import Base from '@ohos.base'; 3627 3628// publishAsBundle callback 3629let callback = (err: Base.BusinessError): void => { 3630 if (err) { 3631 console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`); 3632 } else { 3633 console.info("publishAsBundle success"); 3634 } 3635} 3636// Bundle name of the application whose notification function is taken over by the reminder agent 3637let representativeBundle: string = "com.example.demo"; 3638// User ID 3639let userId: number = 100; 3640// NotificationRequest object 3641let request: notificationManager.NotificationRequest = { 3642 id: 1, 3643 content: { 3644 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 3645 normal: { 3646 title: "test_title", 3647 text: "test_text", 3648 additionalText: "test_additionalText" 3649 } 3650 } 3651}; 3652 3653notificationManager.publishAsBundle(request, representativeBundle, userId, callback); 3654``` 3655 3656## notificationManager.publishAsBundle 3657 3658publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\> 3659 3660Publishes a notification through the reminder agent. This API uses a promise to return the result. 3661 3662**System capability**: SystemCapability.Notification.Notification 3663 3664**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3665 3666**System API**: This is a system API and cannot be called by third-party applications. 3667 3668**Parameters** 3669 3670 3671| Name | Type | Mandatory| Description | 3672| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | 3673| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 3674| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 3675| userId | number | Yes | User ID. | 3676 3677**Error codes** 3678 3679For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3680 3681| ID| Error Message | 3682| -------- | ----------------------------------------- | 3683| 1600001 | Internal error. | 3684| 1600002 | Marshalling or unmarshalling error. | 3685| 1600003 | Failed to connect service. | 3686| 1600004 | Notification is not enabled. | 3687| 1600005 | Notification slot is not enabled. | 3688| 1600008 | The user is not exist. | 3689| 1600009 | Over max number notifications per second. | 3690| 1600012 | No memory space. | 3691 3692**Example** 3693 3694```ts 3695import Base from '@ohos.base'; 3696 3697// Bundle name of the application whose notification function is taken over by the reminder agent 3698let representativeBundle: string = "com.example.demo"; 3699// User ID 3700let userId: number = 100; 3701// NotificationRequest object 3702let request: notificationManager.NotificationRequest = { 3703 id: 1, 3704 content: { 3705 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 3706 normal: { 3707 title: "test_title", 3708 text: "test_text", 3709 additionalText: "test_additionalText" 3710 } 3711 } 3712}; 3713 3714notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => { 3715 console.info("publishAsBundle success"); 3716}).catch((err: Base.BusinessError) => { 3717 console.error(`publishAsBundle fail: ${JSON.stringify(err)}`); 3718}); 3719``` 3720 3721## notificationManager.cancelAsBundle 3722 3723cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void 3724 3725Cancels a notification published by the reminder agent. This API uses an asynchronous callback to return the result. 3726 3727**System capability**: SystemCapability.Notification.Notification 3728 3729**System API**: This is a system API and cannot be called by third-party applications. 3730 3731**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3732 3733**System API**: This is a system API and cannot be called by third-party applications. 3734 3735**Parameters** 3736 3737| Name | Type | Mandatory| Description | 3738| -------------------- | ------------- | ---- | ------------------------ | 3739| id | number | Yes | Notification ID. | 3740| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 3741| userId | number | Yes | User ID. | 3742| callback | AsyncCallback | Yes | Callback used to return the result.| 3743 3744**Error codes** 3745 3746For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3747 3748| ID| Error Message | 3749| -------- | ----------------------------------- | 3750| 1600001 | Internal error. | 3751| 1600002 | Marshalling or unmarshalling error. | 3752| 1600003 | Failed to connect service. | 3753| 1600007 | The notification is not exist. | 3754| 1600008 | The user is not exist. | 3755 3756**Example** 3757 3758```ts 3759import Base from '@ohos.base'; 3760 3761// cancelAsBundle 3762let cancelAsBundleCallback = (err: Base.BusinessError): void => { 3763 if (err) { 3764 console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`); 3765 } else { 3766 console.info("cancelAsBundle success"); 3767 } 3768} 3769// Bundle name of the application whose notification function is taken over by the reminder agent 3770let representativeBundle: string = "com.example.demo"; 3771// User ID 3772let userId: number = 100; 3773 3774notificationManager.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); 3775``` 3776 3777## notificationManager.cancelAsBundle 3778 3779cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\> 3780 3781Cancels a notification published by the reminder agent. This API uses a promise to return the result. 3782 3783**System capability**: SystemCapability.Notification.Notification 3784 3785**System API**: This is a system API and cannot be called by third-party applications. 3786 3787**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3788 3789**System API**: This is a system API and cannot be called by third-party applications. 3790 3791**Parameters** 3792 3793| Name | Type | Mandatory| Description | 3794| -------------------- | ------ | ---- | ------------------ | 3795| id | number | Yes | Notification ID. | 3796| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| 3797| userId | number | Yes | User ID.| 3798 3799**Error codes** 3800 3801For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3802 3803| ID| Error Message | 3804| -------- | ----------------------------------- | 3805| 1600001 | Internal error. | 3806| 1600002 | Marshalling or unmarshalling error. | 3807| 1600003 | Failed to connect service. | 3808| 1600007 | The notification is not exist. | 3809| 1600008 | The user is not exist. | 3810 3811**Example** 3812 3813```ts 3814import Base from '@ohos.base'; 3815 3816// Bundle name of the application whose notification function is taken over by the reminder agent 3817let representativeBundle: string = "com.example.demo"; 3818// User ID 3819let userId: number = 100; 3820 3821notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => { 3822 console.info("cancelAsBundle success"); 3823}).catch((err: Base.BusinessError) => { 3824 console.error(`cancelAsBundle fail: ${JSON.stringify(err)}`); 3825}); 3826``` 3827 3828## notificationManager.setNotificationEnableSlot 3829 3830setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void 3831 3832Sets whether to enable a specified notification slot type for a specified application. This API uses an asynchronous callback to return the result. 3833 3834**System capability**: SystemCapability.Notification.Notification 3835 3836**System API**: This is a system API and cannot be called by third-party applications. 3837 3838**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3839 3840**Parameters** 3841 3842| Name | Type | Mandatory| Description | 3843| -------- | ----------------------------- | ---- | ---------------------- | 3844| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3845| type | [SlotType](#slottype) | Yes | Notification slot type. | 3846| enable | boolean | Yes | Whether to enable notification. | 3847| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3848 3849**Error codes** 3850 3851For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3852 3853| ID| Error Message | 3854| -------- | ---------------------------------------- | 3855| 1600001 | Internal error. | 3856| 1600002 | Marshalling or unmarshalling error. | 3857| 1600003 | Failed to connect service. | 3858| 17700001 | The specified bundle name was not found. | 3859 3860**Example** 3861 3862```ts 3863import Base from '@ohos.base'; 3864 3865// setNotificationEnableSlot 3866let setNotificationEnableSlotCallback = (err: Base.BusinessError): void => { 3867 if (err) { 3868 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3869 } else { 3870 console.info("setNotificationEnableSlot success"); 3871 } 3872}; 3873 3874notificationManager.setNotificationEnableSlot( 3875 { bundle: "ohos.samples.notification", }, 3876 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3877 true, 3878 setNotificationEnableSlotCallback); 3879``` 3880 3881## notificationManager.setNotificationEnableSlot 3882 3883setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void> 3884 3885Sets whether to enable a specified notification slot type for a specified application. This API uses a promise to return the result. 3886 3887**System capability**: SystemCapability.Notification.Notification 3888 3889**System API**: This is a system API and cannot be called by third-party applications. 3890 3891**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3892 3893**Parameters** 3894 3895| Name| Type | Mandatory| Description | 3896| ------ | ----------------------------- | ---- | -------------- | 3897| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3898| type | [SlotType](#slottype) | Yes | Notification slot type.| 3899| enable | boolean | Yes | Whether to enable notification. | 3900 3901**Error codes** 3902 3903For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3904 3905| ID| Error Message | 3906| -------- | ---------------------------------------- | 3907| 1600001 | Internal error. | 3908| 1600002 | Marshalling or unmarshalling error. | 3909| 1600003 | Failed to connect service. | 3910| 17700001 | The specified bundle name was not found. | 3911 3912**Example** 3913 3914```ts 3915import Base from '@ohos.base'; 3916 3917// setNotificationEnableSlot 3918notificationManager.setNotificationEnableSlot( 3919 { bundle: "ohos.samples.notification", }, 3920 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3921 true).then(() => { 3922 console.info("setNotificationEnableSlot success"); 3923 }).catch((err: Base.BusinessError) => { 3924 console.error(`setNotificationEnableSlot fail: ${JSON.stringify(err)}`); 3925 }); 3926``` 3927 3928## notificationManager.isNotificationSlotEnabled 3929 3930isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void 3931 3932Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. 3933 3934**System capability**: SystemCapability.Notification.Notification 3935 3936**System API**: This is a system API and cannot be called by third-party applications. 3937 3938**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3939 3940**Parameters** 3941 3942| Name | Type | Mandatory| Description | 3943| -------- | ----------------------------- | ---- | ---------------------- | 3944| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3945| type | [SlotType](#slottype) | Yes | Notification slot type. | 3946| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 3947 3948**Error codes** 3949 3950For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 3951 3952| ID| Error Message | 3953| -------- | ---------------------------------------- | 3954| 1600001 | Internal error. | 3955| 1600002 | Marshalling or unmarshalling error. | 3956| 1600003 | Failed to connect service. | 3957| 17700001 | The specified bundle name was not found. | 3958 3959**Example** 3960 3961```ts 3962import Base from '@ohos.base'; 3963 3964// isNotificationSlotEnabled 3965let getEnableSlotCallback = (err: Base.BusinessError, data: boolean): void => { 3966 if (err) { 3967 console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`); 3968 } else { 3969 console.info(`isNotificationSlotEnabled success, data is ${JSON.stringify(data)}`); 3970 } 3971}; 3972 3973notificationManager.isNotificationSlotEnabled( 3974 { bundle: "ohos.samples.notification", }, 3975 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3976 getEnableSlotCallback); 3977``` 3978 3979## notificationManager.isNotificationSlotEnabled 3980 3981isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\> 3982 3983Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. 3984 3985**System capability**: SystemCapability.Notification.Notification 3986 3987**System API**: This is a system API and cannot be called by third-party applications. 3988 3989**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3990 3991**Parameters** 3992 3993| Name| Type | Mandatory| Description | 3994| ------ | ----------------------------- | ---- | -------------- | 3995| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3996| type | [SlotType](#slottype) | Yes | Notification slot type.| 3997 3998**Return value** 3999 4000| Type | Description | 4001| ----------------------------------------------------------- | ------------------------------------------------------------ | 4002| Promise\<boolean\> | Promise used to return the result.| 4003 4004**Error codes** 4005 4006For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4007 4008| ID| Error Message | 4009| -------- | ---------------------------------------- | 4010| 1600001 | Internal error. | 4011| 1600002 | Marshalling or unmarshalling error. | 4012| 1600003 | Failed to connect service. | 4013| 17700001 | The specified bundle name was not found. | 4014 4015**Example** 4016 4017```ts 4018import Base from '@ohos.base'; 4019 4020// isNotificationSlotEnabled 4021notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, 4022 notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data: boolean) => { 4023 console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); 4024}).catch((err: Base.BusinessError) => { 4025 console.error(`isNotificationSlotEnabled fail: ${JSON.stringify(err)}`); 4026}); 4027``` 4028 4029 4030## notificationManager.setSyncNotificationEnabledWithoutApp 4031 4032setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void 4033 4034Sets 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. 4035 4036**System capability**: SystemCapability.Notification.Notification 4037 4038**System API**: This is a system API and cannot be called by third-party applications. 4039 4040**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4041 4042**Parameters** 4043 4044| Name| Type | Mandatory| Description | 4045| ------ | ----------------------------- | ---- | -------------- | 4046| userId | number | Yes | User ID. | 4047| enable | boolean | Yes | Whether the feature is enabled. | 4048| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 4049 4050**Error codes** 4051 4052For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4053 4054| ID| Error Message | 4055| -------- | ----------------------------------- | 4056| 1600001 | Internal error. | 4057| 1600002 | Marshalling or unmarshalling error. | 4058| 1600003 | Failed to connect service. | 4059| 1600008 | The user is not exist. | 4060 4061**Example** 4062 4063```ts 4064import Base from '@ohos.base'; 4065 4066let userId: number = 100; 4067let enable: boolean = true; 4068 4069let callback = (err: Base.BusinessError): void => { 4070 if (err) { 4071 console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`); 4072 } else { 4073 console.info("setSyncNotificationEnabledWithoutApp success"); 4074 } 4075} 4076 4077notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable, callback); 4078``` 4079 4080 4081## notificationManager.setSyncNotificationEnabledWithoutApp 4082 4083setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void> 4084 4085Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. 4086 4087**System capability**: SystemCapability.Notification.Notification 4088 4089**System API**: This is a system API and cannot be called by third-party applications. 4090 4091**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4092 4093**Parameters** 4094 4095| Name| Type | Mandatory| Description | 4096| ------ | ----------------------------- | ---- | -------------- | 4097| userId | number | Yes | User ID. | 4098| enable | boolean | Yes | Whether the feature is enabled. | 4099 4100**Return value** 4101 4102| Type | Description | 4103| ----------------------------------------------------------- | ------------------------------------------------------------ | 4104| Promise\<void\> | Promise used to return the result.| 4105 4106**Error codes** 4107 4108For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4109 4110| ID| Error Message | 4111| -------- | ----------------------------------- | 4112| 1600001 | Internal error. | 4113| 1600002 | Marshalling or unmarshalling error. | 4114| 1600003 | Failed to connect service. | 4115| 1600008 | The user is not exist. | 4116 4117**Example** 4118 4119```ts 4120import Base from '@ohos.base'; 4121 4122let userId: number = 100; 4123let enable: boolean = true; 4124 4125notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { 4126 console.info('setSyncNotificationEnabledWithoutApp success'); 4127}).catch((err: Base.BusinessError) => { 4128 console.error(`setSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`); 4129}); 4130``` 4131 4132 4133## notificationManager.getSyncNotificationEnabledWithoutApp 4134 4135getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void 4136 4137Obtains 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. 4138 4139**System capability**: SystemCapability.Notification.Notification 4140 4141**System API**: This is a system API and cannot be called by third-party applications. 4142 4143**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4144 4145**Parameters** 4146 4147| Name| Type | Mandatory| Description | 4148| ------ | ----------------------------- | ---- | -------------- | 4149| userId | number | Yes | User ID. | 4150| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 4151 4152**Error codes** 4153 4154For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4155 4156| ID| Error Message | 4157| -------- | ----------------------------------- | 4158| 1600001 | Internal error. | 4159| 1600002 | Marshalling or unmarshalling error. | 4160| 1600003 | Failed to connect service. | 4161| 1600008 | The user is not exist. | 4162 4163**Example** 4164 4165```ts 4166import Base from '@ohos.base'; 4167 4168let userId: number = 100; 4169 4170let getSyncNotificationEnabledWithoutAppCallback = (err: Base.BusinessError, data: boolean): void => { 4171 if (err) { 4172 console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err); 4173 } else { 4174 console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data); 4175 } 4176} 4177 4178notificationManager.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback); 4179``` 4180 4181 4182## notificationManager.getSyncNotificationEnabledWithoutApp 4183 4184getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean> 4185 4186Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. 4187 4188**System capability**: SystemCapability.Notification.Notification 4189 4190**System API**: This is a system API and cannot be called by third-party applications. 4191 4192**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4193 4194**Parameters** 4195 4196| Name| Type | Mandatory| Description | 4197| ------ | ----------------------------- | ---- | -------------- | 4198| userId | number | Yes | User ID. | 4199 4200**Return value** 4201 4202| Type | Description | 4203| ------------------ | ------------------------------------------------------------ | 4204| Promise\<boolean\> | Promise used to return the result.| 4205 4206**Error codes** 4207 4208For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4209 4210| ID| Error Message | 4211| -------- | ----------------------------------- | 4212| 1600001 | Internal error. | 4213| 1600002 | Marshalling or unmarshalling error. | 4214| 1600003 | Failed to connect service. | 4215| 1600008 | The user is not exist. | 4216 4217**Example** 4218 4219```ts 4220import Base from '@ohos.base'; 4221 4222let userId: number = 100; 4223 4224notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data: boolean) => { 4225 console.info('getSyncNotificationEnabledWithoutApp, data:' + data); 4226}).catch((err: Base.BusinessError) => { 4227 console.error(`getSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`); 4228}); 4229``` 4230 4231## notificationManager.on<sup>10+</sup> 4232 4233on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void; 4234 4235Subscribes 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. 4236 4237**System capability**: SystemCapability.Notification.Notification 4238 4239**System API**: This is a system API and cannot be called by third-party applications. 4240 4241**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4242 4243**Parameters** 4244 4245| Name| Type | Mandatory| Description | 4246| ------ | ----------------------------- | ---- | -------------- | 4247| type | string | Yes | Event type. The value is fixed to **'checkNotification'**.| 4248| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | Yes | Pointer to the notification verification function.| 4249 4250**Error codes** 4251 4252For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4253 4254| ID| Error Message | 4255| -------- | ----------------------------------- | 4256| 1600001 | Internal error. | 4257 4258**Example** 4259 4260```ts 4261import Base from '@ohos.base'; 4262 4263let OnCheckNotification = (info : notificationManager.NotificationCheckInfo): notificationManager.NotificationCheckResult => { 4264 console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`); 4265 if(info.notificationId == 1){ 4266 let result: notificationManager.NotificationCheckResult = { code: 1, message: "testMsg1"}; 4267 return result; 4268 } else { 4269 let result: notificationManager.NotificationCheckResult = { code: 0, message: "testMsg0"}; 4270 return result; 4271 } 4272} 4273try{ 4274 notificationManager.on("checkNotification", OnCheckNotification); 4275} catch (error){ 4276 console.info(`notificationManager.on error: ${JSON.stringify(error as Base.BusinessError)}`); 4277} 4278``` 4279 4280## notificationManager.off<sup>10+</sup> 4281 4282off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void; 4283 4284Unsubscribes from notification events. 4285 4286**System capability**: SystemCapability.Notification.Notification 4287 4288**System API**: This is a system API and cannot be called by third-party applications. 4289 4290**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4291 4292**Parameters** 4293 4294| Name| Type | Mandatory| Description | 4295| ------ | ----------------------------- | ---- | -------------- | 4296| type | string | Yes | Event type. The value is fixed to **'checkNotification'**.| 4297| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | No | Callback used to return the result. This parameter is left empty by default.| 4298 4299**Error codes** 4300 4301For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 4302 4303| ID| Error Message | 4304| -------- | ----------------------------------- | 4305| 1600001 | Internal error. | 4306 4307**Example** 4308 4309```ts 4310import Base from '@ohos.base'; 4311 4312try{ 4313 notificationManager.off("checkNotification"); 4314} catch (error){ 4315 console.info(`notificationManager.off error: ${JSON.stringify(error as Base.BusinessError)}`); 4316} 4317``` 4318 4319## DoNotDisturbDate 4320 4321**System capability**: SystemCapability.Notification.Notification 4322 4323**System API**: This is a system API and cannot be called by third-party applications. 4324 4325| Name | Type | Mandatory| Description | 4326| ----- | ------------------------------------- | ---- | ---------------------- | 4327| type | [DoNotDisturbType](#donotdisturbtype) | Yes | DND time type.| 4328| begin | Date | Yes | DND start time.| 4329| end | Date | Yes | DND end time.| 4330 4331## DoNotDisturbType 4332 4333**System capability**: SystemCapability.Notification.Notification 4334 4335**System API**: This is a system API and cannot be called by third-party applications. 4336 4337| Name | Value | Description | 4338| ------------ | ---------------- | ------------------------------------------ | 4339| TYPE_NONE | 0 | Non-DND. | 4340| TYPE_ONCE | 1 | One-shot DND at the specified time segment (only considering the hour and minute).| 4341| TYPE_DAILY | 2 | Daily DND at the specified time segment (only considering the hour and minute).| 4342| TYPE_CLEARLY | 3 | DND at the specified time segment (considering the year, month, day, hour, and minute). | 4343 4344 4345## ContentType 4346 4347**System capability**: SystemCapability.Notification.Notification 4348 4349| Name | Value | Description | 4350| --------------------------------- | ----------- |------------------| 4351| NOTIFICATION_CONTENT_BASIC_TEXT | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification. | 4352| NOTIFICATION_CONTENT_LONG_TEXT | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification. | 4353| NOTIFICATION_CONTENT_PICTURE | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification. | 4354| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification (not supported currently).| 4355| NOTIFICATION_CONTENT_MULTILINE | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification. | 4356 4357## SlotLevel 4358 4359**System capability**: SystemCapability.Notification.Notification 4360 4361| Name | Value | Description | 4362| --------------------------------- | ----------- | ------------------ | 4363| LEVEL_NONE | 0 | Notification is disabled. | 4364| LEVEL_MIN | 1 | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.| 4365| LEVEL_LOW | 2 | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.| 4366| LEVEL_DEFAULT | 3 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.| 4367| LEVEL_HIGH | 4 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.| 4368 4369 4370## SlotType 4371 4372**System capability**: SystemCapability.Notification.Notification 4373 4374| Name | Value | Description | 4375| -------------------- | -------- | ---------- | 4376| UNKNOWN_TYPE | 0 | Unknown type.| 4377| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication.| 4378| SERVICE_INFORMATION | 2 | Notification slot for service information.| 4379| CONTENT_INFORMATION | 3 | Notification slot for content consultation.| 4380| OTHER_TYPES | 0xFFFF | Notification slot for other purposes.| 4381 4382 4383 4384 4385## DeviceRemindType 4386 4387**System capability**: SystemCapability.Notification.Notification 4388 4389**System API**: This is a system API and cannot be called by third-party applications. 4390 4391| Name | Value | Description | 4392| -------------------- | --- | --------------------------------- | 4393| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. | 4394| IDLE_REMIND | 1 | The device is not in use. | 4395| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | 4396| ACTIVE_REMIND | 3 | The device is in use. | 4397 4398 4399## SourceType 4400 4401**System capability**: SystemCapability.Notification.Notification 4402 4403**System API**: This is a system API and cannot be called by third-party applications. 4404 4405| Name | Value | Description | 4406| -------------------- | --- | -------------------- | 4407| TYPE_NORMAL | 0 | Normal notification. | 4408| TYPE_CONTINUOUS | 1 | Continuous notification. | 4409| TYPE_TIMER | 2 | Timed notification. | 4410 4411## NotificationCheckInfo<sup>10+</sup> 4412 4413**System capability**: SystemCapability.Notification.Notification 4414 4415**System API**: This is a system API and cannot be called by third-party applications. 4416 4417**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4418 4419| Name | Type | Mandatory| Description | 4420| ----- | ------------------------------------- | --- | ---------------------- | 4421| bundleName | string | Yes | Bundle name.| 4422| notificationId | number | Yes | Notification ID. | 4423| contentType | [ContentType](#contenttype) | Yes | Notification type. | 4424 4425## NotificationCheckResult<sup>10+</sup> 4426 4427**System capability**: SystemCapability.Notification.Notification 4428 4429**System API**: This is a system API and cannot be called by third-party applications. 4430 4431**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4432 4433| Name | Type | Mandatory| Description | 4434| ------- | ------------------------------------ | ---- | ---------------------- | 4435| code | number | Yes | Result code.<br>**0**: display.<br>**1**: no display.| 4436| message | string | Yes | Result. | 4437