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](js-apis-inner-notification-notificationCommonDef.md#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| 1600015 | The current notification status does not support duplicate configurations. | 2692| 1600016 | The notification version for this update is too low. | 2693| 2300007 | Network unreachable. | 2694 2695**示例:** 2696 2697```ts 2698import { BusinessError } from '@kit.BasicServicesKit'; 2699 2700//publishAsBundle回调 2701let callback = (err: BusinessError): void => { 2702 if (err) { 2703 console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`); 2704 } else { 2705 console.info("publishAsBundle success"); 2706 } 2707} 2708// 被代理应用的包名 2709let representativeBundle: string = "com.example.demo"; 2710// 用户ID,使用时需替换为真实的userId。 2711let userId: number = 100; 2712// NotificationRequest对象 2713let request: notificationManager.NotificationRequest = { 2714 id: 1, 2715 content: { 2716 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2717 normal: { 2718 title: "test_title", 2719 text: "test_text", 2720 additionalText: "test_additionalText" 2721 } 2722 } 2723}; 2724notificationManager.publishAsBundle(request, representativeBundle, userId, callback); 2725``` 2726 2727## notificationManager.publishAsBundle 2728 2729publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\> 2730 2731发布代理通知。使用Promise异步回调。 2732 2733**系统能力**:SystemCapability.Notification.Notification 2734 2735**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER,ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2736 2737**系统接口**: 此接口为系统接口。 2738 2739**参数:** 2740 2741 2742| 参数名 | 类型 | 必填 | 说明 | 2743| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | 2744| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 2745| representativeBundle | string | 是 | 被代理应用的包名。 | 2746| userId | number | 是 | 用户ID。 | 2747 2748**返回值:** 2749 2750| 类型 | 说明 | 2751|-----------------|-----------| 2752| Promise\<void\> | 无返回结果的Promise对象。 | 2753 2754**错误码:** 2755 2756以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 2757 2758| 错误码ID | 错误信息 | 2759| -------- | ----------------------------------------- | 2760| 201 | Permission denied. | 2761| 202 | Not system application to call the interface. | 2762| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2763| 1600001 | Internal error. | 2764| 1600002 | Marshalling or unmarshalling error. | 2765| 1600003 | Failed to connect to the service. | 2766| 1600004 | Notification disabled. | 2767| 1600005 | Notification slot disabled. | 2768| 1600007 | The notification does not exist. | 2769| 1600008 | The user does not exist. | 2770| 1600009 | Over max number notifications per second. | 2771| 1600012 | No memory space. | 2772| 1600015 | The current notification status does not support duplicate configurations. | 2773| 1600016 | The notification version for this update is too low. | 2774| 2300007 | Network unreachable. | 2775 2776**示例:** 2777 2778```ts 2779import { BusinessError } from '@kit.BasicServicesKit'; 2780 2781// 被代理应用的包名 2782let representativeBundle: string = "com.example.demo"; 2783// 用户ID,使用时需替换为真实的userId。 2784let userId: number = 100; 2785// NotificationRequest对象 2786let request: notificationManager.NotificationRequest = { 2787 id: 1, 2788 content: { 2789 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2790 normal: { 2791 title: "test_title", 2792 text: "test_text", 2793 additionalText: "test_additionalText" 2794 } 2795 } 2796}; 2797notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => { 2798 console.info("publishAsBundle success"); 2799}).catch((err: BusinessError) => { 2800 console.error(`publishAsBundle fail: ${JSON.stringify(err)}`); 2801}); 2802``` 2803 2804## notificationManager.publishAsBundle<sup>12+</sup> 2805 2806publishAsBundle(representativeBundle: BundleOption, request: NotificationRequest): Promise\<void\> 2807 2808发布代理通知。使用Promise异步回调。 2809 2810**系统能力**:SystemCapability.Notification.Notification 2811 2812**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER,ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2813 2814**系统接口**: 此接口为系统接口。 2815 2816**参数:** 2817 2818 2819| 参数名 | 类型 | 必填 | 说明 | 2820|----------------------|--------------------------------------------|------|-----------------------------------------------| 2821| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 被代理应用的包信息。 | 2822| request | [NotificationRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 2823 2824**返回值:** 2825 2826| 类型 | 说明 | 2827|-----------------|-----------| 2828| Promise\<void\> | 无返回结果的Promise对象。 | 2829 2830**错误码:** 2831 2832以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 2833 2834| 错误码ID | 错误信息 | 2835| -------- | ----------------------------------------- | 2836| 201 | Permission denied. | 2837| 202 | Not system application to call the interface. | 2838| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2839| 1600001 | Internal error. | 2840| 1600002 | Marshalling or unmarshalling error. | 2841| 1600003 | Failed to connect to the service. | 2842| 1600004 | Notification is not enabled. | 2843| 1600005 | Notification slot disabled. | 2844| 1600007 | The notification does not exist. | 2845| 1600008 | The user does not exist. | 2846| 1600009 | Over max number notifications per second. | 2847| 1600012 | No memory space. | 2848| 1600015 | The current notification status does not support duplicate configurations. | 2849| 1600016 | The notification version for this update is too low. | 2850| 2300007 | Network unreachable. | 2851 2852**示例:** 2853 2854```ts 2855import { BusinessError } from '@kit.BasicServicesKit'; 2856 2857// 被代理应用的包信息 2858let representativeBundle: notificationManager.BundleOption = { 2859 bundle: "bundleName1", 2860}; 2861// NotificationRequest对象 2862let request: notificationManager.NotificationRequest = { 2863 id: 1, 2864 content: { 2865 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2866 normal: { 2867 title: "test_title", 2868 text: "test_text", 2869 additionalText: "test_additionalText" 2870 } 2871 } 2872}; 2873notificationManager.publishAsBundle(representativeBundle, request).then(() => { 2874 console.info("publishAsBundle success"); 2875}).catch((err: BusinessError) => { 2876 console.error(`publishAsBundle fail: ${JSON.stringify(err)}`); 2877}); 2878``` 2879 2880## notificationManager.cancelAsBundle 2881 2882cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void 2883 2884取消代理通知。使用callback异步回调。 2885 2886**系统能力**:SystemCapability.Notification.Notification 2887 2888**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER,ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2889 2890**系统接口**: 此接口为系统接口。 2891 2892**参数:** 2893 2894| 参数名 | 类型 | 必填 | 说明 | 2895| -------------------- | ------------- | ---- | ------------------------ | 2896| id | number | 是 | 通知ID。 | 2897| representativeBundle | string | 是 | 被代理应用的包名。 | 2898| userId | number | 是 | 用户ID。 | 2899| callback | AsyncCallback\<void\> | 是 | 取消代理通知的回调方法。 | 2900 2901**错误码:** 2902 2903以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 2904 2905| 错误码ID | 错误信息 | 2906| -------- | ----------------------------------- | 2907| 201 | Permission denied. | 2908| 202 | Not system application to call the interface. | 2909| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2910| 1600001 | Internal error. | 2911| 1600002 | Marshalling or unmarshalling error. | 2912| 1600003 | Failed to connect to the service. | 2913| 1600007 | The notification does not exist. | 2914| 1600008 | The user does not exist. | 2915| 17700001 | The specified bundle name was not found. | 2916 2917**示例:** 2918 2919```ts 2920import { BusinessError } from '@kit.BasicServicesKit'; 2921 2922// cancelAsBundle 2923let cancelAsBundleCallback = (err: BusinessError): void => { 2924 if (err) { 2925 console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`); 2926 } else { 2927 console.info("cancelAsBundle success"); 2928 } 2929} 2930// 被代理应用的包名 2931let representativeBundle: string = "com.example.demo"; 2932// 用户ID,使用时需替换为真实的userId。 2933let userId: number = 100; 2934notificationManager.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); 2935``` 2936 2937## notificationManager.cancelAsBundle 2938 2939cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\> 2940 2941取消代理通知。使用Promise异步回调。 2942 2943**系统能力**:SystemCapability.Notification.Notification 2944 2945**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER,ohos.permission.NOTIFICATION_AGENT_CONTROLLER 2946 2947**系统接口**: 此接口为系统接口。 2948 2949**参数:** 2950 2951| 参数名 | 类型 | 必填 | 说明 | 2952| -------------------- | ------ | ---- | ------------------ | 2953| id | number | 是 | 通知ID。 | 2954| representativeBundle | string | 是 | 被代理应用的包名。 | 2955| userId | number | 是 | 用户ID。 | 2956 2957**返回值:** 2958 2959| 类型 | 说明 | 2960|-----------------|-----------| 2961| Promise\<void\> | 无返回结果的Promise对象。 | 2962 2963**错误码:** 2964 2965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 2966 2967| 错误码ID | 错误信息 | 2968| -------- | ----------------------------------- | 2969| 201 | Permission denied. | 2970| 202 | Not system application to call the interface. | 2971| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 2972| 1600001 | Internal error. | 2973| 1600002 | Marshalling or unmarshalling error. | 2974| 1600003 | Failed to connect to the service. | 2975| 1600007 | The notification does not exist. | 2976| 1600008 | The user does not exist. | 2977| 17700001 | The specified bundle name was not found. | 2978 2979**示例:** 2980 2981```ts 2982import { BusinessError } from '@kit.BasicServicesKit'; 2983 2984// 被代理应用的包名 2985let representativeBundle: string = "com.example.demo"; 2986// 用户ID,使用时需替换为真实的userId。 2987let userId: number = 100; 2988notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => { 2989 console.info("cancelAsBundle success"); 2990}).catch((err: BusinessError) => { 2991 console.error(`cancelAsBundle fail: ${JSON.stringify(err)}`); 2992}); 2993``` 2994 2995 2996## notificationManager.cancelAsBundle<sup>12+</sup> 2997 2998cancelAsBundle(representativeBundle: BundleOption, id: number): Promise\<void\> 2999 3000取消代理通知。使用Promise异步回调。 3001 3002**系统能力**:SystemCapability.Notification.Notification 3003 3004**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER,ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3005 3006**系统接口**: 此接口为系统接口。 3007 3008**参数:** 3009 3010 3011| 参数名 | 类型 | 必填 | 说明 | 3012| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | 3013| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) |是 | 被代理应用的包信息。 | 3014| id | number | 是 | 通知ID。 | 3015 3016**返回值:** 3017 3018| 类型 | 说明 | 3019|-----------------|-----------| 3020| Promise\<void\> | 无返回结果的Promise对象。 | 3021 3022**错误码:** 3023 3024以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3025 3026| 错误码ID | 错误信息 | 3027| -------- | ----------------------------------------- | 3028| 201 | Permission denied. | 3029| 202 | Not system application to call the interface. | 3030| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3031| 1600001 | Internal error. | 3032| 1600002 | Marshalling or unmarshalling error. | 3033| 1600003 | Failed to connect to the service. | 3034| 1600007 | The notification does not exist. | 3035| 1600008 | The user does not exist. | 3036| 1600012 | No memory space. | 3037| 17700001 | The specified bundle name was not found. | 3038 3039**示例:** 3040 3041```ts 3042import { BusinessError } from '@kit.BasicServicesKit'; 3043 3044let representativeBundle: notificationManager.BundleOption = { 3045 bundle: "bundleName1", 3046}; 3047notificationManager.cancelAsBundle(representativeBundle, 1).then(() => { 3048 console.info("cancelAsBundle success"); 3049}).catch((err: BusinessError) => { 3050 console.error(`cancelAsBundle fail: ${JSON.stringify(err)}`); 3051}); 3052``` 3053 3054## notificationManager.cancel<sup>12+</sup> 3055 3056cancel(representativeBundle: BundleOption, id: number): Promise\<void\> 3057 3058代理取消当前用户其他应用的通知。使用Promise异步回调。 3059 3060需要当前应用与其他应用存在代理关系,或者当前应用有ohos.permission.NOTIFICATION_AGENT_CONTROLLER权限。 3061 3062**系统能力**:SystemCapability.Notification.Notification 3063 3064**系统接口**: 此接口为系统接口。 3065 3066**参数:** 3067 3068| 参数名 | 类型 | 必填 | 说明 | 3069| -------------------- | ------ | ---- | ------------------ | 3070| representativeBundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3071| id | number | 是 | 通知ID。 | 3072 3073**返回值:** 3074 3075| 类型 | 说明 | 3076|-----------------|-----------| 3077| Promise\<void\> | 无返回结果的Promise对象。 | 3078 3079**错误码:** 3080 3081以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3082 3083| 错误码ID | 错误信息 | 3084| -------- | ----------------------------------- | 3085| 202 | Not system application to call the interface. | 3086| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3087| 1600001 | Internal error. | 3088| 1600002 | Marshalling or unmarshalling error. | 3089| 1600003 | Failed to connect to the service. | 3090| 1600007 | The notification does not exist. | 3091| 1600012 | No memory space. | 3092| 1600017 | There is no corresponding agent relationship configuration. | 3093 3094**示例:** 3095 3096```ts 3097import { BusinessError } from '@kit.BasicServicesKit'; 3098 3099let bundle: notificationManager.BundleOption = { 3100 bundle: "bundleName" 3101}; 3102let id: number = 1; 3103notificationManager.cancel(bundle, id).then(() => { 3104 console.info("cancel success"); 3105}).catch((err: BusinessError) => { 3106 console.error(`cancel fail: ${JSON.stringify(err)}`); 3107}); 3108``` 3109 3110## notificationManager.setNotificationEnableSlot 3111 3112setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void 3113 3114设置指定应用的指定渠道类型的使能状态。使用callback异步回调。 3115 3116**系统能力**:SystemCapability.Notification.Notification 3117 3118**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3119 3120**系统接口**:此接口为系统接口。 3121 3122**参数:** 3123 3124| 参数名 | 类型 | 必填 | 说明 | 3125| -------- | ----------------------------- | ---- | ---------------------- | 3126| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3127| type | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 指定渠道类型。 | 3128| enable | boolean | 是 | 使能状态(true:使能,false:禁止)。 | 3129| callback | AsyncCallback\<void\> | 是 | 设置渠道使能回调函数。 | 3130 3131**错误码:** 3132 3133以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3134 3135| 错误码ID | 错误信息 | 3136| -------- | ---------------------------------------- | 3137| 201 | Permission denied. | 3138| 202 | Not system application to call the interface. | 3139| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3140| 1600001 | Internal error. | 3141| 1600002 | Marshalling or unmarshalling error. | 3142| 1600003 | Failed to connect to the service. | 3143| 1600012 | No memory space. | 3144| 17700001 | The specified bundle name was not found. | 3145 3146**示例:** 3147 3148```ts 3149import { BusinessError } from '@kit.BasicServicesKit'; 3150 3151// setNotificationEnableSlot 3152let setNotificationEnableSlotCallback = (err: BusinessError): void => { 3153 if (err) { 3154 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3155 } else { 3156 console.info("setNotificationEnableSlot success"); 3157 } 3158}; 3159notificationManager.setNotificationEnableSlot( 3160 { bundle: "ohos.samples.notification", }, 3161 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3162 true, 3163 setNotificationEnableSlotCallback); 3164``` 3165 3166## notificationManager.setNotificationEnableSlot<sup>11+</sup> 3167 3168setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl: boolean, callback: AsyncCallback\<void>): void 3169 3170设置指定应用的指定渠道类型的使能状态。使用callback异步回调。 3171 3172**系统能力**:SystemCapability.Notification.Notification 3173 3174**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3175 3176**系统接口**:此接口为系统接口。 3177 3178**参数:** 3179 3180| 参数名 | 类型 | 必填 | 说明 | 3181| -------- | ----------------------------- | ---- | ----------------------- | 3182| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。| 3183| type | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 指定渠道类型。 | 3184| enable | boolean | 是 | 使能状态(true:使能,false:禁止)。 | 3185| isForceControl<sup>11+</sup> | boolean | 是 | 渠道开关是否受通知授权开关影响(false:受影响,true:不受影响)。 | 3186| callback | AsyncCallback\<void\> | 是 | 设置渠道使能回调函数。 | 3187 3188**错误码:** 3189 3190以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3191 3192| 错误码ID | 错误信息 | 3193| -------- | ---------------------------------------- | 3194| 201 | Permission denied. | 3195| 202 | Not system application to call the interface. | 3196| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3197| 1600001 | Internal error. | 3198| 1600002 | Marshalling or unmarshalling error. | 3199| 1600003 | Failed to connect to the service. | 3200| 1600012 | No memory space. | 3201| 17700001 | The specified bundle name was not found. | 3202 3203**示例:** 3204 3205```ts 3206import { BusinessError } from '@kit.BasicServicesKit'; 3207 3208let setNotificationEnableSlotCallback = (err: BusinessError): void => { 3209 if (err) { 3210 console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`); 3211 } else { 3212 console.info("setNotificationEnableSlot success"); 3213 } 3214}; 3215 3216notificationManager.setNotificationEnableSlot( 3217 { bundle: "ohos.samples.notification", }, 3218 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3219 true, 3220 false, 3221 setNotificationEnableSlotCallback); 3222``` 3223 3224## notificationManager.setNotificationEnableSlot 3225 3226setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl?: boolean): Promise\<void> 3227 3228设置指定应用的指定渠道类型的使能状态。使用promise异步回调。 3229 3230**系统能力**:SystemCapability.Notification.Notification 3231 3232**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3233 3234**系统接口**:此接口为系统接口。 3235 3236**参数:** 3237 3238| 参数名 | 类型 | 必填 | 说明 | 3239| ------ | ----------------------------- | ---- | -------------- | 3240| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3241| type | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 渠道类型。 | 3242| enable | boolean | 是 | 使能状态(true:使能,false:禁止)。 | 3243| isForceControl<sup>11+</sup> | boolean | 否 | 渠道开关是否受通知总开关影响(false:受总开关影响,true:不受总开关影响)。默认为false。 | 3244 3245**错误码:** 3246 3247以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3248 3249| 错误码ID | 错误信息 | 3250| -------- | ---------------------------------------- | 3251| 201 | Permission denied. | 3252| 202 | Not system application to call the interface. | 3253| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3254| 1600001 | Internal error. | 3255| 1600002 | Marshalling or unmarshalling error. | 3256| 1600003 | Failed to connect to the service. | 3257| 1600012 | No memory space. | 3258| 17700001 | The specified bundle name was not found. | 3259 3260**示例:** 3261 3262```ts 3263import { BusinessError } from '@kit.BasicServicesKit'; 3264 3265// setNotificationEnableSlot 3266notificationManager.setNotificationEnableSlot( 3267 { bundle: "ohos.samples.notification", }, 3268 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3269 true).then(() => { 3270 console.info("setNotificationEnableSlot success"); 3271 }).catch((err: BusinessError) => { 3272 console.error(`setNotificationEnableSlot fail: ${JSON.stringify(err)}`); 3273 }); 3274``` 3275 3276## notificationManager.isNotificationSlotEnabled 3277 3278isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void 3279 3280获取指定应用的指定渠道类型的使能状态。使用callback异步回调。 3281 3282**系统能力**:SystemCapability.Notification.Notification 3283 3284**系统接口**:此接口为系统接口。 3285 3286**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3287 3288**参数:** 3289 3290| 参数名 | 类型 | 必填 | 说明 | 3291| -------- | ----------------------------- | ---- | ---------------------- | 3292| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3293| type | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 渠道类型。 | 3294| callback | AsyncCallback\<boolean\> | 是 | 获取渠道使能状态回调函数(true:使能,false:禁止)。 | 3295 3296**错误码:** 3297 3298以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3299 3300| 错误码ID | 错误信息 | 3301| -------- | ---------------------------------------- | 3302| 201 | Permission denied. | 3303| 202 | Not system application to call the interface. | 3304| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3305| 1600001 | Internal error. | 3306| 1600002 | Marshalling or unmarshalling error. | 3307| 1600003 | Failed to connect to the service. | 3308| 17700001 | The specified bundle name was not found. | 3309 3310**示例:** 3311 3312```ts 3313import { BusinessError } from '@kit.BasicServicesKit'; 3314 3315// isNotificationSlotEnabledCallback 3316let isNotificationSlotEnabledCallback = (err: BusinessError, data: boolean): void => { 3317 if (err) { 3318 console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`); 3319 } else { 3320 console.info(`isNotificationSlotEnabled success, data is ${JSON.stringify(data)}`); 3321 } 3322}; 3323 3324notificationManager.isNotificationSlotEnabled( 3325 { bundle: "ohos.samples.notification", }, 3326 notificationManager.SlotType.SOCIAL_COMMUNICATION, 3327 isNotificationSlotEnabledCallback); 3328``` 3329 3330## notificationManager.isNotificationSlotEnabled 3331 3332isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\> 3333 3334获取指定应用的指定渠道类型的使能状态。使用Promise异步回调。 3335 3336**系统能力**:SystemCapability.Notification.Notification 3337 3338**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3339 3340**系统接口**:此接口为系统接口。 3341 3342**参数:** 3343 3344| 参数名 | 类型 | 必填 | 说明 | 3345| ------ | ----------------------------- | ---- | -------------- | 3346| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3347| type | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 渠道类型。 | 3348 3349**返回值:** 3350 3351| 类型 | 说明 | 3352| ----------------------------------------------------------- | ------------------------------------------------------------ | 3353| Promise\<boolean\> | 以Promise形式返回指定类型的渠道使能状态(true:使能,false:禁止)。 | 3354 3355**错误码:** 3356 3357以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3358 3359| 错误码ID | 错误信息 | 3360| -------- | ---------------------------------------- | 3361| 201 | Permission denied. | 3362| 202 | Not system application to call the interface. | 3363| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3364| 1600001 | Internal error. | 3365| 1600002 | Marshalling or unmarshalling error. | 3366| 1600003 | Failed to connect to the service. | 3367| 17700001 | The specified bundle name was not found. | 3368 3369**示例:** 3370 3371```ts 3372import { BusinessError } from '@kit.BasicServicesKit'; 3373 3374// isNotificationSlotEnabled 3375notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, 3376 notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data: boolean) => { 3377 console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); 3378}).catch((err: BusinessError) => { 3379 console.error(`isNotificationSlotEnabled fail: ${JSON.stringify(err)}`); 3380}); 3381``` 3382 3383 3384## notificationManager.setSyncNotificationEnabledWithoutApp 3385 3386setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void 3387 3388设置是否将通知同步到未安装应用程序的设备(callback形式)。 3389 3390**系统能力**:SystemCapability.Notification.Notification 3391 3392**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3393 3394**系统接口**:此接口为系统接口。 3395 3396**参数:** 3397 3398| 参数名 | 类型 | 必填 | 说明 | 3399| ------ | ----------------------------- | ---- | -------------- | 3400| userId | number | 是 | 用户ID。 | 3401| enable | boolean | 是 | 是否启用(true:使能,false:禁止)。 | 3402| callback | AsyncCallback\<void\> | 是 | 设置是否将通知同步到未安装应用程序的设备的回调函数。 | 3403 3404**错误码:** 3405 3406以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3407 3408| 错误码ID | 错误信息 | 3409| -------- | ----------------------------------- | 3410| 201 | Permission denied. | 3411| 202 | Not system application to call the interface. | 3412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3413| 1600001 | Internal error. | 3414| 1600002 | Marshalling or unmarshalling error. | 3415| 1600003 | Failed to connect to the service. | 3416| 1600008 | The user does not exist. | 3417 3418**示例:** 3419 3420```ts 3421import { BusinessError } from '@kit.BasicServicesKit'; 3422 3423// 用户ID,使用时需替换为真实的userId。 3424let userId: number = 100; 3425let enable: boolean = true; 3426let setSyncNotificationEnabledWithoutAppCallback = (err: BusinessError): void => { 3427 if (err) { 3428 console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`); 3429 } else { 3430 console.info("setSyncNotificationEnabledWithoutApp success"); 3431 } 3432} 3433notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); 3434``` 3435 3436 3437## notificationManager.setSyncNotificationEnabledWithoutApp 3438 3439setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void> 3440 3441设置是否将通知同步到未安装应用程序的设备(Promise形式)。 3442 3443**系统能力**:SystemCapability.Notification.Notification 3444 3445**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3446 3447**系统接口**:此接口为系统接口。 3448 3449**参数:** 3450 3451| 参数名 | 类型 | 必填 | 说明 | 3452| ------ | ----------------------------- | ---- | -------------- | 3453| userId | number | 是 | 用户ID。 | 3454| enable | boolean | 是 | 是否启用(true:使能,false:禁止)。 | 3455 3456**返回值:** 3457 3458| 类型 | 说明 | 3459| ----------------------------------------------------------- | ------------------------------------------------------------ | 3460| Promise\<void\> | 以Promise形式返回设置是否将通知同步到未安装应用程序的设备的结果。 | 3461 3462**错误码:** 3463 3464以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3465 3466| 错误码ID | 错误信息 | 3467| -------- | ----------------------------------- | 3468| 201 | Permission denied. | 3469| 202 | Not system application to call the interface. | 3470| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3471| 1600001 | Internal error. | 3472| 1600002 | Marshalling or unmarshalling error. | 3473| 1600003 | Failed to connect to the service. | 3474| 1600008 | The user does not exist. | 3475 3476**示例:** 3477 3478```ts 3479import { BusinessError } from '@kit.BasicServicesKit'; 3480 3481// 用户ID,使用时需替换为真实的userId。 3482let userId: number = 100; 3483let enable: boolean = true; 3484notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { 3485 console.info('setSyncNotificationEnabledWithoutApp success'); 3486}).catch((err: BusinessError) => { 3487 console.error(`setSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`); 3488}); 3489``` 3490 3491 3492## notificationManager.getSyncNotificationEnabledWithoutApp 3493 3494getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void 3495 3496获取同步通知到未安装应用程序设备的开关是否开启(callback形式)。 3497 3498**系统能力**:SystemCapability.Notification.Notification 3499 3500**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3501 3502**系统接口**:此接口为系统接口。 3503 3504**参数:** 3505 3506| 参数名 | 类型 | 必填 | 说明 | 3507| ------ | ----------------------------- | ---- | -------------- | 3508| userId | number | 是 | 用户ID。 | 3509| callback | AsyncCallback\<boolean\> | 是 | 获取同步通知到未安装应用程序设备的开关是否开启的回调函数(true:开启,false:未开启)。 | 3510 3511**错误码:** 3512 3513以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3514 3515| 错误码ID | 错误信息 | 3516| -------- | ----------------------------------- | 3517| 201 | Permission denied. | 3518| 202 | Not system application to call the interface. | 3519| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3520| 1600001 | Internal error. | 3521| 1600002 | Marshalling or unmarshalling error. | 3522| 1600003 | Failed to connect to the service. | 3523| 1600008 | The user does not exist. | 3524 3525**示例:** 3526 3527```ts 3528import { BusinessError } from '@kit.BasicServicesKit'; 3529 3530// 用户ID,使用时需替换为真实的userId。 3531let userId: number = 100; 3532let getSyncNotificationEnabledWithoutAppCallback = (err: BusinessError, data: boolean): void => { 3533 if (err) { 3534 console.error(`getSyncNotificationEnabledWithoutAppCallback failed, code is ${err.code}, message is ${err.message}`); 3535 } else { 3536 console.info("getSyncNotificationEnabledWithoutAppCallback success, data: " + JSON.stringify(data)); 3537 } 3538} 3539notificationManager.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback); 3540``` 3541 3542 3543## notificationManager.getSyncNotificationEnabledWithoutApp 3544 3545getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean> 3546 3547获取同步通知到未安装应用程序设备的开关是否开启(Promise形式)。 3548 3549**系统能力**:SystemCapability.Notification.Notification 3550 3551**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3552 3553**系统接口**:此接口为系统接口。 3554 3555**参数:** 3556 3557| 参数名 | 类型 | 必填 | 说明 | 3558| ------ | ----------------------------- | ---- | -------------- | 3559| userId | number | 是 | 用户ID。 | 3560 3561**返回值:** 3562 3563| 类型 | 说明 | 3564| ------------------ | ------------------------------------------------------------ | 3565| Promise\<boolean\> | 以Promise形式返回获取同步通知到未安装应用程序设备的开关是否开启的结果(true:开启,false:未开启)。 | 3566 3567**错误码:** 3568 3569以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3570 3571| 错误码ID | 错误信息 | 3572| -------- | ----------------------------------- | 3573| 201 | Permission denied. | 3574| 202 | Not system application to call the interface. | 3575| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3576| 1600001 | Internal error. | 3577| 1600002 | Marshalling or unmarshalling error. | 3578| 1600003 | Failed to connect to the service. | 3579| 1600008 | The user does not exist. | 3580 3581**示例:** 3582 3583```ts 3584import { BusinessError } from '@kit.BasicServicesKit'; 3585 3586// 用户ID,使用时需替换为真实的userId。 3587let userId: number = 100; 3588notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data: boolean) => { 3589 console.info('getSyncNotificationEnabledWithoutApp, data: ' + JSON.stringify(data)); 3590}).catch((err: BusinessError) => { 3591 console.error(`getSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`); 3592}); 3593``` 3594 3595## notificationManager.on<sup>10+</sup> 3596 3597on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void 3598 3599注册通知监听回调。通知服务将通知信息回调给校验程序,校验程序返回校验结果决定该通知是否发布,如营销类通知发布频率控制等。 3600 3601系统中每个[SlotType](./js-apis-notificationManager.md#slottype)只允许存在一个注册者。 3602 3603**系统能力**:SystemCapability.Notification.Notification 3604 3605**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3606 3607**系统接口**:此接口为系统接口。 3608 3609**参数:** 3610 3611| 参数名 | 类型 | 必填 | 说明 | 3612| ------ |-------------------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3613| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 | 3614| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | 是 | 消息验证函数指针。 | 3615 3616**错误码:** 3617 3618以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3619 3620| 错误码ID | 错误信息 | 3621| -------- | ----------------------------------- | 3622| 202 | Not system application. | 3623| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3624| 1600001 | Internal error. | 3625 3626**示例:** 3627 3628```ts 3629import { BusinessError } from '@kit.BasicServicesKit'; 3630 3631let onCheckNotification = (info : notificationManager.NotificationCheckInfo): notificationManager.NotificationCheckResult => { 3632 console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`); 3633 if(info.notificationId == 1){ 3634 let result: notificationManager.NotificationCheckResult = { code: 1, message: "testMsg1"}; 3635 return result; 3636 } else { 3637 let result: notificationManager.NotificationCheckResult = { code: 0, message: "testMsg0"}; 3638 return result; 3639 } 3640} 3641try{ 3642 notificationManager.on("checkNotification", onCheckNotification); 3643} catch (error){ 3644 console.error(`notificationManager.on error: ${JSON.stringify(error as BusinessError)}`); 3645} 3646``` 3647 3648## notificationManager.on<sup>11+</sup> 3649 3650on(type: 'checkNotification', checkRequest: NotificationCheckRequest, callback: (checkInfo: NotificationCheckInfo) => Promise\<NotificationCheckResult\>): void 3651 3652注册通知监听回调。通知服务将通知信息回调给校验程序,校验程序返回校验结果决定该通知是否发布,如营销类通知发布频率控制等。使用Promise异步回调。 3653 3654系统中每个[SlotType](./js-apis-notificationManager.md#slottype)只允许存在一个注册者。 3655 3656**系统能力**:SystemCapability.Notification.Notification 3657 3658**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3659 3660**系统接口**:此接口为系统接口。 3661 3662**参数:** 3663 3664| 参数名 | 类型 | 必填 | 说明 | 3665| ------ |-----------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3666| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 | 3667| checkRequest | [NotificationCheckRequest](js-apis-inner-notification-notificationRequest-sys.md#notificationcheckrequest11) | 是 | 通知请求验证内容。 | 3668| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => Promise\<[NotificationCheckResult](#notificationcheckresult10)\> | 是 | 消息验证函数指针。 | 3669 3670**错误码:** 3671 3672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3673 3674| 错误码ID | 错误信息 | 3675| -------- | ----------------------------------- | 3676| 201 | Permission denied. | 3677| 202 | Not system application. | 3678| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3679| 1600001 | Internal error. | 3680| 1600002 | Marshalling or unmarshalling error. | 3681| 1600003 | Failed to connect to the service. | 3682 3683**示例:** 3684 3685```ts 3686import { BusinessError } from '@kit.BasicServicesKit'; 3687 3688try{ 3689 notificationManager.on('checkNotification',{ 3690 contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LIVE_VIEW, 3691 slotType: notificationManager.SlotType.LIVE_VIEW , 3692 extraInfoKeys: ["event"], 3693 }, 3694 async (checkInfo)=>{ 3695 return { code: 1, message: "INVALID_PARAMETERS"}; 3696 },); 3697} catch (error) { 3698 console.error(`notificationManager.on error: ${JSON.stringify(error as BusinessError)}`); 3699} 3700``` 3701 3702## notificationManager.off<sup>10+</sup> 3703 3704off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void 3705 3706取消通知监听回调。 3707 3708**系统能力**:SystemCapability.Notification.Notification 3709 3710**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 3711 3712**系统接口**:此接口为系统接口。 3713 3714**参数:** 3715 3716| 参数名 | 类型 | 必填 | 说明 | 3717| ------ |-------------------------------------------------------------------------------------------------------------------------| ---- | -------------- | 3718| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 | 3719| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo10)) => [NotificationCheckResult](#notificationcheckresult10) | 否 | 消息验证函数指针。 | 3720 3721**错误码:** 3722 3723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3724 3725| 错误码ID | 错误信息 | 3726| -------- | ----------------------------------- | 3727| 201 | The application dose not have permission to call the interface. | 3728| 202 | Not system application. | 3729| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3730| 1600001 | Internal error. | 3731 3732**示例:** 3733 3734```ts 3735import { BusinessError } from '@kit.BasicServicesKit'; 3736 3737try{ 3738 notificationManager.off("checkNotification"); 3739} catch (error){ 3740 console.error(`notificationManager.off error: ${JSON.stringify(error as BusinessError)}`); 3741} 3742``` 3743 3744## notificationManager.triggerSystemLiveView<sup>11+</sup> 3745 3746triggerSystemLiveView(bundle: BundleOption, notificationId: number, buttonOptions: ButtonOptions): Promise\<void> 3747 3748触发系统实况窗。使用Promise异步回调。 3749 3750**系统能力**:SystemCapability.Notification.Notification 3751 3752**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 3753 3754**系统接口**:此接口为系统接口。 3755 3756**参数:** 3757 3758| 参数名 | 类型 | 必填 | 说明 | 3759| -------------- | ------------- | ---- | -------------- | 3760| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 |指定应用的包信息。 | 3761| notificationId | number | 是 | 通知ID。 | 3762| buttonOptions | [ButtonOptions](#buttonoptions11) | 是 | 按钮信息。 | 3763 3764**返回值:** 3765 3766| 类型 | 说明 | 3767| ---- | ----| 3768| Promise\<void> | 无返回结果的Promise对象。 | 3769 3770**错误码:** 3771 3772以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3773 3774| 错误码ID | 错误信息 | 3775| -------- | ----------------------------------- | 3776| 201 | Permission denied. | 3777| 202 | Not system application to call the interface. | 3778| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3779| 1600001 | Internal error. | 3780| 1600002 | Marshalling or unmarshalling error. | 3781| 1600003 | Failed to connect to the service. | 3782| 1600007 | The notification does not exist. | 3783| 17700001 | The specified bundle name was not found. | 3784 3785**示例:** 3786 3787```ts 3788import { BusinessError } from '@kit.BasicServicesKit'; 3789 3790// 包信息 3791let bundle: notificationManager.BundleOption = { 3792 bundle: "bundleName1", 3793}; 3794// 通知ID 3795let notificationId = 1; 3796// 按钮信息 3797let buttonOptions: notificationManager.ButtonOptions = { 3798 buttonName: "buttonName1", 3799} 3800notificationManager.triggerSystemLiveView(bundle, notificationId, buttonOptions).then(() => { 3801 console.info("triggerSystemLiveView success"); 3802}).catch((error: BusinessError) => { 3803 console.error(`triggerSystemLiveView fail: ${JSON.stringify(error)}`); 3804}); 3805``` 3806 3807 3808## notificationManager.subscribeSystemLiveView<sup>11+</sup> 3809 3810subscribeSystemLiveView(subscriber: SystemLiveViewSubscriber): Promise\<void> 3811 3812订阅系统实况窗。使用Promise异步回调。 3813 3814**系统能力**:SystemCapability.Notification.Notification 3815 3816**系统接口**:此接口为系统接口。 3817 3818**参数:** 3819 3820| 参数名 | 类型 | 必填 | 说明 | 3821| -------------- | ------------- | ---- | -------------- | 3822| subscriber | [SystemLiveViewSubscriber](#systemliveviewsubscriber11) | 是 | 系统实况窗订阅者。| 3823 3824**返回值:** 3825 3826| 类型 | 说明 | 3827| ---- | ----| 3828| Promise\<void> | 无返回结果的Promise对象。 | 3829 3830**错误码:** 3831 3832以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3833 3834| 错误码ID | 错误信息 | 3835| -------- | ----------------------------------- | 3836| 202 | Not system application to call the interface. | 3837| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3838| 1600001 | Internal error. | 3839| 1600002 | Marshalling or unmarshalling error. | 3840| 1600003 | Failed to connect to the service. | 3841| 1600012 | No memory space. | 3842 3843**示例:** 3844 3845```ts 3846import { BusinessError } from '@kit.BasicServicesKit'; 3847 3848let onResponseCallback = (id:number, option:notificationManager.ButtonOptions) => { 3849 console.info("onResponseCallback: " + JSON.stringify(option) + "notificationId" + id); 3850} 3851let subscriber: notificationManager.SystemLiveViewSubscriber = { 3852 onResponse: onResponseCallback, 3853}; 3854notificationManager.subscribeSystemLiveView(subscriber).then(() => { 3855 console.info("subscribeSystemLiveView success"); 3856}).catch((error: BusinessError) => { 3857 console.error(`subscribeSystemLiveView fail: ${JSON.stringify(error)}`); 3858}); 3859``` 3860 3861## notificationManager.setDistributedEnabledByBundle<sup>12+</sup> 3862 3863setDistributedEnabledByBundle(bundle: BundleOption, deviceType: string, enable: boolean): Promise<void\> 3864 3865设置指定应用是否支持跨设备协同。使用Promise异步回调。 3866 3867**系统能力**:SystemCapability.Notification.Notification 3868 3869**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 3870 3871**系统接口**: 此接口为系统接口。 3872 3873**参数:** 3874 3875| 参数名 | 类型 | 必填 | 说明 | 3876| -------- | ------------------------ | ---- | -------------------------- | 3877| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3878| deviceType | string | 是 | 设备类型。| 3879| enable | boolean | 是 | 指定应用是否支持跨设备协同(true:支持,false:不支持)。| 3880 3881**返回值:** 3882 3883| 类型 | 说明 | 3884| ---- | ----| 3885| Promise\<void> | 无返回结果的Promise对象。 | 3886 3887**错误码:** 3888 3889以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3890 3891| 错误码ID | 错误信息 | 3892| -------- | ---------------------------------------- | 3893| 201 | Permission denied. | 3894| 202 | Not system application to call the interface. | 3895| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3896| 1600001 | Internal error. | 3897| 1600002 | Marshalling or unmarshalling error. | 3898| 1600003 | Failed to connect to the service. | 3899| 1600010 | Distributed operation failed. | 3900| 1600012 | No memory space. | 3901| 17700001 | The specified bundle name was not found. | 3902 3903**示例:** 3904 3905```ts 3906import { BusinessError } from '@kit.BasicServicesKit'; 3907 3908let bundle: notificationManager.BundleOption = { 3909 bundle: "bundleName1", 3910 uid: 1 3911}; 3912let enable: boolean = true; 3913let deviceType: string = "phone"; 3914notificationManager.setDistributedEnabledByBundle(bundle, deviceType, enable).then(() => { 3915 console.info("setDistributedEnabledByBundle success"); 3916}).catch((err: BusinessError) => { 3917 console.error(`setDistributedEnabledByBundle fail: ${JSON.stringify(err)}`); 3918}); 3919``` 3920 3921## notificationManager.isDistributedEnabledByBundle<sup>12+</sup> 3922 3923isDistributedEnabledByBundle(bundle: BundleOption, deviceType: string): Promise<boolean\> 3924 3925获取指定应用是否支持跨设备协同。使用Promise异步回调。 3926 3927**系统能力**:SystemCapability.Notification.Notification 3928 3929**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 3930 3931**系统接口**: 此接口为系统接口。 3932 3933**参数:** 3934 3935| 参数名 | 类型 | 必填 | 说明 | 3936| -------- | ------------------------ | ---- | -------------------------- | 3937| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 3938| deviceType | string | 是 | 设备类型。 | 3939 3940**返回值:** 3941 3942| 类型 | 说明 | 3943| ---- | ----| 3944| Promise\<boolean\> | 以Promise形式返回指定应用是否支持跨设备协同的开关是否开启的结果(true:开启,false:未开启)。 | 3945 3946**错误码:** 3947 3948以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 3949 3950| 错误码ID | 错误信息 | 3951| -------- | ---------------------------------------- | 3952| 201 | Permission denied. | 3953| 202 | Not system application to call the interface. | 3954| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 3955| 1600001 | Internal error. | 3956| 1600002 | Marshalling or unmarshalling error. | 3957| 1600003 | Failed to connect to the service. | 3958| 1600010 | Distributed operation failed. | 3959| 1600012 | No memory space. | 3960| 17700001 | The specified bundle name was not found. | 3961 3962**示例:** 3963 3964```ts 3965import { BusinessError } from '@kit.BasicServicesKit'; 3966 3967let bundle: notificationManager.BundleOption = { 3968 bundle: "bundleName1", 3969 uid: 1 3970}; 3971let deviceType: string = "phone"; 3972notificationManager.isDistributedEnabledByBundle(bundle, deviceType).then((data: boolean) => { 3973 console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); 3974}).catch((err: BusinessError) => { 3975 console.error(`isDistributedEnabledByBundle fail: ${JSON.stringify(err)}`); 3976}); 3977``` 3978 3979## notificationManager.setSmartReminderEnabled<sup>12+</sup> 3980 3981setSmartReminderEnabled(deviceType: string, enable: boolean): Promise<void\> 3982 3983设置设备是否与其他设备协同智能提醒。使用Promise异步回调。 3984 3985**系统能力**:SystemCapability.Notification.Notification 3986 3987**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 3988 3989**系统接口**: 此接口为系统接口。 3990 3991**参数:** 3992 3993| 参数名 | 类型 | 必填 | 说明 | 3994| -------- | ------------------------ | ---- | -------------------------- | 3995| deviceType | string | 是 | 设备类型。 | 3996| enable | boolean | 是 | 指定应用是否支持设备是否与其他设备协同智能提醒(true:支持,false:不支持)。| 3997 3998**返回值:** 3999 4000| 类型 | 说明 | 4001| ---- | ----| 4002| Promise\<void> | 无返回结果的Promise对象。 | 4003 4004**错误码:** 4005 4006以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4007 4008| 错误码ID | 错误信息 | 4009| -------- | ---------------------------------------- | 4010| 201 | Permission denied. | 4011| 202 | Not system application to call the interface. | 4012| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4013| 1600001 | Internal error. | 4014| 1600002 | Marshalling or unmarshalling error. | 4015| 1600003 | Failed to connect to the service. | 4016| 1600010 | Distributed operation failed. | 4017| 1600012 | No memory space. | 4018| 17700001 | The specified bundle name was not found. | 4019 4020**示例:** 4021 4022```ts 4023import { BusinessError } from '@kit.BasicServicesKit'; 4024 4025let deviceType: string = "phone"; 4026let enable: boolean = true; 4027notificationManager.setSmartReminderEnabled(deviceType, enable).then(() => { 4028 console.info("setSmartReminderEnabled success"); 4029}).catch((err: BusinessError) => { 4030 console.error(`setSmartReminderEnabled fail: ${JSON.stringify(err)}`); 4031}); 4032``` 4033 4034## notificationManager.isSmartReminderEnabled<sup>12+</sup> 4035 4036isSmartReminderEnabled(deviceType: string): Promise<boolean\> 4037 4038获取设备是否与其他设备协同智能提醒。使用Promise异步回调。 4039 4040**系统能力**:SystemCapability.Notification.Notification 4041 4042**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 4043 4044**系统接口**: 此接口为系统接口。 4045 4046**参数:** 4047 4048| 参数名 | 类型 | 必填 | 说明 | 4049| -------- | ------------------------ | ---- | -------------------------- | 4050| deviceType | string | 是 | 设备类型。 | 4051 4052**返回值:** 4053 4054| 类型 | 说明 | 4055| ---- | ----| 4056| Promise\<boolean\> | 以Promise形式返回设备与其他设备协同智能提醒的开关是否开启的结果(true:开启,false:未开启)。 | 4057 4058**错误码:** 4059 4060以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4061 4062| 错误码ID | 错误信息 | 4063| -------- | ---------------------------------------- | 4064| 201 | Permission denied. | 4065| 202 | Not system application to call the interface. | 4066| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4067| 1600001 | Internal error. | 4068| 1600002 | Marshalling or unmarshalling error. | 4069| 1600003 | Failed to connect to the service. | 4070| 1600010 | Distributed operation failed. | 4071| 1600012 | No memory space. | 4072| 17700001 | The specified bundle name was not found. | 4073 4074**示例:** 4075 4076```ts 4077import { BusinessError } from '@kit.BasicServicesKit'; 4078 4079let deviceType: string = "phone"; 4080notificationManager.isSmartReminderEnabled(deviceType).then((data: boolean) => { 4081 console.info("isSmartReminderEnabled success, data:" + data); 4082}).catch((err: BusinessError) => { 4083 console.error(`isSmartReminderEnabled fail: ${JSON.stringify(err)}`); 4084}); 4085``` 4086 4087## notificationManager.setBadgeNumberByBundle<sup>12+</sup> 4088 4089setBadgeNumberByBundle(bundle: BundleOption, badgeNumber: number): Promise\<void\> 4090 4091代理其他应用设定角标个数。使用Promise异步回调。 4092 4093**系统能力**:SystemCapability.Notification.Notification 4094 4095**系统接口**:此接口为系统接口。 4096 4097**参数:** 4098 4099| 参数名 | 类型 | 必填 | 说明 | 4100| ----------- | ------ | ---- | ---------- | 4101| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 4102| badgeNumber | number | 是 | 角标个数。 | 4103 4104**返回值:** 4105 4106| 类型 | 说明 | 4107| --------------- | ------------------------- | 4108| Promise\<void\> | 无返回结果的Promise对象。 | 4109 4110**错误码:** 4111 4112以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4113 4114| 错误码ID | 错误信息 | 4115| -------- | ----------------------------------- | 4116| 202 | Not system application to call the interface. | 4117| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4118| 1600001 | Internal error. | 4119| 1600002 | Marshalling or unmarshalling error. | 4120| 1600003 | Failed to connect to the service. | 4121| 1600012 | No memory space. | 4122| 1600017 | There is no corresponding agent relationship configuration. | 4123| 17700001 | The specified bundle name was not found. | 4124 4125**示例:** 4126 4127```ts 4128import { BusinessError } from '@kit.BasicServicesKit'; 4129 4130let bundle: notificationManager.BundleOption = { 4131 bundle: 'com.example.bundleName', 4132}; 4133let badgeNumber: number = 10; 4134 4135notificationManager.setBadgeNumberByBundle(bundle, badgeNumber).then(() => { 4136 console.info('setBadgeNumberByBundle success'); 4137}).catch((err: BusinessError) => { 4138 console.error(`setBadgeNumberByBundle fail: ${JSON.stringify(err)}`); 4139}); 4140``` 4141 4142## notificationManager.getSlotByBundle<sup>12+</sup> 4143 4144getSlotByBundle(bundle: BundleOption, slotType: SlotType): Promise\<NotificationSlot> 4145 4146获取指定应用指定类型的通知渠道。使用Promise异步回调。 4147 4148获取前需要先通过[addSlot](#notificationmanageraddslot)创建通知渠道。 4149 4150**系统能力**:SystemCapability.Notification.Notification 4151 4152**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 4153 4154**系统接口**: 此接口为系统接口。 4155 4156**参数:** 4157 4158| 参数名 | 类型 | 必填 | 说明 | 4159| ------ | ------------ | ---- | ---------- | 4160| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 4161| slotType | [SlotType](././js-apis-notificationManager.md#slottype) | 是 | 渠道类型。 | 4162 4163**返回值:** 4164 4165| 类型 | 说明 | 4166| ----------------------------------------------------------- | ------------------------------------------------------------ | 4167| Promise\<[NotificationSlot](js-apis-inner-notification-notificationSlot-sys.md)> | 以Promise形式返回获取指定应用指定类型的通知渠道。 | 4168 4169**错误码:** 4170 4171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4172 4173| 错误码ID | 错误信息 | 4174| -------- | ---------------------------------------- | 4175| 201 | Permission denied. | 4176| 202 | Not system application to call the interface. | 4177| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4178| 1600001 | Internal error. | 4179| 1600002 | Marshalling or unmarshalling error. | 4180| 1600003 | Failed to connect to the service. | 4181| 1600012 | No memory space. | 4182| 17700001 | The specified bundle name was not found. | 4183 4184**示例:** 4185 4186```ts 4187import { BusinessError } from '@kit.BasicServicesKit'; 4188 4189let bundle: notificationManager.BundleOption = { 4190 bundle: "bundleName1", 4191}; 4192 4193let slotType = notificationManager.SlotType.LIVE_VIEW; 4194 4195notificationManager.getSlotByBundle(bundle, slotType).then((data: notificationManager.NotificationSlot) => { 4196 console.info("getSlotByBundle success, data: " + JSON.stringify(data)); 4197}).catch((err: BusinessError) => { 4198 console.error(`getSlotByBundle fail: ${JSON.stringify(err)}`); 4199}); 4200``` 4201 4202## notificationManager.addDoNotDisturbProfile<sup>12+</sup> 4203 4204addDoNotDisturbProfile(templates: Array\<DoNotDisturbProfile>): Promise\<void\> 4205 4206添加勿扰模式配置信息。使用Promise异步回调。 4207 4208**系统能力**:SystemCapability.Notification.Notification 4209 4210**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 4211 4212**系统接口**: 此接口为系统接口。 4213 4214**参数:** 4215 4216| 参数名 | 类型 | 必填 | 说明 | 4217| ------ | ---------------- | ---- | -------------- | 4218| templates | Array\<[DoNotDisturbProfile](#donotdisturbprofile12)> | 是 | 勿扰模式的配置信息。 | 4219 4220**返回值:** 4221 4222| 类型 | 说明 | 4223|---------|-----------| 4224| Promise\<void\> | 无返回结果的Promise对象。 | 4225 4226**错误码:** 4227 4228以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4229 4230| 错误码ID | 错误信息 | 4231| -------- | ----------------------------------- | 4232| 201 | Permission denied. | 4233| 202 | Not system application to call the interface. | 4234| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4235| 1600001 | Internal error. | 4236| 1600002 | Marshalling or unmarshalling error. | 4237| 1600003 | Failed to connect to the service. | 4238| 1600012 | No memory space. | 4239 4240**示例:** 4241 4242```ts 4243import { BusinessError } from '@kit.BasicServicesKit'; 4244 4245let trustlist: Array<notificationManager.BundleOption> = [ 4246 { 4247 bundle: 'com.example.bundleName', 4248 uid: 0 4249 }, 4250 { 4251 bundle: 'com.example.bundleName1', 4252 uid: 1 4253 } 4254] 4255let templates: Array<notificationManager.DoNotDisturbProfile> = [ 4256 { 4257 id: 3, 4258 name: '工作模式', 4259 trustlist: trustlist 4260 } 4261] 4262 4263notificationManager.addDoNotDisturbProfile(templates).then(() => { 4264 console.info("addDoNotDisturbProfile success."); 4265}).catch((error: BusinessError) => { 4266 console.error(`addDoNotDisturbProfile fail: ${JSON.stringify(error)}`); 4267}); 4268``` 4269 4270## notificationManager.removeDoNotDisturbProfile<sup>12+</sup> 4271 4272removeDoNotDisturbProfile(templates: Array\<DoNotDisturbProfile>): Promise\<void\> 4273 4274删除勿扰模式配置。使用Promise异步回调。 4275 4276**系统能力**:SystemCapability.Notification.Notification 4277 4278**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 4279 4280**系统接口**: 此接口为系统接口。 4281 4282**参数:** 4283 4284| 参数名 | 类型 | 必填 | 说明 | 4285| ------ | ---------------- | ---- | -------------- | 4286| templates | Array\<[DoNotDisturbProfile](#donotdisturbprofile12)> | 是 | 勿扰模式的配置信息。 | 4287 4288**返回值:** 4289 4290| 类型 | 说明 | 4291|---------|-----------| 4292| Promise\<void\> | 无返回结果的Promise对象。 | 4293 4294**错误码:** 4295 4296以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4297 4298| 错误码ID | 错误信息 | 4299| -------- | ----------------------------------- | 4300| 201 | Permission denied. | 4301| 202 | Not system application to call the interface. | 4302| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4303| 1600001 | Internal error. | 4304| 1600002 | Marshalling or unmarshalling error. | 4305| 1600003 | Failed to connect to the service. | 4306| 1600012 | No memory space. | 4307 4308**示例:** 4309 4310```ts 4311import { BusinessError } from '@kit.BasicServicesKit'; 4312 4313let templates: Array<notificationManager.DoNotDisturbProfile> = [ 4314 { 4315 id: 3, 4316 name: '工作模式' 4317 } 4318] 4319notificationManager.removeDoNotDisturbProfile(templates).then(() => { 4320 console.info("removeDoNotDisturbProfile success."); 4321}).catch((error: BusinessError) => { 4322 console.error(`removeDoNotDisturbProfile fail: ${JSON.stringify(error)}`); 4323}); 4324``` 4325 4326## notificationManager.setAdditionalConfig<sup>12+</sup> 4327 4328setAdditionalConfig(key: string, value: string): Promise\<number\> 4329 4330设置通知的系统附加配置信息。使用Promise异步回调。 4331 4332**系统能力**:SystemCapability.Notification.Notification 4333 4334**需要权限**: ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4335 4336**系统接口**: 此接口为系统接口。 4337 4338**参数:** 4339 4340| 参数名 | 类型 | 必填 | 说明 | 4341| ------ | ---------------- | ---- | -------------- | 4342| key | string | 是 | 附加配置键。目前仅支持`RING_TRUSTLIST_PKG`,表示应用支持使用[自定义铃声](./js-apis-inner-notification-notificationRequest.md#notificationrequest-1)。 | 4343| value | string | 是 | 附加配置值。参数示例:[bundleName1,bundleName2]。 | 4344 4345**返回值:** 4346 4347| 类型 | 说明 | 4348|---------|-----------| 4349| Promise\<number\> | Promise对象,返回0表示设置成功,返回其他值表示设置失败。 | 4350 4351**错误码:** 4352 4353以下错误码的详细介绍请参见[通知错误码](./errorcode-notification.md)。 4354 4355| 错误码ID | 错误信息 | 4356| -------- | ----------------------------------- | 4357| 201 | Permission denied. | 4358| 202 | Not system application to call the interface. | 4359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4360| 1600001 | Internal error. | 4361| 1600002 | Marshalling or unmarshalling error. | 4362| 1600003 | Failed to connect to the service. | 4363 4364**示例:** 4365 4366```ts 4367import { BusinessError } from '@kit.BasicServicesKit'; 4368 4369notificationManager.setAdditionalConfig('RING_TRUSTLIST_PKG','[bundleName1,bundleName2]').then((data: number) => { 4370 console.info("setAdditionalConfig success, data: " + JSON.stringify(data)); 4371}).catch((error: BusinessError) => { 4372 console.error(`setAdditionalConfig fail: ${JSON.stringify(error)}`); 4373}); 4374``` 4375 4376## notificationManager.getDoNotDisturbProfile<sup>13+</sup> 4377 4378getDoNotDisturbProfile(id: number): Promise\<DoNotDisturbProfile\> 4379 4380查询勿扰模式配置信息。使用Promise异步回调。 4381 4382**系统能力**:SystemCapability.Notification.Notification 4383 4384**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 4385 4386**系统接口**: 此接口为系统接口。 4387 4388**参数:** 4389 4390| 参数名 | 类型 | 必填 | 说明 | 4391| ------ | ---------------- | ---- | -------------- | 4392| id | number | 是 | 勿扰模式编号。 | 4393 4394**返回值:** 4395 4396| 类型 | 说明 | 4397|---------|-----------| 4398| Promise\<[DoNotDisturbProfile](#donotdisturbprofile12)\> | Promise对象,返回勿扰模式的配置信息。 | 4399 4400**错误码:** 4401 4402以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 4403 4404| 错误码ID | 错误信息 | 4405| -------- | ----------------------------------- | 4406| 201 | Permission denied. | 4407| 202 | Not system application to call the interface. | 4408| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 4409| 1600001 | Internal error. | 4410| 1600002 | Marshalling or unmarshalling error. | 4411| 1600003 | Failed to connect to the service. | 4412| 1600019 | The do-not-disturb profile does not exist. | 4413 4414**示例:** 4415 4416```ts 4417import { BusinessError } from '@kit.BasicServicesKit'; 4418 4419notificationManager.getDoNotDisturbProfile(1).then((data: notificationManager.DoNotDisturbProfile) => { 4420 console.info("getDoNotDisturbProfile success: " + JSON.stringify(data)); 4421}).catch((error: BusinessError) => { 4422 console.error(`getDoNotDisturbProfile fail: ${JSON.stringify(error)}`); 4423}); 4424``` 4425 4426## DoNotDisturbDate 4427 4428**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 4429 4430**系统接口**:此接口为系统接口。 4431 4432| 名称 | 类型 | 必填 | 说明 | 4433| ----- | ------------------------------------- | ---- | ---------------------- | 4434| type | [DoNotDisturbType](#donotdisturbtype) | 是 | 免打扰设置的时间类型。 | 4435| begin | Date | 是 | 免打扰设置的起点时间。 | 4436| end | Date | 是 | 免打扰设置的终点时间。 | 4437 4438## DoNotDisturbType 4439 4440**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 4441 4442**系统接口**: 此接口为系统接口。 4443 4444| 名称 | 值 | 说明 | 4445| ------------ | ---------------- | ------------------------------------------ | 4446| TYPE_NONE | 0 | 非通知勿扰类型。 | 4447| TYPE_ONCE | 1 | 以设置时间段(只看小时和分钟)一次执行勿扰。 | 4448| TYPE_DAILY | 2 | 以设置时间段(只看小时和分钟)每天执行勿扰。 | 4449| TYPE_CLEARLY | 3 | 以设置时间段(明确月日时)执行勿扰。 | 4450 4451 4452## DeviceRemindType 4453 4454**系统能力**:SystemCapability.Notification.Notification 4455 4456**系统接口**: 此接口为系统接口。 4457 4458| 名称 | 值 | 说明 | 4459| -------------------- | --- | --------------------------------- | 4460| IDLE_DONOT_REMIND | 0 | 设备未被使用,无需提醒。 | 4461| IDLE_REMIND | 1 | 提醒设备未被使用。 | 4462| ACTIVE_DONOT_REMIND | 2 | 设备正在使用,无需提醒。 | 4463| ACTIVE_REMIND | 3 | 提醒设备正在使用。 | 4464 4465 4466## SourceType 4467 4468**系统能力**:SystemCapability.Notification.Notification 4469 4470**系统接口**: 此接口为系统接口。 4471 4472| 名称 | 值 | 说明 | 4473| -------------------- | --- | -------------------- | 4474| TYPE_NORMAL | 0 | 一般通知。 | 4475| TYPE_CONTINUOUS | 1 | 连续通知。 | 4476| TYPE_TIMER | 2 | 计划通知。 | 4477 4478## NotificationCheckInfo<sup>10+</sup> 4479 4480**系统能力**:SystemCapability.Notification.Notification 4481 4482**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4483 4484**系统接口**:此接口为系统接口。 4485 4486| 名称 | 类型 | 必填 | 说明 | 4487| ---------------------------- | ---------------------------- | --- | --------------- | 4488| bundleName | string | 是 | Bundle名称。 | 4489| notificationId | number | 是 | 通知ID。 | 4490| label<sup>11+</sup> | string | 否 | 通知标签。 | 4491| contentType | [ContentType](./js-apis-notificationManager.md#contenttype) | 是 | 通知类型。 | 4492| creatorUserId<sup>11+</sup> | number | 是 | 通知的user ID。 | 4493| slotType<sup>11+</sup> | [SlotType](./js-apis-notificationManager.md#slottype) | 是 | 渠道类型。 | 4494| extraInfos<sup>11+</sup> | [key: string]: object | 否 | 实况通知的附加信息。 | 4495 4496## NotificationCheckResult<sup>10+</sup> 4497 4498**系统能力**:SystemCapability.Notification.Notification 4499 4500**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4501 4502**系统接口**:此接口为系统接口。 4503 4504| 名称 | 类型 | 必填 | 说明 | 4505| ------- | ------------------------------------ | ---- | ---------------------- | 4506| code | number | 是 | 0-display, 1-no display。 | 4507| message | string | 是 | 结果信息。 | 4508 4509 4510## ButtonOptions<sup>11+</sup> 4511 4512描述触发按钮信息。 4513 4514**系统能力**:SystemCapability.Notification.Notification 4515 4516**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER 4517 4518**系统接口**:此接口为系统接口。 4519 4520| 名称 | 类型 | 必填 | 说明 | 4521| ------- | ------------------------------------ | ---- | ---------------------- | 4522| buttonName | string | 是 | 按钮名称。 | 4523 4524 4525## SystemLiveViewSubscriber<sup>11+</sup> 4526 4527系统实况窗订阅者。 4528 4529**系统能力**:SystemCapability.Notification.Notification 4530 4531**系统接口**:此接口为系统接口。 4532 4533 4534| 名称 | 类型 | 必填 | 说明 | 4535| ------- | ------------------------------------ | ---- | ---------------------- | 4536| onResponse | (notificationId: number, buttonOptions: [ButtonOptions](#buttonoptions11)) => void | 否 | 点击按钮的回调。 | 4537 4538 4539## SlotType 4540 4541**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 4542 4543| 名称 | 值 | 说明 | 4544| ----------------------------------- | ------ | ------------------------------------------------------------ | 4545| EMERGENCY_INFORMATION<sup>12+</sup> | 10 | 紧急事件。**系统接口**: 此接口为系统接口。 | 4546 4547 4548## NotificationControlFlagStatus<sup>12+</sup> 4549每个bit位都可以控制通知的提示方式。当notificationControlFlags和下表中枚举值进行按位或操作,则表示关闭其提示方式。 4550 4551**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 4552 4553**系统接口**:此接口为系统接口。 4554 4555| 名称 | 值 | 说明 | 4556| ------------------------------------ | ---- | -------- | 4557| NOTIFICATION_STATUS_CLOSE_SOUND | 1<<0 | 关闭声音提示功能。 | 4558| NOTIFICATION_STATUS_CLOSE_LOCKSCREEN | 1<<1 | 关闭锁屏提示功能。 | 4559| NOTIFICATION_STATUS_CLOSE_BANNER | 1<<2 | 关闭横幅提示功能。 | 4560| NOTIFICATION_STATUS_CLOSE_LIGHT_SCREEN | 1<<3 | 关闭亮屏提示功能。 | 4561| NOTIFICATION_STATUS_CLOSE_VIBRATION | 1<<4 | 关闭振动提示功能。 | 4562| NOTIFICATION_STATUS_CLOSE_STATUSBAR_ICON | 1<<5 | 关闭状态栏图标提示功能。 | 4563 4564## DoNotDisturbProfile<sup>12+</sup> 4565 4566**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 4567 4568**系统接口**:此接口为系统接口。 4569 4570| 名称 | 类型 | 必填 | 说明 | 4571| ----- | ------------------------------------- | ---- | ---------------------- | 4572| id | number | 是 | 勿扰模式编号。 | 4573| name | string | 是 | 勿扰模式名称。 | 4574| trustlist | Array\<[BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)> | 否 | 勿扰模式的信任列表。 | 4575