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