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