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