1# @ohos.notificationManager (NotificationManager) (System API) 2<!--Kit: Notification Kit--> 3<!--Subsystem: Notification--> 4<!--Owner: @michael_woo888--> 5<!--Designer: @dongqingran; @wulong158--> 6<!--Tester: @wanghong1997--> 7<!--Adviser: @huipeizi--> 8 9The **NotificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status. 10 11> **NOTE**<br> 12> 13> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 14> 15> This topic describes only system APIs provided by the module. For details about its public APIs, see [NotificationManager](./js-apis-notificationManager.md). 16 17## Modules to Import 18 19```ts 20import { notificationManager } from '@kit.NotificationKit'; 21``` 22 23## notificationManager.publish 24 25publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void 26 27Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. 28 29**System capability**: SystemCapability.Notification.Notification 30 31**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.SEND_NOTIFICATION_CROSS_USER 32 33**System API**: This is a system API. 34 35**Parameters** 36 37| Name | Type | Mandatory| Description | 38| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 39| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 40| userId | number | Yes | User ID. | 41| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 42 43**Error codes** 44 45For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [HTTP Error Codes](../apis-network-kit/errorcode-net-http.md). 46 47| ID| Error Message | 48| -------- | ---------------------------------------------------- | 49| 201 | Permission denied. | 50| 202 | Not system application to call the interface. | 51| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 52| 1600001 | Internal error. | 53| 1600002 | Marshalling or unmarshalling error. | 54| 1600003 | Failed to connect to the service. | 55| 1600004 | Notification disabled. | 56| 1600005 | Notification slot disabled. | 57| 1600007 | The notification does not exist. | 58| 1600008 | The user does not exist. | 59| 1600009 | The notification sending frequency reaches the upper limit. | 60| 1600012 | No memory space. | 61| 1600014 | No permission. | 62| 1600015 | The current notification status does not support duplicate configurations. | 63| 1600016 | The notification version for this update is too low. | 64| 1600020 | The application is not allowed to send notifications due to permission settings. | 65| 2300007 | Network unreachable. | 66 67**Example** 68 69```ts 70import { BusinessError } from '@kit.BasicServicesKit'; 71 72// publish callback 73let publishCallback = (err: BusinessError): void => { 74 if (err) { 75 console.error(`publish failed, code is ${err.code}, message is ${err.message}`); 76 } else { 77 console.info("publish success"); 78 } 79} 80// Use the actual user ID when calling the API. 81let userId: number = 1; 82// NotificationRequest object 83let notificationRequest: notificationManager.NotificationRequest = { 84 id: 1, 85 content: { 86 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 87 normal: { 88 title: "test_title", 89 text: "test_text", 90 additionalText: "test_additionalText" 91 } 92 } 93}; 94notificationManager.publish(notificationRequest, userId, publishCallback); 95``` 96 97## notificationManager.publish 98 99publish(request: NotificationRequest, userId: number): Promise\<void\> 100 101Publishes a notification to a specified user. This API uses a promise to return the result. 102 103**System capability**: SystemCapability.Notification.Notification 104 105**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.SEND_NOTIFICATION_CROSS_USER 106 107**System API**: This is a system API. 108 109**Parameters** 110 111| Name | Type | Mandatory| Description | 112| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 113| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 114| userId | number | Yes | User ID. | 115 116**Return value** 117 118| Type | Description | 119| ------- |-----------| 120| Promise\<void\> | Promise that returns no value.| 121 122**Error codes** 123 124For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [HTTP Error Codes](../apis-network-kit/errorcode-net-http.md). 125 126| ID| Error Message | 127| -------- | ---------------------------------------------------- | 128| 201 | Permission denied. | 129| 202 | Not system application to call the interface. | 130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 131| 1600001 | Internal error. | 132| 1600002 | Marshalling or unmarshalling error. | 133| 1600003 | Failed to connect to the service. | 134| 1600004 | Notification disabled. | 135| 1600005 | Notification slot disabled. | 136| 1600007 | The notification does not exist. | 137| 1600008 | The user does not exist. | 138| 1600009 | The notification sending frequency reaches the upper limit. | 139| 1600012 | No memory space. | 140| 1600014 | No permission. | 141| 1600015 | The current notification status does not support duplicate configurations. | 142| 1600016 | The notification version for this update is too low. | 143| 1600020 | The application is not allowed to send notifications due to permission settings. | 144| 2300007 | Network unreachable. | 145 146**Example** 147 148```ts 149import { BusinessError } from '@kit.BasicServicesKit'; 150 151let notificationRequest: notificationManager.NotificationRequest = { 152 id: 1, 153 content: { 154 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 155 normal: { 156 title: "test_title", 157 text: "test_text", 158 additionalText: "test_additionalText" 159 } 160 } 161}; 162 163// Use the actual user ID when calling the API. 164let userId: number = 1; 165 166notificationManager.publish(notificationRequest, userId).then(() => { 167 console.info("publish success"); 168}).catch((err: BusinessError) => { 169 console.error(`publish failed, code is ${err.code}, message is ${err.message}`); 170}); 171``` 172 173## notificationManager.addSlot 174 175addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void 176 177Adds a notification slot. This API uses an asynchronous callback to return the result. 178 179**System capability**: SystemCapability.Notification.Notification 180 181**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 182 183**System API**: This is a system API. 184 185**Parameters** 186 187| Name | Type | Mandatory| Description | 188| -------- | --------------------- | ---- | -------------------- | 189| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md) | Yes | Notification slot to add.| 190| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 191 192**Error codes** 193 194For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 195 196| ID| Error Message | 197| -------- | ----------------------------------- | 198| 201 | Permission denied. | 199| 202 | Not system application to call the interface. | 200| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 201| 1600001 | Internal error. | 202| 1600002 | Marshalling or unmarshalling error. | 203| 1600003 | Failed to connect to the service. | 204| 1600012 | No memory space. | 205 206**Example** 207 208```ts 209import { BusinessError } from '@kit.BasicServicesKit'; 210 211// addSlot callback 212let addSlotCallBack = (err: BusinessError): void => { 213 if (err) { 214 console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); 215 } else { 216 console.info("addSlot success"); 217 } 218} 219// NotificationSlot object 220let notificationSlot: notificationManager.NotificationSlot = { 221 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 222}; 223notificationManager.addSlot(notificationSlot, addSlotCallBack); 224``` 225 226## notificationManager.addSlot 227 228addSlot(slot: NotificationSlot): Promise\<void\> 229 230Adds a notification slot. This API uses a promise to return the result. 231 232**System capability**: SystemCapability.Notification.Notification 233 234**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 235 236**System API**: This is a system API. 237 238**Parameters** 239 240| Name| Type | Mandatory| Description | 241| ---- | ---------------- | ---- | -------------------- | 242| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md) | Yes | Notification slot to add.| 243 244**Return value** 245 246| Type | Description | 247| ------- |-----------| 248| Promise\<void\> | Promise that returns no value.| 249 250**Error codes** 251 252For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 253 254| ID| Error Message | 255| -------- | ----------------------------------- | 256| 201 | Permission denied. | 257| 202 | Not system application to call the interface. | 258| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 259| 1600001 | Internal error. | 260| 1600002 | Marshalling or unmarshalling error. | 261| 1600003 | Failed to connect to the service. | 262| 1600012 | No memory space. | 263 264**Example** 265 266```ts 267import { BusinessError } from '@kit.BasicServicesKit'; 268 269// NotificationSlot object 270let notificationSlot: notificationManager.NotificationSlot = { 271 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 272}; 273notificationManager.addSlot(notificationSlot).then(() => { 274 console.info("addSlot success"); 275}).catch((err: BusinessError) => { 276 console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); 277}); 278``` 279 280## notificationManager.addSlots 281 282addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void 283 284Adds an array of notification slots. This API uses an asynchronous callback to return the result. 285 286**System capability**: SystemCapability.Notification.Notification 287 288**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 289 290**System API**: This is a system API. 291 292**Parameters** 293 294| Name | Type | Mandatory| Description | 295| -------- | ------------------------- | ---- | ------------------------ | 296| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)\> | Yes | Notification slots to add. The number of elements in the array ranges from 0 to 5.| 297| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 298 299**Error codes** 300 301For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 302 303| ID| Error Message | 304| -------- | ----------------------------------- | 305| 201 | Permission denied. | 306| 202 | Not system application to call the interface. | 307| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 308| 1600001 | Internal error. | 309| 1600002 | Marshalling or unmarshalling error. | 310| 1600003 | Failed to connect to the service. | 311| 1600012 | No memory space. | 312 313**Example** 314 315```ts 316import { BusinessError } from '@kit.BasicServicesKit'; 317 318// addSlots callback 319let addSlotsCallBack = (err: BusinessError): void => { 320 if (err) { 321 console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`); 322 } else { 323 console.info("addSlots success"); 324 } 325} 326// NotificationSlot object 327let notificationSlot: notificationManager.NotificationSlot = { 328 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 329}; 330// NotificationSlotArray object 331let notificationSlotArray: notificationManager.NotificationSlot[] = new Array(); 332notificationSlotArray[0] = notificationSlot; 333 334notificationManager.addSlots(notificationSlotArray, addSlotsCallBack); 335``` 336 337## notificationManager.addSlots 338 339addSlots(slots: Array\<NotificationSlot\>): Promise\<void\> 340 341Adds an array of notification slots. This API uses a promise to return the result. 342 343**System capability**: SystemCapability.Notification.Notification 344 345**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 346 347**System API**: This is a system API. 348 349**Parameters** 350 351| Name | Type | Mandatory| Description | 352| ----- | ------------------------- | ---- | ------------------------ | 353| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)\> | Yes | Notification slots to add. The number of elements in the array ranges from 0 to 5.| 354 355**Return value** 356 357| Type | Description | 358|---------|-----------| 359| Promise\<void\> | Promise that returns no value.| 360 361**Error codes** 362 363For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 364 365| ID| Error Message | 366| -------- | ----------------------------------- | 367| 201 | Permission denied. | 368| 202 | Not system application to call the interface. | 369| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 370| 1600001 | Internal error. | 371| 1600002 | Marshalling or unmarshalling error. | 372| 1600003 | Failed to connect to the service. | 373| 1600012 | No memory space. | 374 375**Example** 376 377```ts 378import { BusinessError } from '@kit.BasicServicesKit'; 379 380// NotificationSlot object 381let notificationSlot: notificationManager.NotificationSlot = { 382 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 383}; 384// NotificationSlotArray object 385let notificationSlotArray: notificationManager.NotificationSlot[] = new Array(); 386notificationSlotArray[0] = notificationSlot; 387 388notificationManager.addSlots(notificationSlotArray).then(() => { 389 console.info("addSlots success"); 390}).catch((err: BusinessError) => { 391 console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`); 392}); 393``` 394 395 396## notificationManager.setNotificationEnable 397 398setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 399 400Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. 401 402**System capability**: SystemCapability.Notification.Notification 403 404**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 405 406**System API**: This is a system API. 407 408**Parameters** 409 410| Name | Type | Mandatory| Description | 411| -------- | --------------------- | ---- | -------------------- | 412| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 413| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 414| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 415 416**Error codes** 417 418For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 419 420| ID| Error Message | 421| -------- | ---------------------------------------- | 422| 201 | Permission denied. | 423| 202 | Not system application to call the interface. | 424| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 425| 1600001 | Internal error. | 426| 1600002 | Marshalling or unmarshalling error. | 427| 1600003 | Failed to connect to the service. | 428| 17700001 | The specified bundle name was not found. | 429 430**Example** 431 432```ts 433import { BusinessError } from '@kit.BasicServicesKit'; 434 435let setNotificationEnableCallback = (err: BusinessError): void => { 436 if (err) { 437 console.error(`setNotificationEnable failed, code is ${err.code}, message is ${err.message}`); 438 } else { 439 console.info("setNotificationEnable success"); 440 } 441} 442let bundle: notificationManager.BundleOption = { 443 bundle: "bundleName1", 444}; 445notificationManager.setNotificationEnable(bundle, false, setNotificationEnableCallback); 446``` 447 448## notificationManager.setNotificationEnable 449 450setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\> 451 452Sets whether to enable notification for a specified application. This API uses a promise to return the result. 453 454**System capability**: SystemCapability.Notification.Notification 455 456**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 457 458**System API**: This is a system API. 459 460**Parameters** 461 462| Name | Type | Mandatory| Description | 463| ------ | ------------ | ---- | ---------- | 464| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 465| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 466 467**Return value** 468 469| Type | Description | 470|---------|-----------| 471| Promise\<void\> | Promise that returns no value.| 472 473**Error codes** 474 475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 476 477| ID| Error Message | 478| -------- | ---------------------------------------- | 479| 201 | Permission denied. | 480| 202 | Not system application to call the interface. | 481| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 482| 1600001 | Internal error. | 483| 1600002 | Marshalling or unmarshalling error. | 484| 1600003 | Failed to connect to the service. | 485| 17700001 | The specified bundle name was not found. | 486 487**Example** 488 489```ts 490import { BusinessError } from '@kit.BasicServicesKit'; 491 492let bundle: notificationManager.BundleOption = { 493 bundle: "bundleName1", 494}; 495notificationManager.setNotificationEnable(bundle, false).then(() => { 496 console.info("setNotificationEnable success"); 497}).catch((err: BusinessError) => { 498 console.error(`setNotificationEnable failed, code is ${err.code}, message is ${err.message}`); 499}); 500``` 501 502## notificationManager.getAllNotificationEnabledBundles<sup>12+</sup> 503 504getAllNotificationEnabledBundles(): Promise<Array<BundleOption\>> 505 506Obtains a list of applications that allow notifications. This API uses a promise to return the result. 507 508**System capability**: SystemCapability.Notification.Notification 509 510**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 511 512**System API**: This is a system API. 513 514**Return value** 515 516| Type | Description | 517|---------|-----------| 518| Promise<Array<[BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)\>> | Returns a list of applications that allow notifications.| 519 520**Error codes** 521 522For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 523 524| ID| Error Message | 525| -------- | ----------------------------------- | 526| 201 | Permission denied. | 527| 202 | Not system application to call the interface. | 528| 1600001 | Internal error. | 529| 1600002 | Marshalling or unmarshalling error. | 530| 1600003 | Failed to connect to the service. | 531 532**Example** 533 534```ts 535import { BusinessError } from '@kit.BasicServicesKit'; 536 537notificationManager.getAllNotificationEnabledBundles().then((data: Array<notificationManager.BundleOption>) => { 538 console.info(`Enable bundle data is ${JSON.stringify(data)}`); 539 data.forEach(element => { 540 console.info(`Enable uid is ${JSON.stringify(element.uid)}`); 541 console.info(`Enable bundle is ${JSON.stringify(element.bundle)}`); 542 }); 543}).catch((err: BusinessError) => { 544 console.error(`getAllNotificationEnabledBundles failed, code is ${err.code}, message is ${err.message}`); 545}) 546``` 547 548## notificationManager.isNotificationEnabled 549 550isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 551 552Checks whether notification is enabled for the specified application. This API uses an asynchronous callback to return the result. 553 554**System capability**: SystemCapability.Notification.Notification 555 556**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 557 558**System API**: This is a system API. 559 560**Parameters** 561 562| Name | Type | Mandatory| Description | 563| -------- | --------------------- | ---- | ------------------------ | 564| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 565| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.| 566 567**Error codes** 568 569For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 570 571| ID| Error Message | 572| -------- | ---------------------------------------- | 573| 201 | Permission denied. | 574| 202 | Not system application to call the interface. | 575| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 576| 1600001 | Internal error. | 577| 1600002 | Marshalling or unmarshalling error. | 578| 1600003 | Failed to connect to the service. | 579| 17700001 | The specified bundle name was not found. | 580 581**Example** 582 583```ts 584import { BusinessError } from '@kit.BasicServicesKit'; 585 586let isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => { 587 if (err) { 588 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 589 } else { 590 console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 591 } 592} 593 594let bundle: notificationManager.BundleOption = { 595 bundle: "bundleName1", 596}; 597 598notificationManager.isNotificationEnabled(bundle, isNotificationEnabledCallback); 599``` 600 601## notificationManager.isNotificationEnabled 602 603isNotificationEnabled(bundle: BundleOption): Promise\<boolean\> 604 605Checks whether notification is enabled for the specified application. This API uses a promise to return the result. 606 607**System capability**: SystemCapability.Notification.Notification 608 609**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 610 611**System API**: This is a system API. 612 613**Parameters** 614 615| Name | Type | Mandatory| Description | 616| ------ | ------------ | ---- | ---------- | 617| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 618 619**Return value** 620 621| Type | Description | 622| ------------------ | --------------------------------------------------- | 623| Promise\<boolean\> | Promise used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.| 624 625**Error codes** 626 627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 628 629| ID| Error Message | 630| -------- | ---------------------------------------- | 631| 201 | Permission denied. | 632| 202 | Not system application to call the interface. | 633| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 634| 1600001 | Internal error. | 635| 1600002 | Marshalling or unmarshalling error. | 636| 1600003 | Failed to connect to the service. | 637| 17700001 | The specified bundle name was not found. | 638 639**Example** 640 641```ts 642import { BusinessError } from '@kit.BasicServicesKit'; 643 644let bundle: notificationManager.BundleOption = { 645 bundle: "bundleName1", 646}; 647notificationManager.isNotificationEnabled(bundle).then((data: boolean) => { 648 console.info(`isNotificationEnabled success, data: ${JSON.stringify(data)}`); 649}).catch((err: BusinessError) => { 650 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 651}); 652``` 653 654## notificationManager.isNotificationEnabled 655 656isNotificationEnabled(userId: number, callback: AsyncCallback\<boolean\>): void 657 658Checks whether notification is enabled for a specified user. This API uses an asynchronous callback to return the result. 659 660**System capability**: SystemCapability.Notification.Notification 661 662**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 663 664**System API**: This is a system API. 665 666**Parameters** 667 668| Name | Type | Mandatory| Description | 669| -------- | --------------------- | ---- | ------------------------ | 670| userId | number | Yes | User ID.| 671| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.| 672 673**Error codes** 674 675For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 676 677| ID| Error Message | 678| -------- | ----------------------------------- | 679| 201 | Permission denied. | 680| 202 | Not system application to call the interface. | 681| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 682| 1600001 | Internal error. | 683| 1600002 | Marshalling or unmarshalling error. | 684| 1600003 | Failed to connect to the service. | 685| 1600008 | The user does not exist. | 686 687**Example** 688 689```ts 690import { BusinessError } from '@kit.BasicServicesKit'; 691 692let isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => { 693 if (err) { 694 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 695 } else { 696 console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 697 } 698} 699 700// Use the actual user ID when calling the API. 701let userId: number = 1; 702 703notificationManager.isNotificationEnabled(userId, isNotificationEnabledCallback); 704``` 705 706## notificationManager.isNotificationEnabled 707 708isNotificationEnabled(userId: number): Promise\<boolean\> 709 710Checks whether notification is enabled for a specified user. This API uses a promise to return the result. 711 712**System capability**: SystemCapability.Notification.Notification 713 714**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 715 716**System API**: This is a system API. 717 718**Parameters** 719 720| Name | Type | Mandatory| Description | 721| ------ | ------------ | ---- | ---------- | 722| userId | number | Yes | User ID.| 723 724**Return value** 725 726| Type | Description | 727| ----------------------------------------------------------- | ------------------------------------------------------------ | 728| Promise\<boolean\> | Promise used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.| 729 730**Error codes** 731 732For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 733 734| ID| Error Message | 735| -------- | ---------------------------------------- | 736| 201 | Permission denied. | 737| 202 | Not system application to call the interface. | 738| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 739| 1600001 | Internal error. | 740| 1600002 | Marshalling or unmarshalling error. | 741| 1600003 | Failed to connect to the service. | 742| 1600008 | The user does not exist. | 743 744**Example** 745 746```ts 747import { BusinessError } from '@kit.BasicServicesKit'; 748 749// Use the actual user ID when calling the API. 750let userId: number = 1; 751 752notificationManager.isNotificationEnabled(userId).then((data: boolean) => { 753 console.info(`isNotificationEnabled success, data: ${JSON.stringify(data)}`); 754}).catch((err: BusinessError) => { 755 console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 756}); 757``` 758 759## notificationManager.displayBadge 760 761displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 762 763Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. 764 765This API is not supported on wearables. 766 767**System capability**: SystemCapability.Notification.Notification 768 769**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 770 771**System API**: This is a system API. 772 773**Parameters** 774 775| Name | Type | Mandatory| Description | 776| -------- | --------------------- | ---- | -------------------- | 777| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 778| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 779| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 780 781**Error codes** 782 783For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 784 785| ID| Error Message | 786| -------- | ---------------------------------------- | 787| 201 | Permission denied. | 788| 202 | Not system application to call the interface. | 789| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 790| 801 | Capability not supported. | 791| 1600001 | Internal error. | 792| 1600002 | Marshalling or unmarshalling error. | 793| 1600003 | Failed to connect to the service. | 794| 17700001 | The specified bundle name was not found. | 795 796**Example** 797 798```ts 799import { BusinessError } from '@kit.BasicServicesKit'; 800 801let displayBadgeCallback = (err: BusinessError): void => { 802 if (err) { 803 console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`); 804 } else { 805 console.info("displayBadge success"); 806 } 807} 808let bundle: notificationManager.BundleOption = { 809 bundle: "bundleName1", 810}; 811notificationManager.displayBadge(bundle, false, displayBadgeCallback); 812``` 813 814## notificationManager.displayBadge 815 816displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\> 817 818Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. 819 820This API is not supported on wearables. 821 822**System capability**: SystemCapability.Notification.Notification 823 824**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 825 826**System API**: This is a system API. 827 828**Parameters** 829 830| Name | Type | Mandatory| Description | 831| ------ | ------------ | ---- | ---------- | 832| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 833| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 834 835**Return value** 836 837| Type | Description | 838|---------|-----------| 839| Promise\<void\> | Promise that returns no value.| 840 841**Error codes** 842 843For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 844 845| ID| Error Message | 846| -------- | ---------------------------------------- | 847| 201 | Permission denied. | 848| 202 | Not system application to call the interface. | 849| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 850| 801 | Capability not supported. | 851| 1600001 | Internal error. | 852| 1600002 | Marshalling or unmarshalling error. | 853| 1600003 | Failed to connect to the service. | 854| 17700001 | The specified bundle name was not found. | 855 856**Example** 857 858```ts 859import { BusinessError } from '@kit.BasicServicesKit'; 860 861let bundle: notificationManager.BundleOption = { 862 bundle: "bundleName1", 863}; 864notificationManager.displayBadge(bundle, false).then(() => { 865 console.info("displayBadge success"); 866}).catch((err: BusinessError) => { 867 console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`); 868}); 869``` 870 871## notificationManager.isBadgeDisplayed 872 873isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 874 875Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. 876 877This API is not supported on wearables. 878 879**System capability**: SystemCapability.Notification.Notification 880 881**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 882 883**System API**: This is a system API. 884 885**Parameters** 886 887| Name | Type | Mandatory| Description | 888| -------- | --------------------- | ---- | ------------------------ | 889| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 890| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that the badge is enabled, and **false** means the opposite.| 891 892**Error codes** 893 894For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 895 896| ID| Error Message | 897| -------- | ---------------------------------------- | 898| 201 | Permission denied. | 899| 202 | Not system application to call the interface. | 900| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 901| 801 | Capability not supported. | 902| 1600001 | Internal error. | 903| 1600002 | Marshalling or unmarshalling error. | 904| 1600003 | Failed to connect to the service. | 905| 17700001 | The specified bundle name was not found. | 906 907**Example** 908 909```ts 910import { BusinessError } from '@kit.BasicServicesKit'; 911 912let isBadgeDisplayedCallback = (err: BusinessError, data: boolean): void => { 913 if (err) { 914 console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`); 915 } else { 916 console.info(`isBadgeDisplayed success, data is ${JSON.stringify(data)}`); 917 } 918} 919let bundle: notificationManager.BundleOption = { 920 bundle: "bundleName1", 921}; 922notificationManager.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); 923``` 924 925## notificationManager.isBadgeDisplayed 926 927isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\> 928 929Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. 930 931This API is not supported on wearables. 932 933**System capability**: SystemCapability.Notification.Notification 934 935**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 936 937**System API**: This is a system API. 938 939**Parameters** 940 941| Name | Type | Mandatory| Description | 942| ------ | ------------ | ---- | ---------- | 943| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 944 945**Return value** 946 947| Type | Description | 948| ----------------------------------------------------------- | ------------------------------------------------------------ | 949| Promise\<boolean\> | Promise used to return the result. The value **true** means that the badge is enabled, and **false** means the opposite.| 950 951**Error codes** 952 953For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 954 955| ID| Error Message | 956| -------- | ---------------------------------------- | 957| 201 | Permission denied. | 958| 202 | Not system application to call the interface. | 959| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 960| 801 | Capability not supported. | 961| 1600001 | Internal error. | 962| 1600002 | Marshalling or unmarshalling error. | 963| 1600003 | Failed to connect to the service. | 964| 17700001 | The specified bundle name was not found. | 965 966**Example** 967 968```ts 969import { BusinessError } from '@kit.BasicServicesKit'; 970 971let bundle: notificationManager.BundleOption = { 972 bundle: "bundleName1", 973}; 974 975notificationManager.isBadgeDisplayed(bundle).then((data: boolean) => { 976 console.info(`isBadgeDisplayed success, data: ${JSON.stringify(data)}`); 977}).catch((err: BusinessError) => { 978 console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`); 979}); 980``` 981 982## notificationManager.setSlotFlagsByBundle<sup>11+</sup> 983 984setSlotFlagsByBundle(bundle: BundleOption, slotFlags: number): Promise\<void\> 985 986Sets the notification slot for a specified application. This API uses a promise to return the result. 987 988This API is not supported on wearables. 989 990**System capability**: SystemCapability.Notification.Notification 991 992**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 993 994**System API**: This is a system API. 995 996**Parameters** 997 998| Name | Type | Mandatory| Description | 999| ------ | ------------ | ---- | ---------- | 1000| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 1001| slotFlags | number | Yes | Notification slot flags.<br>- Bit 0: sound alert. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 1: locking the screen. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 2: banner. The value **0** means to disable the feature, and **1** means the opposite.<br>- BIt 3: turning on the screen. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 4: vibration. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 5: notification icon in the status bar. The value **0** means to disable the feature, and **1** means the opposite.| 1002 1003**Return value** 1004 1005| Type | Description | 1006|---------|-----------| 1007| Promise\<void\> | Promise that returns no value.| 1008 1009**Error codes** 1010 1011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1012 1013| ID| Error Message | 1014| -------- | ---------------------------------------- | 1015| 201 | Permission denied. | 1016| 202 | Not system application to call the interface. | 1017| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1018| 801 | Capability not supported. | 1019| 1600001 | Internal error. | 1020| 1600002 | Marshalling or unmarshalling error. | 1021| 1600003 | Failed to connect to the service. | 1022| 17700001 | The specified bundle name was not found. | 1023 1024**Example** 1025 1026```ts 1027import { BusinessError } from '@kit.BasicServicesKit'; 1028 1029let bundle: notificationManager.BundleOption = { 1030 bundle: "bundleName1", 1031}; 1032 1033let slotFlags: number = 1; 1034 1035notificationManager.setSlotFlagsByBundle(bundle, slotFlags).then(() => { 1036 console.info("setSlotFlagsByBundle success"); 1037}).catch((err: BusinessError) => { 1038 console.error(`setSlotFlagsByBundle failed, code is ${err.code}, message is ${err.message}`); 1039}); 1040``` 1041 1042## notificationManager.setSlotByBundle 1043 1044setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void 1045 1046Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. 1047 1048Before setting a notification slot, create a slot through [addSlot](#notificationmanageraddslot). 1049 1050This API is not supported on wearables. 1051 1052**System capability**: SystemCapability.Notification.Notification 1053 1054**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1055 1056**System API**: This is a system API. 1057 1058**Parameters** 1059 1060| Name | Type | Mandatory| Description | 1061| -------- | --------------------- | ---- | -------------------- | 1062| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 1063| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md) | Yes | Notification slot. | 1064| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1065 1066**Error codes** 1067 1068For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1069 1070| ID| Error Message | 1071| -------- | ---------------------------------------- | 1072| 201 | Permission denied. | 1073| 202 | Not system application to call the interface. | 1074| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1075| 801 | Capability not supported. | 1076| 1600001 | Internal error. | 1077| 1600002 | Marshalling or unmarshalling error. | 1078| 1600003 | Failed to connect to the service. | 1079| 17700001 | The specified bundle name was not found. | 1080 1081**Example** 1082 1083```ts 1084import { BusinessError } from '@kit.BasicServicesKit'; 1085 1086let setSlotByBundleCallback = (err: BusinessError): void => { 1087 if (err) { 1088 console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 1089 } else { 1090 console.info("setSlotByBundle success"); 1091 } 1092} 1093let bundle: notificationManager.BundleOption = { 1094 bundle: "bundleName1", 1095}; 1096let notificationSlot: notificationManager.NotificationSlot = { 1097 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 1098}; 1099notificationManager.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); 1100``` 1101 1102## notificationManager.setSlotByBundle 1103 1104setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\> 1105 1106Sets the notification slot for a specified application. This API uses a promise to return the result. 1107 1108Before setting a notification slot, create a slot through [addSlot](#notificationmanageraddslot). 1109 1110This API is not supported on wearables. 1111 1112**System capability**: SystemCapability.Notification.Notification 1113 1114**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1115 1116**System API**: This is a system API. 1117 1118**Parameters** 1119 1120| Name | Type | Mandatory| Description | 1121| ------ | ------------ | ---- | ---------- | 1122| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 1123| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md) | Yes | Notification slot.| 1124 1125**Return value** 1126 1127| Type | Description | 1128|---------|-----------| 1129| Promise\<void\> | Promise that returns no value.| 1130 1131**Error codes** 1132 1133For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1134 1135| ID| Error Message | 1136| -------- | ---------------------------------------- | 1137| 201 | Permission denied. | 1138| 202 | Not system application to call the interface. | 1139| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1140| 801 | Capability not supported. | 1141| 1600001 | Internal error. | 1142| 1600002 | Marshalling or unmarshalling error. | 1143| 1600003 | Failed to connect to the service. | 1144| 17700001 | The specified bundle name was not found. | 1145 1146**Example** 1147 1148```ts 1149import { BusinessError } from '@kit.BasicServicesKit'; 1150 1151let bundle: notificationManager.BundleOption = { 1152 bundle: "bundleName1", 1153}; 1154 1155let notificationSlot: notificationManager.NotificationSlot = { 1156 notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION 1157}; 1158 1159notificationManager.setSlotByBundle(bundle, notificationSlot).then(() => { 1160 console.info("setSlotByBundle success"); 1161}).catch((err: BusinessError) => { 1162 console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 1163}); 1164``` 1165 1166## notificationManager.getSlotFlagsByBundle<sup>11+</sup> 1167 1168getSlotFlagsByBundle(bundle: BundleOption): Promise\<number\> 1169 1170Obtains the notification slot flag of a specified application. This API uses a promise to return the result. 1171 1172This API is not supported on wearables. 1173 1174**System capability**: SystemCapability.Notification.Notification 1175 1176**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1177 1178**System API**: This is a system API. 1179 1180**Parameters** 1181 1182| Name | Type | Mandatory| Description | 1183| ------ | ------------ | ---- | ---------- | 1184| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 1185 1186**Return value** 1187 1188| Type | Description | 1189| ----------------------------------------------------------- | ------------------------------------------------------------ | 1190| Promise\<number\>| Promise used to return the notification slot flag.<br>- Bit 0: sound alert. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 1: locking the screen. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 2: banner. The value **0** means to disable the feature, and **1** means the opposite.<br>- BIt 3: turning on the screen. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 4: vibration. The value **0** means to disable the feature, and **1** means the opposite.<br>- Bit 5: notification icon in the status bar. The value **0** means to disable the feature, and **1** means the opposite.| 1191 1192**Error codes** 1193 1194For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1195 1196| ID| Error Message | 1197| -------- | ---------------------------------------- | 1198| 201 | Permission denied. | 1199| 202 | Not system application to call the interface. | 1200| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1201| 801 | Capability not supported. | 1202| 1600001 | Internal error. | 1203| 1600002 | Marshalling or unmarshalling error. | 1204| 1600003 | Failed to connect to the service. | 1205| 17700001 | The specified bundle name was not found. | 1206 1207**Example** 1208 1209```ts 1210import { BusinessError } from '@kit.BasicServicesKit'; 1211 1212let bundle: notificationManager.BundleOption = { 1213 bundle: "bundleName1", 1214}; 1215notificationManager.getSlotFlagsByBundle(bundle).then((data : number) => { 1216 console.info(`getSlotFlagsByBundle success, data: ${JSON.stringify(data)}`); 1217}).catch((err: BusinessError) => { 1218 console.error(`getSlotFlagsByBundle failed, code is ${err.code}, message is ${err.message}`); 1219}); 1220``` 1221 1222## notificationManager.getSlotsByBundle 1223 1224getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<NotificationSlot>>): void 1225 1226Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. 1227 1228This API is not supported on wearables. 1229 1230**System capability**: SystemCapability.Notification.Notification 1231 1232**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1233 1234**System API**: This is a system API. 1235 1236**Parameters** 1237 1238| Name | Type | Mandatory| Description | 1239| -------- | ---------------------------------------- | ---- | -------------------- | 1240| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 1241| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)>> | Yes | Callback used to return the result.| 1242 1243**Error codes** 1244 1245For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1246 1247| ID| Error Message | 1248| -------- | ---------------------------------------- | 1249| 201 | Permission denied. | 1250| 202 | Not system application to call the interface. | 1251| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1252| 801 | Capability not supported. | 1253| 1600001 | Internal error. | 1254| 1600002 | Marshalling or unmarshalling error. | 1255| 1600003 | Failed to connect to the service. | 1256| 17700001 | The specified bundle name was not found. | 1257 1258**Example** 1259 1260```ts 1261import { BusinessError } from '@kit.BasicServicesKit'; 1262 1263let getSlotsByBundleCallback = (err: BusinessError, data: Array<notificationManager.NotificationSlot>): void => { 1264 if (err) { 1265 console.error(`getSlotsByBundle failed, code is ${err.code}, message is ${err.message}`); 1266 } else { 1267 console.info(`getSlotsByBundle success, data is ${JSON.stringify(data)}`); 1268 } 1269} 1270let bundle: notificationManager.BundleOption = { 1271 bundle: "bundleName1", 1272}; 1273notificationManager.getSlotsByBundle(bundle, getSlotsByBundleCallback); 1274``` 1275 1276## notificationManager.getSlotsByBundle 1277 1278getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>> 1279 1280Obtains the notification slots of a specified application. This API uses a promise to return the result. 1281 1282This API is not supported on wearables. 1283 1284**System capability**: SystemCapability.Notification.Notification 1285 1286**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1287 1288**System API**: This is a system API. 1289 1290**Parameters** 1291 1292| Name | Type | Mandatory| Description | 1293| ------ | ------------ | ---- | ---------- | 1294| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 1295 1296**Return value** 1297 1298| Type | Description | 1299| ----------------------------------------------------------- | ------------------------------------------------------------ | 1300| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)>> | Promise used to return the result.| 1301 1302**Error codes** 1303 1304For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1305 1306| ID| Error Message | 1307| -------- | ---------------------------------------- | 1308| 201 | Permission denied. | 1309| 202 | Not system application to call the interface. | 1310| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1311| 801 | Capability not supported. | 1312| 1600001 | Internal error. | 1313| 1600002 | Marshalling or unmarshalling error. | 1314| 1600003 | Failed to connect to the service. | 1315| 17700001 | The specified bundle name was not found. | 1316 1317**Example** 1318 1319```ts 1320import { BusinessError } from '@kit.BasicServicesKit'; 1321 1322let bundle: notificationManager.BundleOption = { 1323 bundle: "bundleName1", 1324}; 1325 1326notificationManager.getSlotsByBundle(bundle).then((data: Array<notificationManager.NotificationSlot>) => { 1327 console.info(`getSlotsByBundle success, data: ${JSON.stringify(data)}`); 1328}).catch((err: BusinessError) => { 1329 console.error(`getSlotsByBundle failed, code is ${err.code}, message is ${err.message}`); 1330}); 1331``` 1332 1333## notificationManager.getSlotNumByBundle 1334 1335getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void 1336 1337Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. 1338 1339This API is not supported on wearables. 1340 1341**System capability**: SystemCapability.Notification.Notification 1342 1343**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1344 1345**System API**: This is a system API. 1346 1347**Parameters** 1348 1349| Name | Type | Mandatory| Description | 1350| -------- | ------------------------- | ---- | ---------------------- | 1351| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 1352| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.| 1353 1354**Error codes** 1355 1356For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1357 1358| ID| Error Message | 1359| -------- | ---------------------------------------- | 1360| 201 | Permission denied. | 1361| 202 | Not system application to call the interface. | 1362| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1363| 801 | Capability not supported. | 1364| 1600001 | Internal error. | 1365| 1600002 | Marshalling or unmarshalling error. | 1366| 1600003 | Failed to connect to the service. | 1367| 17700001 | The specified bundle name was not found. | 1368 1369**Example** 1370 1371```ts 1372import { BusinessError } from '@kit.BasicServicesKit'; 1373 1374let getSlotNumByBundleCallback = (err: BusinessError, data: number): void => { 1375 if (err) { 1376 console.error(`getSlotNumByBundle failed, code is ${err.code}, message is ${err.message}`); 1377 } else { 1378 console.info(`getSlotNumByBundle success data is ${JSON.stringify(data)}`); 1379 } 1380} 1381 1382let bundle: notificationManager.BundleOption = { 1383 bundle: "bundleName1", 1384}; 1385 1386notificationManager.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); 1387``` 1388 1389## notificationManager.getSlotNumByBundle 1390 1391getSlotNumByBundle(bundle: BundleOption): Promise\<number\> 1392 1393Obtains the number of notification slots of a specified application. This API uses a promise to return the result. 1394 1395This API is not supported on wearables. 1396 1397**System capability**: SystemCapability.Notification.Notification 1398 1399**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1400 1401**System API**: This is a system API. 1402 1403**Parameters** 1404 1405| Name | Type | Mandatory| Description | 1406| ------ | ------------ | ---- | ---------- | 1407| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 1408 1409**Return value** 1410 1411| Type | Description | 1412| ----------------------------------------------------------- | ------------------------------------------------------------ | 1413| Promise\<number\> | Promise used to return the result.| 1414 1415**Error codes** 1416 1417For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1418 1419| ID| Error Message | 1420| -------- | ---------------------------------------- | 1421| 201 | Permission denied. | 1422| 202 | Not system application to call the interface. | 1423| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1424| 801 | Capability not supported. | 1425| 1600001 | Internal error. | 1426| 1600002 | Marshalling or unmarshalling error. | 1427| 1600003 | Failed to connect to the service. | 1428| 17700001 | The specified bundle name was not found. | 1429 1430**Example** 1431 1432```ts 1433import { BusinessError } from '@kit.BasicServicesKit'; 1434 1435let bundle: notificationManager.BundleOption = { 1436 bundle: "bundleName1", 1437}; 1438 1439notificationManager.getSlotNumByBundle(bundle).then((data: number) => { 1440 console.info(`getSlotNumByBundle success, data: ${JSON.stringify(data)}`); 1441}).catch((err: BusinessError) => { 1442 console.error(`getSlotNumByBundle failed, code is ${err.code}, message is ${err.message}`); 1443}); 1444``` 1445 1446 1447## notificationManager.getAllActiveNotifications 1448 1449getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void 1450 1451Obtains all active notifications. This API uses an asynchronous callback to return the result. 1452 1453**System capability**: SystemCapability.Notification.Notification 1454 1455**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1456 1457**System API**: This is a system API. 1458 1459**Parameters** 1460 1461| Name | Type | Mandatory| Description | 1462| -------- | ------------------------------------------------------------ | ---- | -------------------- | 1463| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest)>> | Yes | Callback used to return the result.| 1464 1465**Error codes** 1466 1467For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1468 1469| ID| Error Message | 1470| -------- | ----------------------------------- | 1471| 201 | Permission denied. | 1472| 202 | Not system application to call the interface. | 1473| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1474| 1600001 | Internal error. | 1475| 1600002 | Marshalling or unmarshalling error. | 1476| 1600003 | Failed to connect to the service. | 1477 1478**Example** 1479 1480```ts 1481import { BusinessError } from '@kit.BasicServicesKit'; 1482 1483let getAllActiveNotificationsCallback = (err: BusinessError, data: Array<notificationManager.NotificationRequest>): void => { 1484 if (err) { 1485 console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`); 1486 } else { 1487 console.info(`getAllActiveNotifications success, data is ${JSON.stringify(data)}`); 1488 } 1489} 1490 1491notificationManager.getAllActiveNotifications(getAllActiveNotificationsCallback); 1492``` 1493 1494## notificationManager.getAllActiveNotifications 1495 1496getAllActiveNotifications(): Promise\<Array\<NotificationRequest\>\> 1497 1498Obtains all active notifications. This API uses a promise to return the result. 1499 1500**System capability**: SystemCapability.Notification.Notification 1501 1502**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1503 1504**System API**: This is a system API. 1505 1506**Return value** 1507 1508| Type | Description | 1509| ----------------------------------------------------------- | ------------------------------------------------------------ | 1510| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest)\>\> | Promise used to return the result.| 1511 1512**Error codes** 1513 1514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1515 1516| ID| Error Message | 1517| -------- | ----------------------------------- | 1518| 201 | Permission denied. | 1519| 202 | Not system application to call the interface. | 1520| 1600001 | Internal error. | 1521| 1600002 | Marshalling or unmarshalling error. | 1522| 1600003 | Failed to connect to the service. | 1523 1524**Example** 1525 1526```ts 1527import { BusinessError } from '@kit.BasicServicesKit'; 1528 1529notificationManager.getAllActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => { 1530 console.info(`getAllActiveNotifications success, data: ${JSON.stringify(data)}`); 1531}).catch((err: BusinessError) => { 1532 console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`); 1533}); 1534``` 1535 1536## notificationManager.getActiveNotificationByFilter<sup>11+</sup> 1537 1538getActiveNotificationByFilter(filter: NotificationFilter, callback: AsyncCallback\<NotificationRequest\>): void 1539 1540Obtains information about the common live view that matches the specified filter criteria. This API uses an asynchronous callback to return the result. 1541 1542**System capability**: SystemCapability.Notification.Notification 1543 1544**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1545 1546**System API**: This is a system API. 1547 1548 1549**Parameters** 1550 1551| Name | Type | Mandatory| Description | 1552| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 1553| filter | [NotificationFilter](js-apis-inner-notification-notificationRequest-sys.md#notificationfilter11) | Yes | Filter criteria for querying the common live view.| 1554| callback | AsyncCallback\<[NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest)> | Yes | Callback used to return the result.| 1555 1556**Error codes** 1557 1558For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1559 1560| ID| Error Message | 1561| -------- | ---------------------------------------- | 1562| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1563| 1600007 | The notification does not exist. | 1564| 17700001 | The specified bundle name was not found. | 1565 1566**Example** 1567 1568```ts 1569import { BusinessError } from '@kit.BasicServicesKit'; 1570import { notificationSubscribe } from '@kit.NotificationKit'; 1571 1572let bundleOption: notificationManager.BundleOption = { 1573 bundle: "bundleName1", 1574}; 1575let notificationKey: notificationSubscribe.NotificationKey = { 1576 id: 11, 1577 label: "" 1578}; 1579let filter: notificationManager.NotificationFilter = { 1580 bundle: bundleOption, 1581 notificationKey: notificationKey, 1582 extraInfoKeys: ['event'] 1583} 1584let getActiveNotificationByFilterCallback = (err: BusinessError, data: notificationManager.NotificationRequest): void => { 1585 if (err) { 1586 console.error(`getActiveNotificationByFilter failed, code is ${err.code}, message is ${err.message}`); 1587 } else { 1588 console.info("getActiveNotificationByFilter success"); 1589 } 1590} 1591notificationManager.getActiveNotificationByFilter(filter, getActiveNotificationByFilterCallback); 1592``` 1593 1594## notificationManager.getActiveNotificationByFilter<sup>11+</sup> 1595 1596getActiveNotificationByFilter(filter: NotificationFilter): Promise\<NotificationRequest\> 1597 1598Obtains information about the common live view that matches the specified filter criteria. This API uses a promise to return the result. 1599 1600**System capability**: SystemCapability.Notification.Notification 1601 1602**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1603 1604**System API**: This is a system API. 1605 1606 1607**Parameters** 1608 1609| Name | Type | Mandatory| Description | 1610| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 1611| filter | [NotificationFilter](js-apis-inner-notification-notificationRequest-sys.md#notificationfilter11) | Yes | Filter criteria for querying the common live view.| 1612 1613**Return value** 1614 1615| Type | Description | 1616| ------------------------------------------------------------ | --------------------------------------- | 1617| Promise\<[NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest)\> | Promise used to return the result.| 1618 1619**Error codes** 1620 1621For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1622 1623| ID| Error Message | 1624| -------- | ---------------------------------------- | 1625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1626| 1600007 | The notification does not exist. | 1627| 17700001 | The specified bundle name was not found. | 1628 1629**Example** 1630 1631```ts 1632import { BusinessError } from '@kit.BasicServicesKit'; 1633import { notificationSubscribe } from '@kit.NotificationKit'; 1634 1635let bundleOption: notificationManager.BundleOption = { 1636 bundle: "bundleName1", 1637}; 1638let notificationKey: notificationSubscribe.NotificationKey = { 1639 id: 11, 1640 label: "" 1641}; 1642let filter: notificationManager.NotificationFilter = { 1643 bundle: bundleOption, 1644 notificationKey: notificationKey, 1645 extraInfoKeys: ['event'] 1646} 1647notificationManager.getActiveNotificationByFilter(filter).then((data: notificationManager.NotificationRequest) => { 1648 console.info(`getActiveNotificationByFilter success, data: ${JSON.stringify(data)}`); 1649}).catch((err: BusinessError) => { 1650 console.error(`getActiveNotificationByFilter failed, code is ${err.code}, message is ${err.message}`); 1651}); 1652``` 1653 1654## notificationManager.removeGroupByBundle 1655 1656removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void 1657 1658Removes notifications under a notification group of the specified application. This API uses an asynchronous callback to return the result. 1659 1660**System capability**: SystemCapability.Notification.Notification 1661 1662**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1663 1664**System API**: This is a system API. 1665 1666**Parameters** 1667 1668| Name | Type | Mandatory| Description | 1669| --------- | --------------------- | ---- | ---------------------------- | 1670| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 1671| groupName | string | Yes | Name of the notification group. | 1672| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1673 1674**Error codes** 1675 1676For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1677 1678| ID| Error Message | 1679| -------- | ---------------------------------------- | 1680| 201 | Permission denied. | 1681| 202 | Not system application to call the interface. | 1682| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1683| 1600001 | Internal error. | 1684| 1600002 | Marshalling or unmarshalling error. | 1685| 1600003 | Failed to connect to the service. | 1686| 17700001 | The specified bundle name was not found. | 1687 1688**Example** 1689 1690```ts 1691import { BusinessError } from '@kit.BasicServicesKit'; 1692 1693let removeGroupByBundleCallback = (err: BusinessError): void => { 1694 if (err) { 1695 console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); 1696 } else { 1697 console.info("removeGroupByBundle success"); 1698 } 1699} 1700 1701let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" }; 1702let groupName: string = "GroupName"; 1703 1704notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); 1705``` 1706 1707## notificationManager.removeGroupByBundle 1708 1709removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\> 1710 1711Removes notifications under a notification group of the specified application. This API uses a promise to return the result. 1712 1713**System capability**: SystemCapability.Notification.Notification 1714 1715**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1716 1717**System API**: This is a system API. 1718 1719**Parameters** 1720 1721| Name | Type | Mandatory| Description | 1722| --------- | ------------ | ---- | -------------- | 1723| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 1724| groupName | string | Yes | Name of the notification group.| 1725 1726**Return value** 1727 1728| Type | Description | 1729|---------|-----------| 1730| Promise\<void\> | Promise that returns no value.| 1731 1732**Error codes** 1733 1734For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 1735 1736| ID| Error Message | 1737| -------- | ---------------------------------------- | 1738| 201 | Permission denied. | 1739| 202 | Not system application to call the interface. | 1740| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1741| 1600001 | Internal error. | 1742| 1600002 | Marshalling or unmarshalling error. | 1743| 1600003 | Failed to connect to the service. | 1744| 17700001 | The specified bundle name was not found. | 1745 1746**Example** 1747 1748```ts 1749import { BusinessError } from '@kit.BasicServicesKit'; 1750 1751let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" }; 1752let groupName: string = "GroupName"; 1753 1754notificationManager.removeGroupByBundle(bundleOption, groupName).then(() => { 1755 console.info("removeGroupByBundle success"); 1756}).catch((err: BusinessError) => { 1757 console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); 1758}); 1759``` 1760 1761## notificationManager.setDoNotDisturbDate 1762 1763setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void 1764 1765Sets the DND time. This API uses an asynchronous callback to return the result. 1766 1767This API is not supported on TVs and wearables. 1768 1769**System capability**: SystemCapability.Notification.Notification 1770 1771**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1772 1773**System API**: This is a system API. 1774 1775**Parameters** 1776 1777| Name | Type | Mandatory| Description | 1778| -------- | --------------------- | ---- | ---------------------- | 1779| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | 1780| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1781 1782**Error codes** 1783 1784For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1785 1786| ID| Error Message | 1787| -------- | ----------------------------------- | 1788| 201 | Permission denied. | 1789| 202 | Not system application to call the interface. | 1790| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1791| 801 | Capability not supported. | 1792| 1600001 | Internal error. | 1793| 1600002 | Marshalling or unmarshalling error. | 1794| 1600003 | Failed to connect to the service. | 1795| 1600012 | No memory space. | 1796 1797**Example** 1798 1799```ts 1800import { BusinessError } from '@kit.BasicServicesKit'; 1801 1802let setDoNotDisturbDateCallback = (err: BusinessError): void => { 1803 if (err) { 1804 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 1805 } else { 1806 console.info("setDoNotDisturbDate success"); 1807 } 1808} 1809 1810let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 1811 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 1812 begin: new Date(), 1813 end: new Date(2021, 11, 15, 18, 0) 1814}; 1815 1816notificationManager.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); 1817``` 1818 1819## notificationManager.setDoNotDisturbDate 1820 1821setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\> 1822 1823Sets the DND time. This API uses a promise to return the result. 1824 1825This API is not supported on TVs and wearables. 1826 1827**System capability**: SystemCapability.Notification.Notification 1828 1829**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1830 1831**System API**: This is a system API. 1832 1833**Parameters** 1834 1835| Name| Type | Mandatory| Description | 1836| ---- | ---------------- | ---- | -------------- | 1837| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| 1838 1839 1840**Return value** 1841 1842| Type | Description | 1843|---------|-----------| 1844| Promise\<void\> | Promise that returns no value.| 1845 1846**Error codes** 1847 1848For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1849 1850| ID| Error Message | 1851| -------- | ----------------------------------- | 1852| 201 | Permission denied. | 1853| 202 | Not system application to call the interface. | 1854| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1855| 801 | Capability not supported. | 1856| 1600001 | Internal error. | 1857| 1600002 | Marshalling or unmarshalling error. | 1858| 1600003 | Failed to connect to the service. | 1859| 1600012 | No memory space. | 1860 1861**Example** 1862 1863```ts 1864import { BusinessError } from '@kit.BasicServicesKit'; 1865 1866let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 1867 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 1868 begin: new Date(), 1869 end: new Date(2021, 11, 15, 18, 0) 1870}; 1871notificationManager.setDoNotDisturbDate(doNotDisturbDate).then(() => { 1872 console.info("setDoNotDisturbDate success"); 1873}).catch((err: BusinessError) => { 1874 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 1875}); 1876``` 1877 1878 1879## notificationManager.setDoNotDisturbDate 1880 1881setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): void 1882 1883Sets the DND time for a specified user. This API uses an asynchronous callback to return the result. 1884 1885This API is not supported on TVs and wearables. 1886 1887**System capability**: SystemCapability.Notification.Notification 1888 1889**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1890 1891**System API**: This is a system API. 1892 1893**Parameters** 1894 1895| Name | Type | Mandatory| Description | 1896| -------- | --------------------- | ---- | ---------------------- | 1897| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | 1898| userId | number | Yes | ID of the user for whom you want to set the DND time.| 1899| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1900 1901**Error codes** 1902 1903For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1904 1905| ID| Error Message | 1906| -------- | ----------------------------------- | 1907| 201 | Permission denied. | 1908| 202 | Not system application to call the interface. | 1909| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1910| 801 | Capability not supported. | 1911| 1600001 | Internal error. | 1912| 1600002 | Marshalling or unmarshalling error. | 1913| 1600003 | Failed to connect to the service. | 1914| 1600008 | The user does not exist. | 1915| 1600012 | No memory space. | 1916 1917**Example** 1918 1919```ts 1920import { BusinessError } from '@kit.BasicServicesKit'; 1921 1922let setDoNotDisturbDateCallback = (err: BusinessError): void => { 1923 if (err) { 1924 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 1925 } else { 1926 console.info("setDoNotDisturbDate success"); 1927 } 1928} 1929 1930let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 1931 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 1932 begin: new Date(), 1933 end: new Date(2021, 11, 15, 18, 0) 1934}; 1935 1936// Use the actual user ID when calling the API. 1937let userId: number = 1; 1938 1939notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); 1940``` 1941 1942## notificationManager.setDoNotDisturbDate 1943 1944setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\> 1945 1946Sets the DND time for a specified user. This API uses a promise to return the result. 1947 1948This API is not supported on TVs and wearables. 1949 1950**System capability**: SystemCapability.Notification.Notification 1951 1952**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 1953 1954**System API**: This is a system API. 1955 1956**Parameters** 1957 1958| Name | Type | Mandatory| Description | 1959| ------ | ---------------- | ---- | -------------- | 1960| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| 1961| userId | number | Yes | ID of the user for whom you want to set the DND time.| 1962 1963**Return value** 1964 1965| Type | Description | 1966|---------|-----------| 1967| Promise\<void\> | Promise that returns no value.| 1968 1969**Error codes** 1970 1971For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 1972 1973| ID| Error Message | 1974| -------- | ----------------------------------- | 1975| 201 | Permission denied. | 1976| 202 | Not system application to call the interface. | 1977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1978| 801 | Capability not supported. | 1979| 1600001 | Internal error. | 1980| 1600002 | Marshalling or unmarshalling error. | 1981| 1600003 | Failed to connect to the service. | 1982| 1600008 | The user does not exist. | 1983| 1600012 | No memory space. | 1984 1985**Example** 1986 1987```ts 1988import { BusinessError } from '@kit.BasicServicesKit'; 1989 1990let doNotDisturbDate: notificationManager.DoNotDisturbDate = { 1991 type: notificationManager.DoNotDisturbType.TYPE_ONCE, 1992 begin: new Date(), 1993 end: new Date(2021, 11, 15, 18, 0) 1994}; 1995 1996// Use the actual user ID when calling the API. 1997let userId: number = 1; 1998 1999notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { 2000 console.info("setDoNotDisturbDate success"); 2001}).catch((err: BusinessError) => { 2002 console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2003}); 2004``` 2005 2006 2007## notificationManager.getDoNotDisturbDate 2008 2009getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void 2010 2011Obtains the DND time. This API uses an asynchronous callback to return the result. 2012 2013This API is not supported on TVs and wearables. 2014 2015**System capability**: SystemCapability.Notification.Notification 2016 2017**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2018 2019**System API**: This is a system API. 2020 2021**Parameters** 2022 2023| Name | Type | Mandatory| Description | 2024| -------- | --------------------------------- | ---- | ---------------------- | 2025| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| 2026 2027**Error codes** 2028 2029For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2030 2031| ID| Error Message | 2032| -------- | ----------------------------------- | 2033| 201 | Permission denied. | 2034| 202 | Not system application to call the interface. | 2035| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2036| 801 | Capability not supported. | 2037| 1600001 | Internal error. | 2038| 1600002 | Marshalling or unmarshalling error. | 2039| 1600003 | Failed to connect to the service. | 2040| 1600012 | No memory space. | 2041 2042**Example** 2043 2044```ts 2045import { BusinessError } from '@kit.BasicServicesKit'; 2046 2047let getDoNotDisturbDateCallback = (err: BusinessError, data: notificationManager.DoNotDisturbDate): void => { 2048 if (err) { 2049 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2050 } else { 2051 console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`); 2052 } 2053} 2054 2055notificationManager.getDoNotDisturbDate(getDoNotDisturbDateCallback); 2056``` 2057 2058## notificationManager.getDoNotDisturbDate 2059 2060getDoNotDisturbDate(): Promise\<DoNotDisturbDate\> 2061 2062Obtains the DND time. This API uses a promise to return the result. 2063 2064This API is not supported on TVs and wearables. 2065 2066**System capability**: SystemCapability.Notification.Notification 2067 2068**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2069 2070**System API**: This is a system API. 2071 2072**Return value** 2073 2074| Type | Description | 2075| ------------------------------------------------ | ----------------------------------------- | 2076| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| 2077 2078**Error codes** 2079 2080For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2081 2082| ID| Error Message | 2083| -------- | ----------------------------------- | 2084| 201 | Permission denied. | 2085| 202 | Not system application to call the interface. | 2086| 801 | Capability not supported. | 2087| 1600001 | Internal error. | 2088| 1600002 | Marshalling or unmarshalling error. | 2089| 1600003 | Failed to connect to the service. | 2090| 1600012 | No memory space. | 2091 2092**Example** 2093 2094```ts 2095import { BusinessError } from '@kit.BasicServicesKit'; 2096 2097notificationManager.getDoNotDisturbDate().then((data: notificationManager.DoNotDisturbDate) => { 2098 console.info(`getDoNotDisturbDate success, data: ${JSON.stringify(data)}`); 2099}).catch((err: BusinessError) => { 2100 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2101}); 2102``` 2103 2104 2105## notificationManager.getDoNotDisturbDate 2106 2107getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): void 2108 2109Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result. 2110 2111This API is not supported on TVs and wearables. 2112 2113**System capability**: SystemCapability.Notification.Notification 2114 2115**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2116 2117**System API**: This is a system API. 2118 2119**Parameters** 2120 2121| Name | Type | Mandatory| Description | 2122| -------- | --------------------------------- | ---- | ---------------------- | 2123| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| 2124| userId | number | Yes | User ID.| 2125 2126**Error codes** 2127 2128For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2129 2130| ID| Error Message | 2131| -------- | ----------------------------------- | 2132| 201 | Permission denied. | 2133| 202 | Not system application to call the interface. | 2134| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2135| 801 | Capability not supported. | 2136| 1600001 | Internal error. | 2137| 1600002 | Marshalling or unmarshalling error. | 2138| 1600003 | Failed to connect to the service. | 2139| 1600008 | The user does not exist. | 2140| 1600012 | No memory space. | 2141 2142**Example** 2143 2144```ts 2145import { BusinessError } from '@kit.BasicServicesKit'; 2146 2147let getDoNotDisturbDateCallback = (err: BusinessError, data: notificationManager.DoNotDisturbDate): void => { 2148 if (err) { 2149 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2150 } else { 2151 console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`); 2152 } 2153} 2154 2155// Use the actual user ID when calling the API. 2156let userId: number = 1; 2157 2158notificationManager.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); 2159``` 2160 2161## notificationManager.getDoNotDisturbDate 2162 2163getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\> 2164 2165Obtains the DND time of a specified user. This API uses a promise to return the result. 2166 2167This API is not supported on TVs and wearables. 2168 2169**System capability**: SystemCapability.Notification.Notification 2170 2171**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2172 2173**System API**: This is a system API. 2174 2175**Parameters** 2176 2177| Name | Type | Mandatory| Description | 2178| -------- | --------------------------------- | ---- | ---------------------- | 2179| userId | number | Yes | User ID.| 2180 2181**Return value** 2182 2183| Type | Description | 2184| ------------------------------------------------ | ----------------------------------------- | 2185| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| 2186 2187**Error codes** 2188 2189For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2190 2191| ID| Error Message | 2192| -------- | ----------------------------------- | 2193| 201 | Permission denied. | 2194| 202 | Not system application to call the interface. | 2195| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2196| 801 | Capability not supported. | 2197| 1600001 | Internal error. | 2198| 1600002 | Marshalling or unmarshalling error. | 2199| 1600003 | Failed to connect to the service. | 2200| 1600008 | The user does not exist. | 2201| 1600012 | No memory space. | 2202 2203**Example** 2204 2205```ts 2206import { BusinessError } from '@kit.BasicServicesKit'; 2207 2208// Use the actual user ID when calling the API. 2209let userId: number = 1; 2210 2211notificationManager.getDoNotDisturbDate(userId).then((data: notificationManager.DoNotDisturbDate) => { 2212 console.info(`getDoNotDisturbDate success, data: ${JSON.stringify(data)}`); 2213}).catch((err: BusinessError) => { 2214 console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`); 2215}); 2216``` 2217 2218 2219## notificationManager.isSupportDoNotDisturbMode 2220 2221 isSupportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void 2222 2223Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. 2224 2225This API is not supported on TVs and wearables. 2226 2227**System capability**: SystemCapability.Notification.Notification 2228 2229**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2230 2231**System API**: This is a system API. 2232 2233**Parameters** 2234 2235| Name | Type | Mandatory| Description | 2236| -------- | ------------------------ | ---- | -------------------------------- | 2237| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that DND mode is supported, and **false** means the opposite.| 2238 2239**Error codes** 2240 2241For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2242 2243| ID| Error Message | 2244| -------- | ----------------------------------- | 2245| 201 | Permission denied. | 2246| 202 | Not system application to call the interface. | 2247| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2248| 801 | Capability not supported. | 2249| 1600001 | Internal error. | 2250| 1600002 | Marshalling or unmarshalling error. | 2251| 1600003 | Failed to connect to the service. | 2252 2253**Example** 2254 2255```ts 2256import { BusinessError } from '@kit.BasicServicesKit'; 2257 2258let isSupportDoNotDisturbModeCallback = (err: BusinessError, data: boolean): void => { 2259 if (err) { 2260 console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`); 2261 } else { 2262 console.info(`isSupportDoNotDisturbMode success, data: ${JSON.stringify(data)}`); 2263 } 2264} 2265 2266notificationManager.isSupportDoNotDisturbMode(isSupportDoNotDisturbModeCallback); 2267``` 2268 2269## notificationManager.isSupportDoNotDisturbMode 2270 2271isSupportDoNotDisturbMode(): Promise\<boolean\> 2272 2273Checks whether DND mode is supported. This API uses a promise to return the result. 2274 2275This API is not supported on TVs and wearables. 2276 2277**System capability**: SystemCapability.Notification.Notification 2278 2279**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2280 2281**System API**: This is a system API. 2282 2283**Return value** 2284 2285| Type | Description | 2286| ----------------------------------------------------------- | ------------------------------------------------------------ | 2287| Promise\<boolean\> | Promise used to return the result. The value **true** means that DND mode is supported, and **false** means the opposite.| 2288 2289**Error codes** 2290 2291For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2292 2293| ID| Error Message | 2294| -------- | ----------------------------------- | 2295| 201 | Permission denied. | 2296| 202 | Not system application to call the interface. | 2297| 801 | Capability not supported. | 2298| 1600001 | Internal error. | 2299| 1600002 | Marshalling or unmarshalling error. | 2300| 1600003 | Failed to connect to the service. | 2301 2302**Example** 2303 2304```ts 2305import { BusinessError } from '@kit.BasicServicesKit'; 2306 2307notificationManager.isSupportDoNotDisturbMode().then((data: boolean) => { 2308 console.info(`isSupportDoNotDisturbMode success, data: ${JSON.stringify(data)}`); 2309}).catch((err: BusinessError) => { 2310 console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`); 2311}); 2312``` 2313 2314## notificationManager.setDistributedEnable 2315 2316setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void 2317 2318Sets whether to enable distributed notification on this device. This API uses an asynchronous callback to return the result. 2319 2320This API is not supported on TVs and wearables. 2321 2322**System capability**: SystemCapability.Notification.Notification 2323 2324**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2325 2326**System API**: This is a system API. 2327 2328**Parameters** 2329 2330| Name | Type | Mandatory| Description | 2331| -------- | ------------------------ | ---- | -------------------------- | 2332| enable | boolean | Yes | Whether to enable distributed notification. The value **true** means to enable distributed notification, and **false** means the opposite.| 2333| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2334 2335**Error codes** 2336 2337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2338 2339| ID| Error Message | 2340| -------- | ----------------------------------- | 2341| 201 | Permission denied. | 2342| 202 | Not system application to call the interface. | 2343| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2344| 801 | Capability not supported. | 2345| 1600001 | Internal error. | 2346| 1600002 | Marshalling or unmarshalling error. | 2347| 1600003 | Failed to connect to the service. | 2348| 1600010 | Distributed operation failed. | 2349 2350**Example** 2351 2352```ts 2353import { BusinessError } from '@kit.BasicServicesKit'; 2354 2355let setDistributedEnableCallback = (err: BusinessError): void => { 2356 if (err) { 2357 console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`); 2358 } else { 2359 console.info("setDistributedEnable success"); 2360 } 2361}; 2362let enable: boolean = true; 2363notificationManager.setDistributedEnable(enable, setDistributedEnableCallback); 2364``` 2365 2366## notificationManager.setDistributedEnable 2367 2368setDistributedEnable(enable: boolean): Promise\<void> 2369 2370Sets whether to enable distributed notification on this device. This API uses a promise to return the result. 2371 2372This API is not supported on TVs and wearables. 2373 2374**System capability**: SystemCapability.Notification.Notification 2375 2376**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2377 2378**System API**: This is a system API. 2379 2380**Parameters** 2381 2382| Name | Type | Mandatory| Description | 2383| -------- | ------------------------ | ---- | -------------------------- | 2384| enable | boolean | Yes | Whether to enable distributed notification. The value **true** means to enable distributed notification, and **false** means the opposite.| 2385 2386**Return value** 2387 2388| Type | Description | 2389|-----------------|-----------| 2390| Promise\<void\> | Promise that returns no value.| 2391 2392**Error codes** 2393 2394For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2395 2396| ID| Error Message | 2397| -------- | ----------------------------------- | 2398| 201 | Permission denied. | 2399| 202 | Not system application to call the interface. | 2400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2401| 801 | Capability not supported. | 2402| 1600001 | Internal error. | 2403| 1600002 | Marshalling or unmarshalling error. | 2404| 1600003 | Failed to connect to the service. | 2405| 1600010 | Distributed operation failed. | 2406 2407**Example** 2408 2409```ts 2410import { BusinessError } from '@kit.BasicServicesKit'; 2411 2412let enable: boolean = true; 2413notificationManager.setDistributedEnable(enable).then(() => { 2414 console.info("setDistributedEnable success"); 2415}).catch((err: BusinessError) => { 2416 console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`); 2417}); 2418``` 2419 2420## notificationManager.setDistributedEnableByBundle 2421 2422setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void 2423 2424Sets whether to enable distributed notification for a specified application. This API uses an asynchronous callback to return the result. 2425 2426This API is not supported on TVs and wearables. 2427 2428**System capability**: SystemCapability.Notification.Notification 2429 2430**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2431 2432**System API**: This is a system API. 2433 2434**Parameters** 2435 2436| Name | Type | Mandatory| Description | 2437| -------- | ------------------------ | ---- | -------------------------- | 2438| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 2439| enable | boolean | Yes | Whether to enable distributed notification. The value **true** means to enable distributed notification, and **false** means the opposite.| 2440| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2441 2442**Error codes** 2443 2444For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 2445 2446| ID| Error Message | 2447| -------- | ---------------------------------------- | 2448| 201 | Permission denied. | 2449| 202 | Not system application to call the interface. | 2450| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2451| 801 | Capability not supported. | 2452| 1600001 | Internal error. | 2453| 1600002 | Marshalling or unmarshalling error. | 2454| 1600003 | Failed to connect to the service. | 2455| 1600010 | Distributed operation failed. | 2456| 17700001 | The specified bundle name was not found. | 2457 2458**Example** 2459 2460```ts 2461import { BusinessError } from '@kit.BasicServicesKit'; 2462 2463let setDistributedEnableByBundleCallback = (err: BusinessError): void => { 2464 if (err) { 2465 console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`); 2466 } else { 2467 console.info("setDistributedEnableByBundle success"); 2468 } 2469}; 2470let bundle: notificationManager.BundleOption = { 2471 bundle: "bundleName1", 2472}; 2473let enable: boolean = true; 2474notificationManager.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback); 2475``` 2476 2477 2478 2479## notificationManager.setDistributedEnableByBundle 2480 2481setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<void> 2482 2483Sets whether to enable distributed notification for a specified application. This API uses a promise to return the result. 2484 2485This API is not supported on TVs and wearables. 2486 2487**System capability**: SystemCapability.Notification.Notification 2488 2489**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2490 2491**System API**: This is a system API. 2492 2493**Parameters** 2494 2495| Name | Type | Mandatory| Description | 2496| -------- | ------------------------ | ---- | -------------------------- | 2497| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 2498| enable | boolean | Yes | Whether to enable distributed notification. The value **true** means to enable distributed notification, and **false** means the opposite. | 2499 2500**Return value** 2501 2502| Type | Description | 2503|-----------------|-----------| 2504| Promise\<void\> | Promise that returns no value.| 2505 2506**Error codes** 2507 2508For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 2509 2510| ID| Error Message | 2511| -------- | ---------------------------------------- | 2512| 201 | Permission denied. | 2513| 202 | Not system application to call the interface. | 2514| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2515| 801 | Capability not supported. | 2516| 1600001 | Internal error. | 2517| 1600002 | Marshalling or unmarshalling error. | 2518| 1600003 | Failed to connect to the service. | 2519| 1600010 | Distributed operation failed. | 2520| 17700001 | The specified bundle name was not found. | 2521 2522**Example** 2523 2524```ts 2525import { BusinessError } from '@kit.BasicServicesKit'; 2526 2527let bundle: notificationManager.BundleOption = { 2528 bundle: "bundleName1", 2529}; 2530let enable: boolean = true; 2531notificationManager.setDistributedEnableByBundle(bundle, enable).then(() => { 2532 console.info("setDistributedEnableByBundle success"); 2533}).catch((err: BusinessError) => { 2534 console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`); 2535}); 2536``` 2537 2538## notificationManager.isDistributedEnabledByBundle 2539 2540isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void 2541 2542Checks whether distributed notification is enabled for a specified application. This API uses an asynchronous callback to return the result. 2543 2544This API is not supported on TVs and wearables. 2545 2546**System capability**: SystemCapability.Notification.Notification 2547 2548**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2549 2550**System API**: This is a system API. 2551 2552**Parameters** 2553 2554| Name | Type | Mandatory| Description | 2555| -------- | ------------------------ | ---- | -------------------------- | 2556| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 2557| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that distributed notification is enabled, and **false** means the opposite.| 2558 2559**Error codes** 2560 2561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 2562 2563| ID| Error Message | 2564| -------- | ---------------------------------------- | 2565| 201 | Permission denied. | 2566| 202 | Not system application to call the interface. | 2567| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2568| 801 | Capability not supported. | 2569| 1600001 | Internal error. | 2570| 1600002 | Marshalling or unmarshalling error. | 2571| 1600003 | Failed to connect to the service. | 2572| 1600010 | Distributed operation failed. | 2573| 17700001 | The specified bundle name was not found. | 2574 2575**Example** 2576 2577```ts 2578import { BusinessError } from '@kit.BasicServicesKit'; 2579 2580let isDistributedEnabledByBundleCallback = (err: BusinessError, data: boolean): void => { 2581 if (err) { 2582 console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`); 2583 } else { 2584 console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`); 2585 } 2586}; 2587let bundle: notificationManager.BundleOption = { 2588 bundle: "bundleName1", 2589}; 2590notificationManager.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback); 2591``` 2592 2593## notificationManager.isDistributedEnabledByBundle 2594 2595isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean> 2596 2597Checks whether distributed notification is enabled for a specified application. This API uses a promise to return the result. 2598 2599This API is not supported on TVs and wearables. 2600 2601**System capability**: SystemCapability.Notification.Notification 2602 2603**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2604 2605**System API**: This is a system API. 2606 2607**Parameters** 2608 2609| Name | Type | Mandatory| Description | 2610| -------- | ------------------------ | ---- | -------------------------- | 2611| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle of the application. | 2612 2613**Return value** 2614 2615| Type | Description | 2616| ------------------ | ------------------------------------------------- | 2617| Promise\<boolean\> | Promise used to return the result. The value **true** means that distributed notification is enabled, and **false** means the opposite.| 2618 2619**Error codes** 2620 2621For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 2622 2623| ID| Error Message | 2624| -------- | ---------------------------------------- | 2625| 201 | Permission denied. | 2626| 202 | Not system application to call the interface. | 2627| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2628| 801 | Capability not supported. | 2629| 1600001 | Internal error. | 2630| 1600002 | Marshalling or unmarshalling error. | 2631| 1600003 | Failed to connect to the service. | 2632| 1600010 | Distributed operation failed. | 2633| 17700001 | The specified bundle name was not found. | 2634 2635**Example** 2636 2637```ts 2638import { BusinessError } from '@kit.BasicServicesKit'; 2639 2640let bundle: notificationManager.BundleOption = { 2641 bundle: "bundleName1", 2642}; 2643notificationManager.isDistributedEnabledByBundle(bundle).then((data: boolean) => { 2644 console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`); 2645}).catch((err: BusinessError) => { 2646 console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`); 2647}); 2648``` 2649 2650 2651## notificationManager.getDeviceRemindType 2652 2653getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void 2654 2655Obtains the notification reminder type. This API uses an asynchronous callback to return the result. 2656 2657This API is not supported on TVs and wearables. 2658 2659**System capability**: SystemCapability.Notification.Notification 2660 2661**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2662 2663**System API**: This is a system API. 2664 2665**Parameters** 2666 2667| Name | Type | Mandatory| Description | 2668| -------- | --------------------------------- | ---- | -------------------------- | 2669| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes | Callback used to return the result.| 2670 2671**Error codes** 2672 2673For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2674 2675| ID| Error Message | 2676| -------- | ----------------------------------- | 2677| 201 | Permission denied. | 2678| 202 | Not system application to call the interface. | 2679| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2680| 801 | Capability not supported. | 2681| 1600001 | Internal error. | 2682| 1600002 | Marshalling or unmarshalling error. | 2683| 1600003 | Failed to connect to the service. | 2684 2685**Example** 2686 2687```ts 2688import { BusinessError } from '@kit.BasicServicesKit'; 2689 2690let getDeviceRemindTypeCallback = (err: BusinessError, data: notificationManager.DeviceRemindType): void => { 2691 if (err) { 2692 console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`); 2693 } else { 2694 console.info(`getDeviceRemindType success, data is ${JSON.stringify(data)}`); 2695 } 2696}; 2697notificationManager.getDeviceRemindType(getDeviceRemindTypeCallback); 2698``` 2699 2700## notificationManager.getDeviceRemindType 2701 2702getDeviceRemindType(): Promise\<DeviceRemindType\> 2703 2704Obtains the notification reminder type. This API uses a promise to return the result. 2705 2706This API is not supported on TVs and wearables. 2707 2708**System capability**: SystemCapability.Notification.Notification 2709 2710**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 2711 2712**System API**: This is a system API. 2713 2714**Return value** 2715 2716| Type | Description | 2717| ------------------ | --------------- | 2718| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.| 2719 2720**Error codes** 2721 2722For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 2723 2724| ID| Error Message | 2725| -------- | ----------------------------------- | 2726| 201 | Permission denied. | 2727| 202 | Not system application to call the interface. | 2728| 801 | Capability not supported. | 2729| 1600001 | Internal error. | 2730| 1600002 | Marshalling or unmarshalling error. | 2731| 1600003 | Failed to connect to the service. | 2732 2733**Example** 2734 2735```ts 2736import { BusinessError } from '@kit.BasicServicesKit'; 2737 2738notificationManager.getDeviceRemindType().then((data: notificationManager.DeviceRemindType) => { 2739 console.info(`getDeviceRemindType success, data: ${JSON.stringify(data)}`); 2740}).catch((err: BusinessError) => { 2741 console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`); 2742}); 2743``` 2744 2745 2746## notificationManager.publishAsBundle 2747 2748publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void 2749 2750Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result. 2751 2752**System capability**: SystemCapability.Notification.Notification 2753 2754**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2755 2756**System API**: This is a system API. 2757 2758**Parameters** 2759 2760| Name | Type | Mandatory| Description | 2761| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | 2762| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 2763| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 2764| userId | number | Yes | User ID. | 2765| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 2766 2767**Error codes** 2768 2769For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [HTTP Error Codes](../apis-network-kit/errorcode-net-http.md). 2770 2771| ID| Error Message | 2772| -------- | ----------------------------------------- | 2773| 201 | Permission denied. | 2774| 202 | Not system application to call the interface. | 2775| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2776| 1600001 | Internal error. | 2777| 1600002 | Marshalling or unmarshalling error. | 2778| 1600003 | Failed to connect to the service. | 2779| 1600004 | Notification disabled. | 2780| 1600005 | Notification slot disabled. | 2781| 1600007 | The notification does not exist. | 2782| 1600008 | The user does not exist. | 2783| 1600009 | The notification sending frequency reaches the upper limit. | 2784| 1600012 | No memory space. | 2785| 1600015 | The current notification status does not support duplicate configurations. | 2786| 1600016 | The notification version for this update is too low. | 2787| 1600020 | The application is not allowed to send notifications due to permission settings. | 2788| 2300007 | Network unreachable. | 2789 2790**Example** 2791 2792```ts 2793import { BusinessError } from '@kit.BasicServicesKit'; 2794 2795// publishAsBundle callback 2796let callback = (err: BusinessError): void => { 2797 if (err) { 2798 console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`); 2799 } else { 2800 console.info("publishAsBundle success"); 2801 } 2802} 2803// Bundle name of the application whose notification function is taken over by the reminder agent 2804let representativeBundle: string = "com.example.demo"; 2805// Use the actual user ID when calling the API. 2806let userId: number = 100; 2807// NotificationRequest object 2808let request: notificationManager.NotificationRequest = { 2809 id: 1, 2810 content: { 2811 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2812 normal: { 2813 title: "test_title", 2814 text: "test_text", 2815 additionalText: "test_additionalText" 2816 } 2817 } 2818}; 2819notificationManager.publishAsBundle(request, representativeBundle, userId, callback); 2820``` 2821 2822## notificationManager.publishAsBundle 2823 2824publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\> 2825 2826Publishes a notification through the reminder agent. This API uses a promise to return the result. 2827 2828**System capability**: SystemCapability.Notification.Notification 2829 2830**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2831 2832**System API**: This is a system API. 2833 2834**Parameters** 2835 2836 2837| Name | Type | Mandatory| Description | 2838| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | 2839| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 2840| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 2841| userId | number | Yes | User ID. | 2842 2843**Return value** 2844 2845| Type | Description | 2846|-----------------|-----------| 2847| Promise\<void\> | Promise that returns no value.| 2848 2849**Error codes** 2850 2851For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [HTTP Error Codes](../apis-network-kit/errorcode-net-http.md). 2852 2853| ID| Error Message | 2854| -------- | ----------------------------------------- | 2855| 201 | Permission denied. | 2856| 202 | Not system application to call the interface. | 2857| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2858| 1600001 | Internal error. | 2859| 1600002 | Marshalling or unmarshalling error. | 2860| 1600003 | Failed to connect to the service. | 2861| 1600004 | Notification disabled. | 2862| 1600005 | Notification slot disabled. | 2863| 1600007 | The notification does not exist. | 2864| 1600008 | The user does not exist. | 2865| 1600009 | The notification sending frequency reaches the upper limit. | 2866| 1600012 | No memory space. | 2867| 1600015 | The current notification status does not support duplicate configurations. | 2868| 1600016 | The notification version for this update is too low. | 2869| 1600020 | The application is not allowed to send notifications due to permission settings. | 2870| 2300007 | Network unreachable. | 2871 2872**Example** 2873 2874```ts 2875import { BusinessError } from '@kit.BasicServicesKit'; 2876 2877// Bundle name of the application whose notification function is taken over by the reminder agent 2878let representativeBundle: string = "com.example.demo"; 2879// Use the actual user ID when calling the API. 2880let userId: number = 100; 2881// NotificationRequest object 2882let request: notificationManager.NotificationRequest = { 2883 id: 1, 2884 content: { 2885 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2886 normal: { 2887 title: "test_title", 2888 text: "test_text", 2889 additionalText: "test_additionalText" 2890 } 2891 } 2892}; 2893notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => { 2894 console.info("publishAsBundle success"); 2895}).catch((err: BusinessError) => { 2896 console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`); 2897}); 2898``` 2899 2900## notificationManager.publishAsBundle<sup>12+</sup> 2901 2902publishAsBundle(representativeBundle: BundleOption, request: NotificationRequest): Promise\<void\> 2903 2904Publishes a notification through the reminder agent. This API uses a promise to return the result. 2905 2906**System capability**: SystemCapability.Notification.Notification 2907 2908**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2909 2910**System API**: This is a system API. 2911 2912**Parameters** 2913 2914 2915| Name | Type | Mandatory| Description | 2916|----------------------|--------------------------------------------|------|-----------------------------------------------| 2917| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application whose notification function is taken over by the reminder agent. | 2918| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | Yes | Content and related configuration of the notification to publish.| 2919 2920**Return value** 2921 2922| Type | Description | 2923|-----------------|-----------| 2924| Promise\<void\> | Promise that returns no value.| 2925 2926**Error codes** 2927 2928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [HTTP Error Codes](../apis-network-kit/errorcode-net-http.md). 2929 2930| ID| Error Message | 2931| -------- | ----------------------------------------- | 2932| 201 | Permission denied. | 2933| 202 | Not system application to call the interface. | 2934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2935| 1600001 | Internal error. | 2936| 1600002 | Marshalling or unmarshalling error. | 2937| 1600003 | Failed to connect to the service. | 2938| 1600004 | Notification disabled. | 2939| 1600005 | Notification slot disabled. | 2940| 1600007 | The notification does not exist. | 2941| 1600008 | The user does not exist. | 2942| 1600009 | The notification sending frequency reaches the upper limit. | 2943| 1600012 | No memory space. | 2944| 1600015 | The current notification status does not support duplicate configurations. | 2945| 1600016 | The notification version for this update is too low. | 2946| 1600020 | The application is not allowed to send notifications due to permission settings. | 2947| 2300007 | Network unreachable. | 2948 2949**Example** 2950 2951```ts 2952import { BusinessError } from '@kit.BasicServicesKit'; 2953 2954// Bundle information of the application whose notification function is taken over by the reminder agent. 2955let representativeBundle: notificationManager.BundleOption = { 2956 bundle: "bundleName1", 2957}; 2958// NotificationRequest object 2959let request: notificationManager.NotificationRequest = { 2960 id: 1, 2961 content: { 2962 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2963 normal: { 2964 title: "test_title", 2965 text: "test_text", 2966 additionalText: "test_additionalText" 2967 } 2968 } 2969}; 2970notificationManager.publishAsBundle(representativeBundle, request).then(() => { 2971 console.info("publishAsBundle success"); 2972}).catch((err: BusinessError) => { 2973 console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`); 2974}); 2975``` 2976 2977## notificationManager.cancelAsBundle 2978 2979cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void 2980 2981Cancels a notification published through the reminder agent. This API uses an asynchronous callback to return the result. 2982 2983**System capability**: SystemCapability.Notification.Notification 2984 2985**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2986 2987**System API**: This is a system API. 2988 2989**Parameters** 2990 2991| Name | Type | Mandatory| Description | 2992| -------------------- | ------------- | ---- | ------------------------ | 2993| id | number | Yes | Notification ID. | 2994| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | 2995| userId | number | Yes | User ID. | 2996| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 2997 2998**Error codes** 2999 3000For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3001 3002| ID| Error Message | 3003| -------- | ----------------------------------- | 3004| 201 | Permission denied. | 3005| 202 | Not system application to call the interface. | 3006| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3007| 1600001 | Internal error. | 3008| 1600002 | Marshalling or unmarshalling error. | 3009| 1600003 | Failed to connect to the service. | 3010| 1600007 | The notification does not exist. | 3011| 1600008 | The user does not exist. | 3012| 17700001 | The specified bundle name was not found. | 3013 3014**Example** 3015 3016```ts 3017import { BusinessError } from '@kit.BasicServicesKit'; 3018 3019// cancelAsBundle 3020let cancelAsBundleCallback = (err: BusinessError): void => { 3021 if (err) { 3022 console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`); 3023 } else { 3024 console.info("cancelAsBundle success"); 3025 } 3026} 3027// Bundle name of the application whose notification function is taken over by the reminder agent 3028let representativeBundle: string = "com.example.demo"; 3029// Use the actual user ID when calling the API. 3030let userId: number = 100; 3031notificationManager.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); 3032``` 3033 3034## notificationManager.cancelAsBundle 3035 3036cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\> 3037 3038Cancels a notification published through the reminder agent. This API uses a promise to return the result. 3039 3040**System capability**: SystemCapability.Notification.Notification 3041 3042**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3043 3044**System API**: This is a system API. 3045 3046**Parameters** 3047 3048| Name | Type | Mandatory| Description | 3049| -------------------- | ------ | ---- | ------------------ | 3050| id | number | Yes | Notification ID. | 3051| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| 3052| userId | number | Yes | User ID.| 3053 3054**Return value** 3055 3056| Type | Description | 3057|-----------------|-----------| 3058| Promise\<void\> | Promise that returns no value.| 3059 3060**Error codes** 3061 3062For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3063 3064| ID| Error Message | 3065| -------- | ----------------------------------- | 3066| 201 | Permission denied. | 3067| 202 | Not system application to call the interface. | 3068| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3069| 1600001 | Internal error. | 3070| 1600002 | Marshalling or unmarshalling error. | 3071| 1600003 | Failed to connect to the service. | 3072| 1600007 | The notification does not exist. | 3073| 1600008 | The user does not exist. | 3074| 17700001 | The specified bundle name was not found. | 3075 3076**Example** 3077 3078```ts 3079import { BusinessError } from '@kit.BasicServicesKit'; 3080 3081// Bundle name of the application whose notification function is taken over by the reminder agent 3082let representativeBundle: string = "com.example.demo"; 3083// Use the actual user ID when calling the API. 3084let userId: number = 100; 3085notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => { 3086 console.info("cancelAsBundle success"); 3087}).catch((err: BusinessError) => { 3088 console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`); 3089}); 3090``` 3091 3092 3093## notificationManager.cancelAsBundle<sup>12+</sup> 3094 3095cancelAsBundle(representativeBundle: BundleOption, id: number): Promise\<void\> 3096 3097Cancels a notification published through the reminder agent. This API uses a promise to return the result. 3098 3099**System capability**: SystemCapability.Notification.Notification 3100 3101**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3102 3103**System API**: This is a system API. 3104 3105**Parameters** 3106 3107 3108| Name | Type | Mandatory| Description | 3109| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | 3110| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) |Yes | Bundle information of the application whose notification function is taken over by the reminder agent.| 3111| id | number | Yes | Notification ID. | 3112 3113**Return value** 3114 3115| Type | Description | 3116|-----------------|-----------| 3117| Promise\<void\> | Promise that returns no value.| 3118 3119**Error codes** 3120 3121For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3122 3123| ID| Error Message | 3124| -------- | ----------------------------------------- | 3125| 201 | Permission denied. | 3126| 202 | Not system application to call the interface. | 3127| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3128| 1600001 | Internal error. | 3129| 1600002 | Marshalling or unmarshalling error. | 3130| 1600003 | Failed to connect to the service. | 3131| 1600007 | The notification does not exist. | 3132| 1600008 | The user does not exist. | 3133| 1600012 | No memory space. | 3134| 17700001 | The specified bundle name was not found. | 3135 3136**Example** 3137 3138```ts 3139import { BusinessError } from '@kit.BasicServicesKit'; 3140 3141let representativeBundle: notificationManager.BundleOption = { 3142 bundle: "bundleName1", 3143}; 3144notificationManager.cancelAsBundle(representativeBundle, 1).then(() => { 3145 console.info("cancelAsBundle success"); 3146}).catch((err: BusinessError) => { 3147 console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`); 3148}); 3149``` 3150 3151## notificationManager.cancel<sup>12+</sup> 3152 3153cancel(representativeBundle: BundleOption, id: number): Promise\<void\> 3154 3155Cancels the notification of other applications of the user. This API uses a promise to return the result. 3156 3157The current application must have a proxy relationship with another application, or the **ohos.permission.NOTIFICATION_AGENT_CONTROLLER** permission is granted to the current application. 3158 3159**System capability**: SystemCapability.Notification.Notification 3160 3161**System API**: This is a system API. 3162 3163**Parameters** 3164 3165| Name | Type | Mandatory| Description | 3166| -------------------- | ------ | ---- | ------------------ | 3167| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3168| id | number | Yes | Notification ID.| 3169 3170**Return value** 3171 3172| Type | Description | 3173|-----------------|-----------| 3174| Promise\<void\> | Promise that returns no value.| 3175 3176**Error codes** 3177 3178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3179 3180| ID| Error Message | 3181| -------- | ----------------------------------- | 3182| 202 | Not system application to call the interface. | 3183| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3184| 1600001 | Internal error. | 3185| 1600002 | Marshalling or unmarshalling error. | 3186| 1600003 | Failed to connect to the service. | 3187| 1600007 | The notification does not exist. | 3188| 1600012 | No memory space. | 3189| 1600017 | There is no corresponding agent relationship configuration. | 3190 3191**Example** 3192 3193```ts 3194import { BusinessError } from '@kit.BasicServicesKit'; 3195 3196let bundle: notificationManager.BundleOption = { 3197 bundle: "bundleName" 3198}; 3199let id: number = 1; 3200notificationManager.cancel(bundle, id).then(() => { 3201 console.info("cancel success"); 3202}).catch((err: BusinessError) => { 3203 console.error(`cancel failed, code is ${err.code}, message is ${err.message}`); 3204}); 3205``` 3206 3207## notificationManager.setNotificationEnableSlot 3208 3209setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void 3210 3211Sets the enabled status of a slot type for the specified application. This API uses an asynchronous callback to return the result. 3212 3213This API is not supported on wearables. 3214 3215**System capability**: SystemCapability.Notification.Notification 3216 3217**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3218 3219**System API**: This is a system API. 3220 3221**Parameters** 3222 3223| Name | Type | Mandatory| Description | 3224| -------- | ----------------------------- | ---- | ---------------------- | 3225| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3226| type | [SlotType](./js-apis-notificationManager.md#slottype) | Yes | Notification slot type. | 3227| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 3228| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3229 3230**Error codes** 3231 3232For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3233 3234| ID| Error Message | 3235| -------- | ---------------------------------------- | 3236| 201 | Permission denied. | 3237| 202 | Not system application to call the interface. | 3238| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3239| 801 | Capability not supported. | 3240| 1600001 | Internal error. | 3241| 1600002 | Marshalling or unmarshalling error. | 3242| 1600003 | Failed to connect to the service. | 3243| 1600012 | No memory space. | 3244| 17700001 | The specified bundle name was not found. | 3245 3246**Example** 3247 3248```ts 3249import { BusinessError } from '@kit.BasicServicesKit'; 3250 3251// setNotificationEnableSlot 3252let setNotificationEnableSlotCallback = (err: BusinessError): void => { 3253 if (err) { 3254 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3255 } else { 3256 console.info("setNotificationEnableSlot success"); 3257 } 3258}; 3259notificationManager.setNotificationEnableSlot( 3260 { bundle: "ohos.samples.notification", }, 3261 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3262 true, 3263 setNotificationEnableSlotCallback); 3264``` 3265 3266## notificationManager.setNotificationEnableSlot<sup>11+</sup> 3267 3268setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl: boolean, callback: AsyncCallback\<void>): void 3269 3270Sets the enabled status of a slot type for the specified application. This API uses an asynchronous callback to return the result. 3271 3272This API is not supported on wearables. 3273 3274**System capability**: SystemCapability.Notification.Notification 3275 3276**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3277 3278**System API**: This is a system API. 3279 3280**Parameters** 3281 3282| Name | Type | Mandatory| Description | 3283| -------- | ----------------------------- | ---- | ----------------------- | 3284| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 3285| type | [SlotType](./js-apis-notificationManager.md#slottype) | Yes | Notification slot type. | 3286| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 3287| isForceControl<sup>11+</sup> | boolean | Yes | Whether the slot is affected by the notification authorization. The value **true** means the slot is affected, and **false** means the opposite.| 3288| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 3289 3290**Error codes** 3291 3292For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3293 3294| ID| Error Message | 3295| -------- | ---------------------------------------- | 3296| 201 | Permission denied. | 3297| 202 | Not system application to call the interface. | 3298| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3299| 801 | Capability not supported. | 3300| 1600001 | Internal error. | 3301| 1600002 | Marshalling or unmarshalling error. | 3302| 1600003 | Failed to connect to the service. | 3303| 1600012 | No memory space. | 3304| 17700001 | The specified bundle name was not found. | 3305 3306**Example** 3307 3308```ts 3309import { BusinessError } from '@kit.BasicServicesKit'; 3310 3311let setNotificationEnableSlotCallback = (err: BusinessError): void => { 3312 if (err) { 3313 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3314 } else { 3315 console.info("setNotificationEnableSlot success"); 3316 } 3317}; 3318 3319notificationManager.setNotificationEnableSlot( 3320 { bundle: "ohos.samples.notification", }, 3321 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3322 true, 3323 false, 3324 setNotificationEnableSlotCallback); 3325``` 3326 3327## notificationManager.setNotificationEnableSlot 3328 3329setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl?: boolean): Promise\<void> 3330 3331Sets the enabled status of a slot type for the specified application. This API uses a promise to return the result. 3332 3333This API is not supported on wearables. 3334 3335**System capability**: SystemCapability.Notification.Notification 3336 3337**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3338 3339**System API**: This is a system API. 3340 3341**Parameters** 3342 3343| Name| Type | Mandatory| Description | 3344| ------ | ----------------------------- | ---- | -------------- | 3345| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3346| type | [SlotType](./js-apis-notificationManager.md#slottype) | Yes | Notification slot type.| 3347| enable | boolean | Yes | Whether to enable the notification slot type. The value **true** means to enable the notification slot type, and **false** means the opposite. | 3348| isForceControl<sup>11+</sup> | boolean | No | Whether the enabled status of the notification slot is subject to the enabled status of notification. The value **false** means that the enabled status of the notification slot is subject to the enabled status of notification, and **true** means the opposite. Default value: **false** | 3349 3350**Return value** 3351 3352| Type | Description | 3353| ------- |------------| 3354| Promise\<void\> | Promise that returns no value.| 3355 3356**Error codes** 3357 3358For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3359 3360| ID| Error Message | 3361| -------- | ---------------------------------------- | 3362| 201 | Permission denied. | 3363| 202 | Not system application to call the interface. | 3364| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3365| 801 | Capability not supported. | 3366| 1600001 | Internal error. | 3367| 1600002 | Marshalling or unmarshalling error. | 3368| 1600003 | Failed to connect to the service. | 3369| 1600012 | No memory space. | 3370| 17700001 | The specified bundle name was not found. | 3371 3372**Example** 3373 3374```ts 3375import { BusinessError } from '@kit.BasicServicesKit'; 3376 3377// setNotificationEnableSlot 3378notificationManager.setNotificationEnableSlot( 3379 { bundle: "ohos.samples.notification", }, 3380 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3381 true).then(() => { 3382 console.info("setNotificationEnableSlot success"); 3383 }).catch((err: BusinessError) => { 3384 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3385 }); 3386``` 3387 3388## notificationManager.isNotificationSlotEnabled 3389 3390isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void 3391 3392Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. 3393 3394This API is not supported on wearables. 3395 3396**System capability**: SystemCapability.Notification.Notification 3397 3398**System API**: This is a system API. 3399 3400**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3401 3402**Parameters** 3403 3404| Name | Type | Mandatory| Description | 3405| -------- | ----------------------------- | ---- | ---------------------- | 3406| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3407| type | [SlotType](./js-apis-notificationManager.md#slottype) | Yes | Notification slot type. | 3408| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that the notification slot type is enabled, and **false** means the opposite.| 3409 3410**Error codes** 3411 3412For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3413 3414| ID| Error Message | 3415| -------- | ---------------------------------------- | 3416| 201 | Permission denied. | 3417| 202 | Not system application to call the interface. | 3418| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3419| 801 | Capability not supported. | 3420| 1600001 | Internal error. | 3421| 1600002 | Marshalling or unmarshalling error. | 3422| 1600003 | Failed to connect to the service. | 3423| 17700001 | The specified bundle name was not found. | 3424 3425**Example** 3426 3427```ts 3428import { BusinessError } from '@kit.BasicServicesKit'; 3429 3430// isNotificationSlotEnabledCallback 3431let isNotificationSlotEnabledCallback = (err: BusinessError, data: boolean): void => { 3432 if (err) { 3433 console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`); 3434 } else { 3435 console.info(`isNotificationSlotEnabled success, data is ${JSON.stringify(data)}`); 3436 } 3437}; 3438 3439notificationManager.isNotificationSlotEnabled( 3440 { bundle: "ohos.samples.notification", }, 3441 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3442 isNotificationSlotEnabledCallback); 3443``` 3444 3445## notificationManager.isNotificationSlotEnabled 3446 3447isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\> 3448 3449Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. 3450 3451This API is not supported on wearables. 3452 3453**System capability**: SystemCapability.Notification.Notification 3454 3455**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3456 3457**System API**: This is a system API. 3458 3459**Parameters** 3460 3461| Name| Type | Mandatory| Description | 3462| ------ | ----------------------------- | ---- | -------------- | 3463| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 3464| type | [SlotType](./js-apis-notificationManager.md#slottype) | Yes | Notification slot type.| 3465 3466**Return value** 3467 3468| Type | Description | 3469| ----------------------------------------------------------- | ------------------------------------------------------------ | 3470| Promise\<boolean\> | Promise used to return the result. The value **true** means that the notification slot type is enabled, and **false** means the opposite.| 3471 3472**Error codes** 3473 3474For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3475 3476| ID| Error Message | 3477| -------- | ---------------------------------------- | 3478| 201 | Permission denied. | 3479| 202 | Not system application to call the interface. | 3480| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3481| 801 | Capability not supported. | 3482| 1600001 | Internal error. | 3483| 1600002 | Marshalling or unmarshalling error. | 3484| 1600003 | Failed to connect to the service. | 3485| 17700001 | The specified bundle name was not found. | 3486 3487**Example** 3488 3489```ts 3490import { BusinessError } from '@kit.BasicServicesKit'; 3491 3492// isNotificationSlotEnabled 3493notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, 3494 notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data: boolean) => { 3495 console.info(`isNotificationSlotEnabled success, data: ${JSON.stringify(data)}`); 3496}).catch((err: BusinessError) => { 3497 console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`); 3498}); 3499``` 3500 3501 3502## notificationManager.setSyncNotificationEnabledWithoutApp 3503 3504setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void 3505 3506Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result. 3507 3508This API is not supported on TVs and wearables. 3509 3510**System capability**: SystemCapability.Notification.Notification 3511 3512**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3513 3514**System API**: This is a system API. 3515 3516**Parameters** 3517 3518| Name| Type | Mandatory| Description | 3519| ------ | ----------------------------- | ---- | -------------- | 3520| userId | number | Yes | User ID. | 3521| enable | boolean | Yes | Whether to enable the notification sync feature. The value **true** means to enable the feature, and **false** means the opposite. | 3522| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3523 3524**Error codes** 3525 3526For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3527 3528| ID| Error Message | 3529| -------- | ----------------------------------- | 3530| 201 | Permission denied. | 3531| 202 | Not system application to call the interface. | 3532| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3533| 801 | Capability not supported. | 3534| 1600001 | Internal error. | 3535| 1600002 | Marshalling or unmarshalling error. | 3536| 1600003 | Failed to connect to the service. | 3537| 1600008 | The user does not exist. | 3538 3539**Example** 3540 3541```ts 3542import { BusinessError } from '@kit.BasicServicesKit'; 3543 3544// Use the actual user ID when calling the API. 3545let userId: number = 100; 3546let enable: boolean = true; 3547let setSyncNotificationEnabledWithoutAppCallback = (err: BusinessError): void => { 3548 if (err) { 3549 console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`); 3550 } else { 3551 console.info("setSyncNotificationEnabledWithoutApp success"); 3552 } 3553} 3554notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); 3555``` 3556 3557 3558## notificationManager.setSyncNotificationEnabledWithoutApp 3559 3560setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void> 3561 3562Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. 3563 3564This API is not supported on TVs and wearables. 3565 3566**System capability**: SystemCapability.Notification.Notification 3567 3568**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3569 3570**System API**: This is a system API. 3571 3572**Parameters** 3573 3574| Name| Type | Mandatory| Description | 3575| ------ | ----------------------------- | ---- | -------------- | 3576| userId | number | Yes | User ID. | 3577| enable | boolean | Yes | Whether to enable the notification sync feature. The value **true** means to enable the feature, and **false** means the opposite. | 3578 3579**Return value** 3580 3581| Type | Description | 3582| ----------------------------------------------------------- | ------------------------------------------------------------ | 3583| Promise\<void\> | Promise used to return the result.| 3584 3585**Error codes** 3586 3587For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3588 3589| ID| Error Message | 3590| -------- | ----------------------------------- | 3591| 201 | Permission denied. | 3592| 202 | Not system application to call the interface. | 3593| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3594| 801 | Capability not supported. | 3595| 1600001 | Internal error. | 3596| 1600002 | Marshalling or unmarshalling error. | 3597| 1600003 | Failed to connect to the service. | 3598| 1600008 | The user does not exist. | 3599 3600**Example** 3601 3602```ts 3603import { BusinessError } from '@kit.BasicServicesKit'; 3604 3605// Use the actual user ID when calling the API. 3606let userId: number = 100; 3607let enable: boolean = true; 3608notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { 3609 console.info('setSyncNotificationEnabledWithoutApp success'); 3610}).catch((err: BusinessError) => { 3611 console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`); 3612}); 3613``` 3614 3615 3616## notificationManager.getSyncNotificationEnabledWithoutApp 3617 3618getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void 3619 3620Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result. 3621 3622**System capability**: SystemCapability.Notification.Notification 3623 3624**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3625 3626**System API**: This is a system API. 3627 3628**Parameters** 3629 3630| Name| Type | Mandatory| Description | 3631| ------ | ----------------------------- | ---- | -------------- | 3632| userId | number | Yes | User ID. | 3633| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that the notification sync feature is enabled, and **false** means the opposite.| 3634 3635**Error codes** 3636 3637For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3638 3639| ID| Error Message | 3640| -------- | ----------------------------------- | 3641| 201 | Permission denied. | 3642| 202 | Not system application to call the interface. | 3643| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3644| 1600001 | Internal error. | 3645| 1600002 | Marshalling or unmarshalling error. | 3646| 1600003 | Failed to connect to the service. | 3647| 1600008 | The user does not exist. | 3648 3649**Example** 3650 3651```ts 3652import { BusinessError } from '@kit.BasicServicesKit'; 3653 3654// Use the actual user ID when calling the API. 3655let userId: number = 100; 3656let getSyncNotificationEnabledWithoutAppCallback = (err: BusinessError, data: boolean): void => { 3657 if (err) { 3658 console.error(`getSyncNotificationEnabledWithoutAppCallback failed, code is ${err.code}, message is ${err.message}`); 3659 } else { 3660 console.info(`getSyncNotificationEnabledWithoutAppCallback success, data: ${JSON.stringify(data)}`); 3661 } 3662} 3663notificationManager.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback); 3664``` 3665 3666 3667## notificationManager.getSyncNotificationEnabledWithoutApp 3668 3669getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean> 3670 3671Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. 3672 3673**System capability**: SystemCapability.Notification.Notification 3674 3675**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3676 3677**System API**: This is a system API. 3678 3679**Parameters** 3680 3681| Name| Type | Mandatory| Description | 3682| ------ | ----------------------------- | ---- | -------------- | 3683| userId | number | Yes | User ID. | 3684 3685**Return value** 3686 3687| Type | Description | 3688| ------------------ | ------------------------------------------------------------ | 3689| Promise\<boolean\> | Promise used to return the result. The value **true** means that the notification sync feature is enabled, and **false** means the opposite.| 3690 3691**Error codes** 3692 3693For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3694 3695| ID| Error Message | 3696| -------- | ----------------------------------- | 3697| 201 | Permission denied. | 3698| 202 | Not system application to call the interface. | 3699| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3700| 1600001 | Internal error. | 3701| 1600002 | Marshalling or unmarshalling error. | 3702| 1600003 | Failed to connect to the service. | 3703| 1600008 | The user does not exist. | 3704 3705**Example** 3706 3707```ts 3708import { BusinessError } from '@kit.BasicServicesKit'; 3709 3710// Use the actual user ID when calling the API. 3711let userId: number = 100; 3712notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data: boolean) => { 3713 console.info(`getSyncNotificationEnabledWithoutApp, data: ${JSON.stringify(data)}`); 3714}).catch((err: BusinessError) => { 3715 console.error(`getSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`); 3716}); 3717``` 3718 3719## notificationManager.on<sup>10+</sup> 3720 3721on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void 3722 3723Subscribes to notification events. The notification service sends the notification information in the callback to the verification program. The verification program returns the verification result to determine whether to publish the notification, for example, controlling the publish frequency of marketing notifications. 3724 3725Each [SlotType](./js-apis-notificationManager.md#slottype) in the system can have only one registrant. 3726 3727**System capability**: SystemCapability.Notification.Notification 3728 3729**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3730 3731**System API**: This is a system API. 3732 3733**Parameters** 3734 3735| Name| Type | Mandatory| Description | 3736| ------ |-------------------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3737| type | string | Yes | Event type. The value is fixed to **'checkNotification'**.| 3738| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | Yes | Pointer to the notification verification function.| 3739 3740**Error codes** 3741 3742For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3743 3744| ID| Error Message | 3745| -------- | ----------------------------------- | 3746| 202 | Not system application. | 3747| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3748| 1600001 | Internal error. | 3749 3750**Example** 3751 3752```ts 3753import { BusinessError } from '@kit.BasicServicesKit'; 3754 3755let onCheckNotification = (info : notificationManager.NotificationCheckInfo): notificationManager.NotificationCheckResult => { 3756 console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`); 3757 if(info.notificationId == 1){ 3758 let result: notificationManager.NotificationCheckResult = { code: 1, message: "testMsg1"}; 3759 return result; 3760 } else { 3761 let result: notificationManager.NotificationCheckResult = { code: 0, message: "testMsg0"}; 3762 return result; 3763 } 3764} 3765try{ 3766 notificationManager.on("checkNotification", onCheckNotification); 3767} catch (err){ 3768 console.error(`notificationManager.on failed, code is ${err.code}, message is ${err.message}`); 3769} 3770``` 3771 3772## notificationManager.on<sup>11+</sup> 3773 3774on(type: 'checkNotification', checkRequest: NotificationCheckRequest, callback: (checkInfo: NotificationCheckInfo) => Promise\<NotificationCheckResult\>): void 3775 3776Subscribes to notification events. The notification service sends the notification information in the callback to the verification program. The verification program returns the verification result to determine whether to publish the notification, for example, controlling the publish frequency of marketing notifications. This API uses a promise to return the result. 3777 3778Each [SlotType](./js-apis-notificationManager.md#slottype) in the system can have only one registrant. 3779 3780**System capability**: SystemCapability.Notification.Notification 3781 3782**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3783 3784**System API**: This is a system API. 3785 3786**Parameters** 3787 3788| Name| Type | Mandatory| Description | 3789| ------ |-----------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3790| type | string | Yes | Event type. The value is fixed to **'checkNotification'**.| 3791| checkRequest | [NotificationCheckRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationcheckrequest11) | Yes | Notification verification content.| 3792| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => Promise\<[NotificationCheckResult](#notificationcheckresult10)\> | Yes | Pointer to the notification verification function.| 3793 3794**Error codes** 3795 3796For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3797 3798| ID| Error Message | 3799| -------- | ----------------------------------- | 3800| 201 | Permission denied. | 3801| 202 | Not system application. | 3802| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3803| 1600001 | Internal error. | 3804| 1600002 | Marshalling or unmarshalling error. | 3805| 1600003 | Failed to connect to the service. | 3806 3807**Example** 3808 3809```ts 3810import { BusinessError } from '@kit.BasicServicesKit'; 3811 3812try{ 3813 notificationManager.on('checkNotification',{ 3814 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LIVE_VIEW, 3815 slotType: notificationManager.SlotType.LIVE_VIEW , 3816 extraInfoKeys: ["event"], 3817 }, 3818 async (checkInfo)=>{ 3819 return { code: 1, message: "INVALID_PARAMETERS"}; 3820 },); 3821} catch (err) { 3822 console.error(`notificationManager.on failed, code is ${err.code}, message is ${err.message}`); 3823} 3824``` 3825 3826## notificationManager.off<sup>10+</sup> 3827 3828off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void 3829 3830Unsubscribes from notification events. 3831 3832**System capability**: SystemCapability.Notification.Notification 3833 3834**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3835 3836**System API**: This is a system API. 3837 3838**Parameters** 3839 3840| Name| Type | Mandatory| Description | 3841| ------ |-------------------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3842| type | string | Yes | Event type. The value is fixed to **'checkNotification'**.| 3843| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | No | Pointer to the notification verification function.| 3844 3845**Error codes** 3846 3847For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3848 3849| ID| Error Message | 3850| -------- | ----------------------------------- | 3851| 202 | Not system application. | 3852| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3853| 1600001 | Internal error. | 3854 3855**Example** 3856 3857```ts 3858import { BusinessError } from '@kit.BasicServicesKit'; 3859 3860try{ 3861 notificationManager.off("checkNotification"); 3862} catch (err){ 3863 console.error(`notificationManager.off failed, code is ${err.code}, message is ${err.message}`); 3864} 3865``` 3866 3867## notificationManager.triggerSystemLiveView<sup>11+</sup> 3868 3869triggerSystemLiveView(bundle: BundleOption, notificationId: number, buttonOptions: ButtonOptions): Promise\<void> 3870 3871Triggers a system live view notification. This API uses a promise to return the result. 3872 3873This API is not supported on wearables. 3874 3875**System capability**: SystemCapability.Notification.Notification 3876 3877**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 3878 3879**System API**: This is a system API. 3880 3881**Parameters** 3882 3883| Name| Type | Mandatory| Description | 3884| -------------- | ------------- | ---- | -------------- | 3885| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes |Bundle information of the application.| 3886| notificationId | number | Yes | Notification ID.| 3887| buttonOptions | [ButtonOptions](#buttonoptions11) | Yes | Button information.| 3888 3889**Return value** 3890 3891| Type| Description| 3892| ---- | ----| 3893| Promise\<void> | Promise that returns no value.| 3894 3895**Error codes** 3896 3897For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 3898 3899| ID| Error Message | 3900| -------- | ----------------------------------- | 3901| 201 | Permission denied. | 3902| 202 | Not system application to call the interface. | 3903| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3904| 801 | Capability not supported. | 3905| 1600001 | Internal error. | 3906| 1600002 | Marshalling or unmarshalling error. | 3907| 1600003 | Failed to connect to the service. | 3908| 1600007 | The notification does not exist. | 3909| 17700001 | The specified bundle name was not found. | 3910 3911**Example** 3912 3913```ts 3914import { BusinessError } from '@kit.BasicServicesKit'; 3915 3916// Bundle information 3917let bundle: notificationManager.BundleOption = { 3918 bundle: "bundleName1", 3919}; 3920// Notification ID 3921let notificationId = 1; 3922// Button information 3923let buttonOptions: notificationManager.ButtonOptions = { 3924 buttonName: "buttonName1", 3925} 3926notificationManager.triggerSystemLiveView(bundle, notificationId, buttonOptions).then(() => { 3927 console.info("triggerSystemLiveView success"); 3928}).catch((err: BusinessError) => { 3929 console.error(`triggerSystemLiveView failed, code is ${err.code}, message is ${err.message}`); 3930}); 3931``` 3932 3933 3934## notificationManager.subscribeSystemLiveView<sup>11+</sup> 3935 3936subscribeSystemLiveView(subscriber: SystemLiveViewSubscriber): Promise\<void> 3937 3938Subscribes to the system live view notification. This API uses a promise to return the result. 3939 3940This API is not supported on wearables. 3941 3942**System capability**: SystemCapability.Notification.Notification 3943 3944**System API**: This is a system API. 3945 3946**Parameters** 3947 3948| Name| Type | Mandatory| Description | 3949| -------------- | ------------- | ---- | -------------- | 3950| subscriber | [SystemLiveViewSubscriber](#systemliveviewsubscriber11) | Yes | Subscriber of the system live view notification.| 3951 3952**Return value** 3953 3954| Type| Description| 3955| ---- | ----| 3956| Promise\<void> | Promise that returns no value.| 3957 3958**Error codes** 3959 3960For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 3961 3962| ID| Error Message | 3963| -------- | ----------------------------------- | 3964| 202 | Not system application to call the interface. | 3965| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3966| 801 | Capability not supported. | 3967| 1600001 | Internal error. | 3968| 1600002 | Marshalling or unmarshalling error. | 3969| 1600003 | Failed to connect to the service. | 3970| 1600012 | No memory space. | 3971 3972**Example** 3973 3974```ts 3975import { BusinessError } from '@kit.BasicServicesKit'; 3976 3977let onResponseCallback = (id:number, option:notificationManager.ButtonOptions) => { 3978 console.info(`notificationId: ${id},onResponseCallback: ${JSON.stringify(option)}`); 3979} 3980let subscriber: notificationManager.SystemLiveViewSubscriber = { 3981 onResponse: onResponseCallback, 3982}; 3983notificationManager.subscribeSystemLiveView(subscriber).then(() => { 3984 console.info("subscribeSystemLiveView success"); 3985}).catch((err: BusinessError) => { 3986 console.error(`subscribeSystemLiveView failed, code is ${err.code}, message is ${err.message}`); 3987}); 3988``` 3989 3990## notificationManager.setDistributedEnabledByBundle<sup>12+</sup> 3991 3992setDistributedEnabledByBundle(bundle: BundleOption, deviceType: string, enable: boolean): Promise<void\> 3993 3994Sets whether a specified application supports cross-device collaboration. This API uses a promise to return the result. 3995 3996This API is not supported on TVs and wearables. 3997 3998**System capability**: SystemCapability.Notification.Notification 3999 4000**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4001 4002**System API**: This is a system API. 4003 4004**Parameters** 4005 4006| Name | Type | Mandatory| Description | 4007| -------- | ------------------------ | ---- | -------------------------- | 4008| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 4009| deviceType | string | Yes | Device type.| 4010| enable | boolean | Yes | Whether to enable cross-device collaboration. The value **true** means to enable distributed notification, and **false** means the opposite.| 4011 4012**Return value** 4013 4014| Type| Description| 4015| ---- | ----| 4016| Promise\<void> | Promise that returns no value.| 4017 4018**Error codes** 4019 4020For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4021 4022| ID| Error Message | 4023| -------- | ---------------------------------------- | 4024| 201 | Permission denied. | 4025| 202 | Not system application to call the interface. | 4026| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4027| 801 | Capability not supported. | 4028| 1600001 | Internal error. | 4029| 1600002 | Marshalling or unmarshalling error. | 4030| 1600003 | Failed to connect to the service. | 4031| 1600010 | Distributed operation failed. | 4032| 1600012 | No memory space. | 4033| 17700001 | The specified bundle name was not found. | 4034 4035**Example** 4036 4037```ts 4038import { BusinessError } from '@kit.BasicServicesKit'; 4039 4040let bundle: notificationManager.BundleOption = { 4041 bundle: "bundleName1", 4042 uid: 1 4043}; 4044let enable: boolean = true; 4045let deviceType: string = "phone"; 4046notificationManager.setDistributedEnabledByBundle(bundle, deviceType, enable).then(() => { 4047 console.info("setDistributedEnabledByBundle success"); 4048}).catch((err: BusinessError) => { 4049 console.error(`setDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`); 4050}); 4051``` 4052 4053## notificationManager.isDistributedEnabledByBundle<sup>12+</sup> 4054 4055isDistributedEnabledByBundle(bundle: BundleOption, deviceType: string): Promise<boolean\> 4056 4057Obtains whether a specified application supports cross-device collaboration. This API uses a promise to return the result. 4058 4059This API is not supported on TVs and wearables. 4060 4061**System capability**: SystemCapability.Notification.Notification 4062 4063**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4064 4065**System API**: This is a system API. 4066 4067**Parameters** 4068 4069| Name | Type | Mandatory| Description | 4070| -------- | ------------------------ | ---- | -------------------------- | 4071| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 4072| deviceType | string | Yes | Device type.| 4073 4074**Return value** 4075 4076| Type| Description| 4077| ---- | ----| 4078| Promise\<boolean\> | Promise used to return the result (true: enabled; false: disabled).| 4079 4080**Error codes** 4081 4082For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4083 4084| ID| Error Message | 4085| -------- | ---------------------------------------- | 4086| 201 | Permission denied. | 4087| 202 | Not system application to call the interface. | 4088| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4089| 801 | Capability not supported. | 4090| 1600001 | Internal error. | 4091| 1600002 | Marshalling or unmarshalling error. | 4092| 1600003 | Failed to connect to the service. | 4093| 1600010 | Distributed operation failed. | 4094| 1600012 | No memory space. | 4095| 17700001 | The specified bundle name was not found. | 4096 4097**Example** 4098 4099```ts 4100import { BusinessError } from '@kit.BasicServicesKit'; 4101 4102let bundle: notificationManager.BundleOption = { 4103 bundle: "bundleName1", 4104 uid: 1 4105}; 4106let deviceType: string = "phone"; 4107notificationManager.isDistributedEnabledByBundle(bundle, deviceType).then((data: boolean) => { 4108 console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`); 4109}).catch((err: BusinessError) => { 4110 console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`); 4111}); 4112``` 4113 4114## notificationManager.setSmartReminderEnabled<sup>12+</sup> 4115 4116setSmartReminderEnabled(deviceType: string, enable: boolean): Promise<void\> 4117 4118Sets a smart reminder for cross-device collaboration. This API uses a promise to return the result. 4119 4120This API is not supported on TVs and wearables. 4121 4122**System capability**: SystemCapability.Notification.Notification 4123 4124**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4125 4126**System API**: This is a system API. 4127 4128**Parameters** 4129 4130| Name | Type | Mandatory| Description | 4131| -------- | ------------------------ | ---- | -------------------------- | 4132| deviceType | string | Yes | Device type.| 4133| enable | boolean | Yes | Indicates whether the specified application supports a smart reminder for cross-device collaboration (**true**: enabled; **false**: disabled).| 4134 4135**Return value** 4136 4137| Type| Description| 4138| ---- | ----| 4139| Promise\<void> | Promise that returns no value.| 4140 4141**Error codes** 4142 4143For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4144 4145| ID| Error Message | 4146| -------- | ---------------------------------------- | 4147| 201 | Permission denied. | 4148| 202 | Not system application to call the interface. | 4149| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4150| 801 | Capability not supported. | 4151| 1600001 | Internal error. | 4152| 1600002 | Marshalling or unmarshalling error. | 4153| 1600003 | Failed to connect to the service. | 4154| 1600010 | Distributed operation failed. | 4155| 1600012 | No memory space. | 4156| 17700001 | The specified bundle name was not found. | 4157 4158**Example** 4159 4160```ts 4161import { BusinessError } from '@kit.BasicServicesKit'; 4162 4163let deviceType: string = "phone"; 4164let enable: boolean = true; 4165notificationManager.setSmartReminderEnabled(deviceType, enable).then(() => { 4166 console.info("setSmartReminderEnabled success"); 4167}).catch((err: BusinessError) => { 4168 console.error(`setSmartReminderEnabled failed, code is ${err.code}, message is ${err.message}`); 4169}); 4170``` 4171 4172## notificationManager.isSmartReminderEnabled<sup>12+</sup> 4173 4174isSmartReminderEnabled(deviceType: string): Promise<boolean\> 4175 4176Obtains a smart reminder for cross-device collaboration. This API uses a promise to return the result. 4177 4178This API is not supported on TVs and wearables. 4179 4180**System capability**: SystemCapability.Notification.Notification 4181 4182**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4183 4184**System API**: This is a system API. 4185 4186**Parameters** 4187 4188| Name | Type | Mandatory| Description | 4189| -------- | ------------------------ | ---- | -------------------------- | 4190| deviceType | string | Yes | Device type.| 4191 4192**Return value** 4193 4194| Type| Description| 4195| ---- | ----| 4196| Promise\<boolean\> | Promise used to return the result (**true**: enabled; **false**: disabled).| 4197 4198**Error codes** 4199 4200For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4201 4202| ID| Error Message | 4203| -------- | ---------------------------------------- | 4204| 201 | Permission denied. | 4205| 202 | Not system application to call the interface. | 4206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4207| 801 | Capability not supported. | 4208| 1600001 | Internal error. | 4209| 1600002 | Marshalling or unmarshalling error. | 4210| 1600003 | Failed to connect to the service. | 4211| 1600010 | Distributed operation failed. | 4212| 1600012 | No memory space. | 4213| 17700001 | The specified bundle name was not found. | 4214 4215**Example** 4216 4217```ts 4218import { BusinessError } from '@kit.BasicServicesKit'; 4219 4220let deviceType: string = "phone"; 4221notificationManager.isSmartReminderEnabled(deviceType).then((data: boolean) => { 4222 console.info(`isSmartReminderEnabled success, data:${data}`); 4223}).catch((err: BusinessError) => { 4224 console.error(`isSmartReminderEnabled failed, code is ${err.code}, message is ${err.message}`); 4225}); 4226``` 4227 4228## notificationManager.setBadgeNumberByBundle<sup>12+</sup> 4229 4230setBadgeNumberByBundle(bundle: BundleOption, badgeNumber: number): Promise\<void\> 4231 4232Sets the badge count for other applications. This API uses a promise to return the result. 4233 4234This API is not supported on wearables. 4235 4236**System capability**: SystemCapability.Notification.Notification 4237 4238**System API**: This is a system API. 4239 4240**Parameters** 4241 4242| Name | Type | Mandatory| Description | 4243| ----------- | ------ | ---- | ---------- | 4244| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 4245| badgeNumber | number | Yes | Notification badge number to set.| 4246 4247**Return value** 4248 4249| Type | Description | 4250| --------------- | ------------------------- | 4251| Promise\<void\> | Promise that returns no value.| 4252 4253**Error codes** 4254 4255For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4256 4257| ID| Error Message | 4258| -------- | ----------------------------------- | 4259| 202 | Not system application to call the interface. | 4260| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4261| 801 | Capability not supported. | 4262| 1600001 | Internal error. | 4263| 1600002 | Marshalling or unmarshalling error. | 4264| 1600003 | Failed to connect to the service. | 4265| 1600012 | No memory space. | 4266| 1600017 | There is no corresponding agent relationship configuration. | 4267| 17700001 | The specified bundle name was not found. | 4268 4269**Example** 4270 4271```ts 4272import { BusinessError } from '@kit.BasicServicesKit'; 4273 4274let bundle: notificationManager.BundleOption = { 4275 bundle: 'com.example.bundleName', 4276}; 4277let badgeNumber: number = 10; 4278 4279notificationManager.setBadgeNumberByBundle(bundle, badgeNumber).then(() => { 4280 console.info('setBadgeNumberByBundle success'); 4281}).catch((err: BusinessError) => { 4282 console.error(`setBadgeNumberByBundle failed, code is ${err.code}, message is ${err.message}`); 4283}); 4284``` 4285 4286## notificationManager.getSlotByBundle<sup>12+</sup> 4287 4288getSlotByBundle(bundle: BundleOption, slotType: SlotType): Promise\<NotificationSlot> 4289 4290Obtains a notification slot of a specified application. This API uses a promise to return the result. 4291 4292This API is not supported on wearables. 4293 4294Before obtaining the notification slot, create a slot through [addSlot](#notificationmanageraddslot). 4295 4296**System capability**: SystemCapability.Notification.Notification 4297 4298**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4299 4300**System API**: This is a system API. 4301 4302**Parameters** 4303 4304| Name | Type | Mandatory| Description | 4305| ------ | ------------ | ---- | ---------- | 4306| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 4307| slotType | [SlotType](././js-apis-notificationManager.md#slottype) | Yes | Notification slot type.| 4308 4309**Return value** 4310 4311| Type | Description | 4312| ----------------------------------------------------------- | ------------------------------------------------------------ | 4313| Promise\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)> | Promise used to return the result.| 4314 4315**Error codes** 4316 4317For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4318 4319| ID| Error Message | 4320| -------- | ---------------------------------------- | 4321| 201 | Permission denied. | 4322| 202 | Not system application to call the interface. | 4323| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4324| 801 | Capability not supported. | 4325| 1600001 | Internal error. | 4326| 1600002 | Marshalling or unmarshalling error. | 4327| 1600003 | Failed to connect to the service. | 4328| 1600012 | No memory space. | 4329| 17700001 | The specified bundle name was not found. | 4330 4331**Example** 4332 4333```ts 4334import { BusinessError } from '@kit.BasicServicesKit'; 4335 4336let bundle: notificationManager.BundleOption = { 4337 bundle: "bundleName1", 4338}; 4339 4340let slotType = notificationManager.SlotType.LIVE_VIEW; 4341 4342notificationManager.getSlotByBundle(bundle, slotType).then((data: notificationManager.NotificationSlot) => { 4343 console.info(`getSlotByBundle success, data: ${JSON.stringify(data)}`); 4344}).catch((err: BusinessError) => { 4345 console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`); 4346}); 4347``` 4348 4349## notificationManager.addDoNotDisturbProfile<sup>12+</sup> 4350 4351addDoNotDisturbProfile(templates: Array\<DoNotDisturbProfile>): Promise\<void\> 4352 4353Adds the Do Not Disturb profile configuration information. This API uses a promise to return the result. 4354 4355This API is not supported on TVs and wearables. 4356 4357**System capability**: SystemCapability.Notification.Notification 4358 4359**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4360 4361**System API**: This is a system API. 4362 4363**Parameters** 4364 4365| Name | Type | Mandatory| Description | 4366| ------ | ---------------- | ---- | -------------- | 4367| templates | Array\<[DoNotDisturbProfile](#donotdisturbprofile12)> | Yes| Configuration information about the Do Not Disturb profile.| 4368 4369**Return value** 4370 4371| Type | Description | 4372|---------|-----------| 4373| Promise\<void\> | Promise that returns no value.| 4374 4375**Error codes** 4376 4377For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 4378 4379| ID| Error Message | 4380| -------- | ----------------------------------- | 4381| 201 | Permission denied. | 4382| 202 | Not system application to call the interface. | 4383| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4384| 801 | Capability not supported. | 4385| 1600001 | Internal error. | 4386| 1600002 | Marshalling or unmarshalling error. | 4387| 1600003 | Failed to connect to the service. | 4388| 1600012 | No memory space. | 4389 4390**Example** 4391 4392```ts 4393import { BusinessError } from '@kit.BasicServicesKit'; 4394 4395let trustlist: Array<notificationManager.BundleOption> = [ 4396 { 4397 bundle: 'com.example.bundleName', 4398 uid: 0 4399 }, 4400 { 4401 bundle: 'com.example.bundleName1', 4402 uid: 1 4403 } 4404] 4405let templates: Array<notificationManager.DoNotDisturbProfile> = [ 4406 { 4407 id: 3, 4408 name: 'working mode', 4409 trustlist: trustlist 4410 } 4411] 4412 4413notificationManager.addDoNotDisturbProfile(templates).then(() => { 4414 console.info("addDoNotDisturbProfile success."); 4415}).catch((err: BusinessError) => { 4416 console.error(`addDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`); 4417}); 4418``` 4419 4420## notificationManager.removeDoNotDisturbProfile<sup>12+</sup> 4421 4422removeDoNotDisturbProfile(templates: Array\<DoNotDisturbProfile>): Promise\<void\> 4423 4424Deletes the Do Not Disturb profile configuration. This API uses a promise to return the result. 4425 4426This API is not supported on TVs and wearables. 4427 4428**System capability**: SystemCapability.Notification.Notification 4429 4430**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4431 4432**System API**: This is a system API. 4433 4434**Parameters** 4435 4436| Name | Type | Mandatory| Description | 4437| ------ | ---------------- | ---- | -------------- | 4438| templates | Array\<[DoNotDisturbProfile](#donotdisturbprofile12)> | Yes | Configuration information about the Do Not Disturb profile.| 4439 4440**Return value** 4441 4442| Type | Description | 4443|---------|-----------| 4444| Promise\<void\> | Promise that returns no value.| 4445 4446**Error codes** 4447 4448For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 4449 4450| ID| Error Message | 4451| -------- | ----------------------------------- | 4452| 201 | Permission denied. | 4453| 202 | Not system application to call the interface. | 4454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4455| 801 | Capability not supported. | 4456| 1600001 | Internal error. | 4457| 1600002 | Marshalling or unmarshalling error. | 4458| 1600003 | Failed to connect to the service. | 4459| 1600012 | No memory space. | 4460 4461**Example** 4462 4463```ts 4464import { BusinessError } from '@kit.BasicServicesKit'; 4465 4466let templates: Array<notificationManager.DoNotDisturbProfile> = [ 4467 { 4468 id: 3, 4469 name: 'working mode' 4470 } 4471] 4472notificationManager.removeDoNotDisturbProfile(templates).then(() => { 4473 console.info("removeDoNotDisturbProfile success."); 4474}).catch((err: BusinessError) => { 4475 console.error(`removeDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`); 4476}); 4477``` 4478 4479## notificationManager.setAdditionalConfig<sup>12+</sup> 4480 4481setAdditionalConfig(key: string, value: string): Promise\<number\> 4482 4483Sets the additional system configuration information of the notification. This API uses a promise to return the result. 4484 4485This API is not supported on TVs and wearables. 4486 4487**System capability**: SystemCapability.Notification.Notification 4488 4489**Required permissions**: ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4490 4491**System API**: This is a system API. 4492 4493**Parameters** 4494 4495| Name | Type | Mandatory| Description | 4496| ------ | ---------------- | ---- | -------------- | 4497| key | string | Yes | Additional configuration key. Currently, only **RING_TRUSTLIST_PKG** is supported, indicating that the application supports [customized ring tone](./js-apis-inner-notification-notificationRequest.md#notificationrequest-1).| 4498| value | string | Yes | Additional configuration value. Example: [bundleName1,bundleName2].| 4499 4500**Return value** 4501 4502| Type | Description | 4503|---------|-----------| 4504| Promise\<number\> | Promise used to return the result. **0** indicates successful; other values indicate failed.| 4505 4506**Error codes** 4507 4508For details about the error codes, see [Notification Error Codes](./errorcode-notification.md). 4509 4510| ID| Error Message | 4511| -------- | ----------------------------------- | 4512| 201 | Permission denied. | 4513| 202 | Not system application to call the interface. | 4514| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4515| 801 | Capability not supported. | 4516| 1600001 | Internal error. | 4517| 1600002 | Marshalling or unmarshalling error. | 4518| 1600003 | Failed to connect to the service. | 4519 4520**Example** 4521 4522```ts 4523import { BusinessError } from '@kit.BasicServicesKit'; 4524 4525notificationManager.setAdditionalConfig('RING_TRUSTLIST_PKG','[bundleName1,bundleName2]').then((data: number) => { 4526 console.info(`setAdditionalConfig success, data: ${JSON.stringify(data)}`); 4527}).catch((err: BusinessError) => { 4528 console.error(`setAdditionalConfig failed, code is ${err.code}, message is ${err.message}`); 4529}); 4530``` 4531 4532## notificationManager.getDoNotDisturbProfile<sup>13+</sup> 4533 4534getDoNotDisturbProfile(id: number): Promise\<DoNotDisturbProfile\> 4535 4536Queries the configuration information about the Do Not Disturb profile. This API uses a promise to return the result. 4537 4538This API is not supported on TVs and wearables. 4539 4540**System capability**: SystemCapability.Notification.Notification 4541 4542**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4543 4544**System API**: This is a system API. 4545 4546**Parameters** 4547 4548| Name | Type | Mandatory| Description | 4549| ------ | ---------------- | ---- | -------------- | 4550| id | number | Yes | ID of the Do Not Disturb profile.| 4551 4552**Return value** 4553 4554| Type | Description | 4555|---------|-----------| 4556| Promise\<[DoNotDisturbProfile](#donotdisturbprofile12)\> | Promise used to return the result.| 4557 4558**Error codes** 4559 4560For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 4561 4562| ID| Error Message | 4563| -------- | ----------------------------------- | 4564| 201 | Permission denied. | 4565| 202 | Not system application to call the interface. | 4566| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4567| 801 | Capability not supported. | 4568| 1600001 | Internal error. | 4569| 1600002 | Marshalling or unmarshalling error. | 4570| 1600003 | Failed to connect to the service. | 4571| 1600019 | The do-not-disturb profile does not exist. | 4572 4573**Example** 4574 4575```ts 4576import { BusinessError } from '@kit.BasicServicesKit'; 4577 4578notificationManager.getDoNotDisturbProfile(1).then((data: notificationManager.DoNotDisturbProfile) => { 4579 console.info(`getDoNotDisturbProfile success: ${JSON.stringify(data)}`); 4580}).catch((err: BusinessError) => { 4581 console.error(`getDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`); 4582}); 4583``` 4584 4585## notificationManager.disableNotificationFeature<sup>18+</sup> 4586 4587disableNotificationFeature(disabled: boolean, bundleList: Array\<string\>): Promise\<void\> 4588 4589Disables the application from publishing notifications by adding the application bundle name to the permission control list. This function can be disabled as required. 4590 4591This API is not supported on wearables. 4592 4593**System capability**: SystemCapability.Notification.Notification 4594 4595**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.MANAGE_EDM_POLICY 4596 4597**System API**: This is a system API. 4598 4599**Parameters** 4600 4601| Name | Type | Mandatory| Description | 4602| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4603| disabled | boolean | Yes | Whether to enable the permission control list for publishing notifications (**true**: enabled; **false**: disabled).| 4604| bundleList | Array\<string\> | Yes | Application list under the permission control list. The bundle name is used to represent the application.| 4605 4606**Return value** 4607 4608| Type | Description | 4609|-----------------|-------------------------| 4610| Promise\<void\> | Promise that returns no value.| 4611 4612**Error codes** 4613 4614For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 4615 4616| ID| Error Message | 4617| -------- | ------------------------------------------------------------ | 4618| 201 | Permission denied. | 4619| 202 | Not system application to call the interface. | 4620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4621| 1600001 | Internal error. | 4622| 1600002 | Marshalling or unmarshalling error. | 4623 4624**Example** 4625 4626```ts 4627import { BusinessError } from '@kit.BasicServicesKit'; 4628import { hilog } from '@kit.PerformanceAnalysisKit'; 4629 4630let disabled: boolean = true; 4631let bundleList: Array<string> = ["com.example.myapplication"]; 4632try { 4633 notificationManager.disableNotificationFeature(disabled, bundleList).then(() => { 4634 hilog.info(0x0000, 'testTag', '%{public}s', `disableNotificationFeature success.`); 4635 }).catch((err: BusinessError) => { 4636 hilog.error(0x0000, 'testTag', '%{public}s', `disableNotificationFeature failed, code is ${err.code}, message is ${err.message}`); 4637 }); 4638} catch (err) { 4639 hilog.error(0x0000, 'testTag', '%{public}s', `testTag failed, code is ${err.code}, message is ${err.message}`); 4640} 4641``` 4642 4643## notificationManager.disableNotificationFeature<sup>20+</sup> 4644 4645disableNotificationFeature(disabled: boolean, bundleList: Array\<string\>, userId: number): Promise\<void\> 4646 4647Disables the application from publishing notifications by adding the application bundle name to the permission control list. This API uses a promise to return the result. 4648 4649This API is not supported on wearables. 4650 4651**System capability**: SystemCapability.Notification.Notification 4652 4653**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.MANAGE_EDM_POLICY 4654 4655**System API**: This is a system API. 4656 4657**Parameters** 4658 4659| Name | Type | Mandatory| Description | 4660| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4661| disabled | boolean | Yes | Whether to enable the notification permission control list. The value **true** indicates that the notification permission control list is enabled; **false** indicates the opposite.| 4662| bundleList | Array\<string\> | Yes | Bundles under the permission control list. The bundle name is used to represent a specific application.| 4663| userId | number | Yes | User ID.| 4664 4665**Return value** 4666 4667| Type | Description | 4668|-----------------|-------------------------| 4669| Promise\<void\> | Promise that returns no value.| 4670 4671**Error codes** 4672 4673For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 4674 4675| ID| Error Message | 4676| -------- | ------------------------------------------------------------ | 4677| 201 | Permission verification failed. The application does not have the permission required to call the API. | 4678| 202 | Permission verification failed. A non-system application calls a system API. | 4679| 1600001 | Internal error. | 4680| 1600002 | Marshalling or unmarshalling error. | 4681 4682**Example** 4683 4684```ts 4685import { BusinessError } from '@kit.BasicServicesKit'; 4686import { hilog } from '@kit.PerformanceAnalysisKit'; 4687 4688let disabled: boolean = true; 4689let bundleList: Array<string> = ["com.example.myapplication"]; 4690let userId: number = 1; 4691try { 4692 notificationManager.disableNotificationFeature(disabled, bundleList, userId).then(() => { 4693 hilog.info(0x0000, 'testTag', '%{public}s', `disableNotificationFeature success.`); 4694 }).catch((err: BusinessError) => { 4695 hilog.error(0x0000, 'testTag', '%{public}s', `disableNotificationFeature failed, code is ${err.code}, message is ${err.message}`); 4696 }); 4697} catch (err) { 4698 hilog.error(0x0000, 'testTag', '%{public}s', `testTag failed, code is ${err.code}, message is ${err.message}`); 4699} 4700``` 4701 4702## notificationManager.setTargetDeviceStatus<sup>18+</sup> 4703 4704setTargetDeviceStatus(deviceType: string, status: number): Promise\<void\> 4705 4706Sets the status of a device after it is successfully connected. Device status determines the notification mode of the current device when a notification is published. 4707 4708**System capability**: SystemCapability.Notification.Notification 4709 4710**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4711 4712**System API**: This is a system API. 4713 4714**Parameters** 4715 4716| Name | Type | Mandatory| Description | 4717| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4718| deviceType | string | Yes | Device type. Currently, only **headset** (wearable audio device), **liteWearable** (lite wearables), **wearable** (smart wearables), and **current** (local device) are supported.| 4719| status | number | Yes | Device status.<br>- Bit 0: whether the device is in use. The value **0** indicates that the device is available; **1** indicates that the device is in use.<br>- Bit 1: whether the device user is the owner. The value **0** indicates that the user is not the owner; **1** indicates the opposite.<br>- Bit 2: whether the device is in the Do Not Disturb mode. The value **0** indicates that the device is not in the Do Not Disturb mode; **1** indicates the opposite.| 4720 4721**Return value** 4722 4723| Type | Description | 4724|-----------------|-------------------------| 4725| Promise\<void\> | Promise that returns no value.| 4726 4727**Error codes** 4728 4729For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4730 4731| ID| Error Message | 4732| -------- | ------------------------------------------------------------ | 4733| 201 | Permission denied. | 4734| 202 | Not system application to call the interface. | 4735| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4736 4737**Example** 4738 4739```ts 4740import { BusinessError } from '@kit.BasicServicesKit'; 4741 4742notificationManager.setTargetDeviceStatus("current", 1).then(() => { 4743 console.info(`Succeeded in setting target device status.`); 4744}).catch((err: BusinessError) => { 4745 console.error(`Failed to set target device status. Code is ${err.code}, message is ${err.message}`); 4746}); 4747``` 4748 4749## notificationManager.setDistributedEnabledBySlot<sup>18+</sup> 4750 4751setDistributedEnabledBySlot(slot: SlotType, deviceType: string, enabled: boolean): Promise\<void\> 4752 4753Sets whether the notification of a specified slot can be sent to devices of a specified type through cross-device collaboration. This API uses a promise to return the result. 4754 4755**System capability**: SystemCapability.Notification.Notification 4756 4757**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4758 4759**System API**: This is a system API. 4760 4761**Parameters** 4762 4763| Name | Type | Mandatory| Description | 4764| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4765| slot | [SlotType](js-apis-notificationManager.md#slottype) | Yes | Types of the notification slot.| 4766| deviceType | string | Yes | Device type.<br>Since API version 18, the following device types are supported:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>Since API version 20, the following device types are supported:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>- **current**: current device<br>- **2in1**: PC<br>- **tablet**: tablet| 4767| enabled | boolean | Yes | Whether to enable cross-device collaboration for notifications. The value **true** means to enable cross-device collaboration, and **false** means the opposite.| 4768 4769**Return value** 4770 4771| Type | Description | 4772|-----------------|-------------------------| 4773| Promise\<void\> | Promise that returns no value.| 4774 4775**Error codes** 4776 4777For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4778 4779| ID| Error Message | 4780| -------- | ------------------------------------------------------------ | 4781| 201 | Permission denied. | 4782| 202 | Not system application to call the interface. | 4783| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4784 4785**Example** 4786 4787```ts 4788import { BusinessError } from '@kit.BasicServicesKit'; 4789import { hilog } from '@kit.PerformanceAnalysisKit'; 4790 4791let slot: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 4792let deviceType: string = 'wearable'; 4793let enabled: boolean = true; 4794 4795notificationManager.setDistributedEnabledBySlot(slot, deviceType, enabled).then(() => { 4796 hilog.info(0x0000, 'testTag', '%{public}s', `setDistributedEnabledBySlot success.`); 4797}).catch((err: BusinessError) => { 4798 hilog.error(0x0000, 'testTag', '%{public}s', `setDistributedEnabledBySlot failed, code is ${err.code}, message is ${err.message}`); 4799}); 4800``` 4801 4802## notificationManager.isDistributedEnabledBySlot<sup>18+</sup> 4803 4804isDistributedEnabledBySlot(slot: SlotType, deviceType: string): Promise\<boolean\> 4805 4806Queries whether notifications of a specified slot can be sent to devices of a specified type. This API uses a promise to return the result. 4807 4808**System capability**: SystemCapability.Notification.Notification 4809 4810**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4811 4812**System API**: This is a system API. 4813 4814**Parameters** 4815 4816| Name | Type | Mandatory| Description | 4817| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4818| slot | [SlotType](js-apis-notificationManager.md#slottype) | Yes | Types of the notification slot.| 4819| deviceType | string | Yes | Device type.<br>Since API version 18, the following device types are supported:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>Since API version 20, the following device types are supported:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>- **current**: current device<br>- **2in1**: PC<br>- **tablet**: tablet| 4820 4821**Return value** 4822 4823| Type | Description | 4824|-----------------|-------------------------| 4825| Promise\<boolean\> | Promise used to return the result. The value **true** means that cross-device collaboration is supported, and **false** means the opposite.| 4826 4827**Error codes** 4828 4829For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4830 4831| ID| Error Message | 4832| -------- | ------------------------------------------------------------ | 4833| 201 | Permission denied. | 4834| 202 | Not system application to call the interface. | 4835| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4836 4837**Example** 4838 4839```ts 4840import { BusinessError } from '@kit.BasicServicesKit'; 4841import { hilog } from '@kit.PerformanceAnalysisKit'; 4842 4843let slot: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 4844let deviceType: string = 'wearable'; 4845 4846notificationManager.isDistributedEnabledBySlot(slot, deviceType).then((data: boolean) => { 4847 hilog.info(0x0000, 'testTag', '%{public}s', `isDistributedEnabledBySlot success.`); 4848}).catch((err: BusinessError) => { 4849 hilog.error(0x0000, 'testTag', '%{public}s', `isDistributedEnabledBySlot failed, code is ${err.code}, message is ${err.message}`); 4850}); 4851``` 4852 4853## notificationManager.setSilentReminderEnabled<sup>20+</sup> 4854 4855setSilentReminderEnabled(bundle: BundleOption, enabled: boolean): Promise\<void\> 4856 4857Sets the enabling status of the silent reminder. This API uses a promise to return the result. 4858 4859**System capability**: SystemCapability.Notification.Notification 4860 4861**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4862 4863**System API**: This is a system API. 4864 4865**Parameters** 4866 4867| Name | Type | Mandatory| Description | 4868| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4869| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 4870| enabled | boolean | Yes | Whether to enable the silent reminder. The value **true** means to enable the silent reminder, and **false** means the opposite.| 4871 4872**Return value** 4873 4874| Type | Description | 4875|-----------------|-------------------------| 4876| Promise\<void\> | Promise that returns no value.| 4877 4878**Error codes** 4879 4880For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4881 4882| ID| Error Message | 4883| -------- | ------------------------------------------------------------ | 4884| 201 | Permission denied. | 4885| 202 | Not system application to call the interface. | 4886| 1600001 | Internal error. | 4887| 1600002 | Marshalling or unmarshalling error. | 4888| 1600003 | Failed to connect to the service. | 4889| 1600012 | No memory space. | 4890| 17700001 | The specified bundle name was not found. | 4891 4892**Example** 4893 4894```ts 4895import { BusinessError } from '@kit.BasicServicesKit'; 4896import { hilog } from '@kit.PerformanceAnalysisKit'; 4897 4898let bundle: notificationManager.BundleOption = { 4899 bundle: "bundleName", 4900}; 4901notificationManager.setSilentReminderEnabled(bundle, true).then(() => { 4902 hilog.info(0x0000, 'testTag', '%{public}s', `setSilentReminderEnabled success.`); 4903}).catch((err: BusinessError) => { 4904 hilog.error(0x0000, 'testTag', '%{public}s', `setSilentReminderEnabled failed, code is ${err.code}, message is ${err.message}`); 4905}); 4906``` 4907 4908## notificationManager.isSilentReminderEnabled<sup>20+</sup> 4909 4910isSilentReminderEnabled(bundle: BundleOption): Promise\<SwitchState\> 4911 4912Checks whether the silent reminder is enabled. This API uses a promise to return the result. 4913 4914**System capability**: SystemCapability.Notification.Notification 4915 4916**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4917 4918**System API**: This is a system API. 4919 4920**Parameters** 4921 4922| Name | Type | Mandatory| Description | 4923| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4924| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 4925 4926**Return value** 4927 4928| Type | Description | 4929|-----------------|-------------------------| 4930| Promise\<[SwitchState](#switchstate20)\> | Promise used to return the result.| 4931 4932**Error codes** 4933 4934For details about the error codes, see [Universal Error Codes](../errorcode-universal.md), [Notification Error Codes](./errorcode-notification.md), and [Bundle Error Codes](../../reference/apis-ability-kit/errorcode-bundle.md). 4935 4936| ID| Error Message | 4937| -------- | ------------------------------------------------------------ | 4938| 201 | Permission denied. | 4939| 202 | Not system application to call the interface. | 4940| 1600001 | Internal error. | 4941| 1600002 | Marshalling or unmarshalling error. | 4942| 1600003 | Failed to connect to the service. | 4943| 1600012 | No memory space. | 4944| 17700001 | The specified bundle name was not found. | 4945 4946**Example** 4947 4948```ts 4949import { BusinessError } from '@kit.BasicServicesKit'; 4950import { hilog } from '@kit.PerformanceAnalysisKit'; 4951 4952let bundle: notificationManager.BundleOption = { 4953 bundle: "bundleName1", 4954}; 4955notificationManager.isSilentReminderEnabled(bundle).then((data: notificationManager.SwitchState) => { 4956 hilog.info(0x0000, 'testTag', '%{public}s', `isSilentReminderEnabled success, switchState: ${JSON.stringify(data)}.`); 4957}).catch((err: BusinessError) => { 4958 hilog.error(0x0000, 'testTag', '%{public}s', `isSilentReminderEnabled failed, code is ${err.code}, message is ${err.message}`); 4959}); 4960``` 4961 4962## notificationManager.isDistributedEnabled<sup>20+</sup> 4963 4964isDistributedEnabled(deviceType: string): Promise\<boolean\> 4965 4966Checks whether the device supports cross-device notifications. This API uses a promise to return the result. 4967 4968**System capability**: SystemCapability.Notification.Notification 4969 4970**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 4971 4972**System API**: This is a system API. 4973 4974**Parameters** 4975 4976| Name | Type | Mandatory| Description | 4977| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 4978| deviceType | string | Yes | Device type. The options are as follows:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>- **current**: current device<br>- **2in1**: PC<br>- **tablet**: tablet| 4979 4980**Return value** 4981 4982| Type | Description | 4983|-----------------|-------------------------| 4984| Promise\<boolean\> | Promise used to return the result. The value **true** means that the cross-device notifications are supported, and **false** means the opposite. Promise| 4985 4986**Error codes** 4987 4988For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4989 4990| ID| Error Message | 4991| -------- | ------------------------------------------------------------ | 4992| 201 | Permission denied. | 4993| 202 | Not system application to call the interface. | 4994 4995**Example** 4996 4997```ts 4998import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 4999import { BusinessError } from '@kit.BasicServicesKit'; 5000 5001export default class EntryAbility extends UIAbility { 5002 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 5003 } 5004 5005 onForeground(): void { 5006 try { 5007 let deviceType: string = "wearable"; 5008 notificationManager.isDistributedEnabled(deviceType).then((data: boolean) => { 5009 console.info('isDistributedEnabled succeeded, result = ' + data); 5010 }).catch((err: BusinessError) => { 5011 console.error(`isDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`); 5012 }); 5013 } catch (err) { 5014 console.error(`isDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`); 5015 } 5016 } 5017} 5018``` 5019 5020## notificationManager.setDistributedEnabled<sup>20+</sup> 5021 5022setDistributedEnabled(enable: boolean, deviceType: string): Promise\<void\> 5023 5024Sets whether the device of a specified type supports cross-device notifications. This API uses a promise to return the result. 5025 5026**System capability**: SystemCapability.Notification.Notification 5027 5028**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 5029 5030**System API**: This is a system API. 5031 5032**Parameters** 5033 5034| Name | Type | Mandatory| Description | 5035| -------- | ------------------------------------------------------------ | ---- | ------------------------ | 5036| enable | boolean | Yes | Whether the device of a specified type supports cross-device notifications. The value **true** means cross-device notifications are supported, and **false** means the opposite.| 5037| deviceType | string | Yes | Device type. The options are as follows:<br>- **headset**: wearable audio device<br>- **liteWearable**: lite wearables<br>- **wearable**: wearables<br>- **current**: current device<br>- **2in1**: PC<br>- **tablet**: tablet| 5038 5039**Return value** 5040 5041| Type | Description | 5042|-----------------|-------------------------| 5043| Promise\<void\> | Promise that returns no result.| 5044 5045**Error codes** 5046 5047For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5048 5049| ID| Error Message | 5050| -------- | ------------------------------------------------------------ | 5051| 201 | Permission denied. | 5052| 202 | Not system application to call the interface. | 5053 5054**Example** 5055 5056```ts 5057import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 5058import { BusinessError } from '@kit.BasicServicesKit'; 5059 5060export default class EntryAbility extends UIAbility { 5061 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 5062 } 5063 5064 onForeground(): void { 5065 try { 5066 let isEnable: boolean = true; 5067 let deviceType: string = "wearable"; 5068 notificationManager.setDistributedEnabled(isEnable, deviceType).then(() => { 5069 console.info('setDistributedEnabled succeeded.'); 5070 }).catch((err: BusinessError) => { 5071 console.error(`setDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`); 5072 }); 5073 } catch (err) { 5074 console.error(`setDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`); 5075 } 5076 } 5077} 5078``` 5079 5080## notificationManager.getDistributedDeviceList<sup>20+</sup> 5081 5082getDistributedDeviceList(): Promise\<Array\<string\>\> 5083 5084Obtains the device types that support cross-device notifications. This API uses a promise to return the result. 5085 5086**System capability**: SystemCapability.Notification.Notification 5087 5088**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 5089 5090**System API**: This is a system API. 5091 5092**Return value** 5093 5094| Type | Description | 5095|-----------------|-------------------------| 5096| Promise\<Array\<string\>\> | Promise used to return the list of devices that support cross-device notifications.| 5097 5098**Error codes** 5099 5100For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5101 5102| ID| Error Message | 5103| -------- | ------------------------------------------------------------ | 5104| 201 | Permission denied. | 5105| 202 | Not system application to call the interface. | 5106 5107**Example** 5108 5109```ts 5110import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 5111import { BusinessError } from '@kit.BasicServicesKit'; 5112 5113export default class EntryAbility extends UIAbility { 5114 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 5115 } 5116 5117 onForeground(): void { 5118 try { 5119 notificationManager.getDistributedDeviceList().then((data: Array<string>) => { 5120 console.info('getDistributedDeviceList succeeded, result = ' + data); 5121 }).catch((err: BusinessError) => { 5122 console.error(`getDistributedDeviceList failed. Code is ${err.code}, message is ${err.message}`); 5123 }); 5124 } catch (err) { 5125 console.error(`getDistributedDeviceList failed. Code is ${err.code}, message is ${err.message}`); 5126 } 5127 } 5128} 5129``` 5130 5131## DoNotDisturbDate 5132 5133**System capability**: SystemCapability.Notification.Notification 5134 5135**System API**: This is a system API. 5136 5137| Name | Type | Mandatory| Description | 5138| ----- | ------------------------------------- | ---- | ---------------------- | 5139| type | [DoNotDisturbType](#donotdisturbtype) | Yes | DND time type.| 5140| begin | Date | Yes | DND start time.| 5141| end | Date | Yes | DND end time.| 5142 5143## DoNotDisturbType 5144 5145**System capability**: SystemCapability.Notification.Notification 5146 5147**System API**: This is a system API. 5148 5149| Name | Value | Description | 5150| ------------ | ---------------- | ------------------------------------------ | 5151| TYPE_NONE | 0 | Non-DND. | 5152| TYPE_ONCE | 1 | One-shot DND at the specified time segment (only considering the hour and minute).| 5153| TYPE_DAILY | 2 | Daily DND at the specified time segment (only considering the hour and minute).| 5154| TYPE_CLEARLY | 3 | DND at the specified time segment (with the hour, day, and month specified). | 5155 5156 5157## DeviceRemindType 5158 5159**System capability**: SystemCapability.Notification.Notification 5160 5161**System API**: This is a system API. 5162 5163| Name | Value | Description | 5164| -------------------- | --- | --------------------------------- | 5165| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. | 5166| IDLE_REMIND | 1 | The device is not in use. | 5167| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | 5168| ACTIVE_REMIND | 3 | The device is in use. | 5169 5170 5171## SourceType 5172 5173**System capability**: SystemCapability.Notification.Notification 5174 5175**System API**: This is a system API. 5176 5177| Name | Value | Description | 5178| -------------------- | --- | -------------------- | 5179| TYPE_NORMAL | 0 | Normal notification. | 5180| TYPE_CONTINUOUS | 1 | Continuous notification. | 5181| TYPE_TIMER | 2 | Timed notification. | 5182 5183## NotificationCheckInfo<sup>10+</sup> 5184 5185**System capability**: SystemCapability.Notification.Notification 5186 5187**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 5188 5189**System API**: This is a system API. 5190 5191| Name | Type | Read-Only| Optional| Description | 5192| ---------------------------- | ---------------------------- | ---- | ---- |--------------- | 5193| bundleName | string | No | No | Bundle name. | 5194| notificationId | number | No | No | Notification ID. | 5195| label<sup>11+</sup> | string | No | Yes | Notification label. | 5196| contentType | [ContentType](./js-apis-notificationManager.md#contenttype) | No | No | Notification type. | 5197| creatorUserId<sup>11+</sup> | number | No | No | User ID of the notification.| 5198| slotType<sup>11+</sup> | [SlotType](./js-apis-notificationManager.md#slottype) | No | No | Notification slot type. | 5199| extraInfos<sup>11+</sup> | Record<string, Object> | No | Yes | Extra information about the live view.| 5200 5201## NotificationCheckResult<sup>10+</sup> 5202 5203**System capability**: SystemCapability.Notification.Notification 5204 5205**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 5206 5207**System API**: This is a system API. 5208 5209| Name | Type | Read-Only| Optional| Description | 5210| ------- | ------- | ---- | ---- | ----------------------- | 5211| code | number | No | No | Result code.<br>**0**: display.<br>**1**: no display.| 5212| message | string | No | No | Result. | 5213 5214 5215## ButtonOptions<sup>11+</sup> 5216 5217Provides the button information of the notification. 5218 5219**System capability**: SystemCapability.Notification.Notification 5220 5221**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER 5222 5223**System API**: This is a system API. 5224 5225| Name | Type | Read-Only| Optional| Description | 5226| ---------- | ------ | ---- | ---- | ---------------------- | 5227| buttonName | string | No | No | Button name. | 5228 5229 5230## SystemLiveViewSubscriber<sup>11+</sup> 5231 5232Subscriber of the system live view notification. 5233 5234**System capability**: SystemCapability.Notification.Notification 5235 5236**System API**: This is a system API. 5237 5238 5239| Name | Type | Mandatory| Description | 5240| ------- | ------------------------------------ | ---- | ---------------------- | 5241| onResponse | (notificationId: number, buttonOptions: [ButtonOptions](#buttonoptions11)) => void | No | Callback when the button is touched.| 5242 5243 5244## SlotType 5245 5246**System capability**: SystemCapability.Notification.Notification 5247 5248| Name | Value | Description | 5249| ----------------------------------- | ------ | ------------------------------------------------------------ | 5250| EMERGENCY_INFORMATION<sup>12+</sup> | 10 | Emergency event. **System API**: This is a system API. | 5251 5252 5253## NotificationControlFlagStatus<sup>12+</sup> 5254Each bit can control the notification mode. When the bitwise OR operation is performed on **notificationControlFlags** and the enumerated values in the following table, the notification mode is disabled. 5255 5256**System capability**: SystemCapability.Notification.Notification 5257 5258**System API**: This is a system API. 5259 5260| Name | Value | Description | 5261| ------------------------------------ | ---- | -------- | 5262| NOTIFICATION_STATUS_CLOSE_SOUND | 1<<0 | Disables the sound notification function.| 5263| NOTIFICATION_STATUS_CLOSE_LOCKSCREEN | 1<<1 | Disables the screen lock notification function. | 5264| NOTIFICATION_STATUS_CLOSE_BANNER | 1<<2 | Disables the banner notification function. | 5265| NOTIFICATION_STATUS_CLOSE_LIGHT_SCREEN | 1<<3 | Disables the screen-on notification function. | 5266| NOTIFICATION_STATUS_CLOSE_VIBRATION | 1<<4 | Disables the vibration notification function. | 5267| NOTIFICATION_STATUS_CLOSE_STATUSBAR_ICON | 1<<5 | Disables the icon notification function in the status bar. | 5268 5269## DoNotDisturbProfile<sup>12+</sup> 5270 5271**System capability**: SystemCapability.Notification.Notification 5272 5273**System API**: This is a system API. 5274 5275| Name | Type | Mandatory| Description | 5276| ----- | ------------------------------------- | ---- | ---------------------- | 5277| id | number | Yes| ID of the Do Not Disturb profile.| 5278| name | string | Yes| Name of the Do Not Disturb profile.| 5279| trustlist | Array\<[BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)> | No| Trustlist in Do Not Disturb profile.| 5280 5281## NotificationLiveViewContent<sup>11+</sup> 5282 5283type NotificationLiveViewContent = _NotificationLiveViewContent 5284 5285Describes the common live view. 5286 5287**System capability**: SystemCapability.Notification.Notification 5288 5289**System API**: This is a system API. 5290 5291| Type| Description| 5292| --- | --- | 5293| [_NotificationLiveViewContent](js-apis-inner-notification-notificationContent-sys.md#notificationliveviewcontent11) | Common live view.| 5294 5295## SwitchState<sup>20+</sup> 5296 5297Describes the switch state of notifications. 5298 5299**System capability**: SystemCapability.Notification.Notification 5300 5301**System API**: This is a system API. 5302 5303| Name | Value | Description | 5304| --------------------| --- | --------------------------------- | 5305| USER_MODIFIED_OFF | 0 | Disabled state set by the user. | 5306| USER_MODIFIED_ON | 1 | Enabled state set by the user. | 5307| SYSTEM_DEFAULT_OFF | 2 | Initial disabled state before user settings. | 5308| SYSTEM_DEFAULT_ON | 3 | Initial enabled state before user settings. | 5309