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