1# @ohos.notification (Notification模块)(系统应用) 2 3本模块提供通知管理的能力,包括发布、取消发布通知,创建、获取、移除通知通道,订阅、取消订阅通知,获取通知的使能状态、角标使能状态,获取通知的相关信息等。 4 5> **说明:** 6> 7> 从API version 9开始,该接口不再维护,推荐使用新接口[@ohos.notificationManager](js-apis-notificationManager.md)。 8> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 9> 10> 当前界面仅包含本模块的系统接口,其他公开接口参见[Notification](./js-apis-notification.md)。 11 12 13## 导入模块 14 15```ts 16import Notification from '@ohos.notification'; 17``` 18 19## Notification.publish<sup>8+</sup> 20 21publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void 22 23发布通知给指定的用户(callback形式)。 24 25**系统能力**:SystemCapability.Notification.Notification 26 27**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 28 29**系统API**: 此接口为系统接口,三方应用不支持调用。 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 35| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 36| userId | number | 是 | 用户ID。 | 37| callback | AsyncCallback\<void\> | 是 | 被指定的回调方法。 | 38 39**示例:** 40 41```ts 42import NotificationManager from '@ohos.notificationManager'; 43import Base from '@ohos.base'; 44 45// publish回调 46let publishCallback = (err: Base.BusinessError) => { 47 if (err) { 48 console.error(`publish failed, code is ${err.code}`); 49 } else { 50 console.info("publish success"); 51 } 52} 53// 用户ID 54let userId: number = 1; 55// 通知Request对象 56let notificationRequest: NotificationManager.NotificationRequest = { 57 id: 1, 58 content: { 59 contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 60 normal: { 61 title: "test_title", 62 text: "test_text", 63 additionalText: "test_additionalText" 64 } 65 } 66}; 67Notification.publish(notificationRequest, userId, publishCallback); 68``` 69 70## Notification.publish<sup>8+</sup> 71 72publish(request: NotificationRequest, userId: number): Promise\<void\> 73 74发布通知给指定的用户(Promise形式)。 75 76**系统能力**:SystemCapability.Notification.Notification 77 78**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 79 80**系统API**: 此接口为系统接口,三方应用不支持调用。 81 82**参数:** 83 84| 参数名 | 类型 | 必填 | 说明 | 85| -------- | ----------------------------------------- | ---- | ------------------------------------------- | 86| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 87| userId | number | 是 | 用户ID。 | 88 89**返回值:** 90 91| 类型 | 说明 | 92| ------- |------------| 93| Promise\<void\> | 无返回结果的Promise对象。 | 94 95**示例:** 96 97```ts 98import NotificationManager from '@ohos.notificationManager'; 99import Base from '@ohos.base'; 100 101let notificationRequest: NotificationManager.NotificationRequest = { 102 id: 1, 103 content: { 104 contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 105 normal: { 106 title: "test_title", 107 text: "test_text", 108 additionalText: "test_additionalText" 109 } 110 } 111}; 112 113let userId: number = 1; 114 115Notification.publish(notificationRequest, userId).then(() => { 116 console.info("publish success"); 117}).catch((err: Base.BusinessError) => { 118 console.error(`publish failed, code is ${err}`); 119}); 120``` 121 122## Notification.addSlot 123 124addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void 125 126创建通知通道(callback形式)。 127 128**系统能力**:SystemCapability.Notification.Notification 129 130**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 131 132**系统API**: 此接口为系统接口,三方应用不支持调用。 133 134**参数:** 135 136| 参数名 | 类型 | 必填 | 说明 | 137| -------- | --------------------- | ---- | -------------------- | 138| slot | [NotificationSlot](./js-apis-notification.md#notificationslot) | 是 | 要创建的通知通道对象。 | 139| callback | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 | 140 141**示例:** 142 143```ts 144import NotificationManager from '@ohos.notificationManager'; 145import Base from '@ohos.base'; 146 147// addslot回调 148let addSlotCallBack = (err: Base.BusinessError) => { 149 if (err) { 150 console.info("addSlot failed " + JSON.stringify(err)); 151 } else { 152 console.info("addSlot success"); 153 } 154} 155// 通知slot对象 156let notificationSlot: NotificationManager.NotificationSlot = { 157 type: Notification.SlotType.SOCIAL_COMMUNICATION 158}; 159Notification.addSlot(notificationSlot, addSlotCallBack); 160``` 161 162## Notification.addSlot 163 164addSlot(slot: NotificationSlot): Promise\<void\> 165 166创建通知通道(Promise形式)。 167 168**系统能力**:SystemCapability.Notification.Notification 169 170**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 171 172**系统API**: 此接口为系统接口,三方应用不支持调用。 173 174**参数:** 175 176| 参数名 | 类型 | 必填 | 说明 | 177| ---- | ---------------- | ---- | -------------------- | 178| slot | [NotificationSlot](./js-apis-notification.md#notificationslot) | 是 | 要创建的通知通道对象。 | 179 180**返回值:** 181 182| 类型 | 说明 | 183| ------- |------------| 184| Promise\<void\> | 无返回结果的Promise对象。 | 185 186**示例:** 187 188```ts 189import NotificationManager from '@ohos.notificationManager'; 190import Base from '@ohos.base'; 191 192// 通知slot对象 193let notificationSlot: NotificationManager.NotificationSlot = { 194 type: Notification.SlotType.SOCIAL_COMMUNICATION 195}; 196Notification.addSlot(notificationSlot).then(() => { 197 console.info("addSlot success"); 198}).catch((err: Base.BusinessError) => { 199 console.error(`addSlot failed, code is ${err}`); 200}); 201``` 202 203## Notification.addSlots 204 205addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void 206 207创建多个通知通道(callback形式)。 208 209**系统能力**:SystemCapability.Notification.Notification 210 211**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 212 213**系统API**: 此接口为系统接口,三方应用不支持调用。 214 215**参数:** 216 217| 参数名 | 类型 | 必填 | 说明 | 218| -------- | ------------------------- | ---- | ------------------------ | 219| slots | Array\<[NotificationSlot](./js-apis-notification.md#notificationslot)\> | 是 | 要创建的通知通道对象数组。 | 220| callback | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 | 221 222**示例:** 223 224```ts 225import NotificationManager from '@ohos.notificationManager'; 226import Base from '@ohos.base'; 227 228// addSlots回调 229let addSlotsCallBack = (err: Base.BusinessError) => { 230 if (err) { 231 console.info("addSlots failed " + JSON.stringify(err)); 232 } else { 233 console.info("addSlots success"); 234 } 235} 236// 通知slot对象 237let notificationSlot: NotificationManager.NotificationSlot = { 238 type: Notification.SlotType.SOCIAL_COMMUNICATION 239}; 240// 通知slot array 对象 241let notificationSlotArray: NotificationManager.NotificationSlot[] = new Array(); 242notificationSlotArray[0] = notificationSlot; 243 244Notification.addSlots(notificationSlotArray, addSlotsCallBack); 245``` 246 247## Notification.addSlots 248 249addSlots(slots: Array\<NotificationSlot\>): Promise\<void\> 250 251创建多个通知通道(Promise形式)。 252 253**系统能力**:SystemCapability.Notification.Notification 254 255**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 256 257**系统API**: 此接口为系统接口,三方应用不支持调用。 258 259**参数:** 260 261| 参数名 | 类型 | 必填 | 说明 | 262| ----- | ------------------------- | ---- | ------------------------ | 263| slots | Array\<[NotificationSlot](./js-apis-notification.md#notificationslot)\> | 是 | 要创建的通知通道对象数组。 | 264 265**返回值:** 266 267| 类型 | 说明 | 268| ------- |------------| 269| Promise\<void\> | 无返回结果的Promise对象。 | 270 271**示例:** 272 273```ts 274import NotificationManager from '@ohos.notificationManager'; 275import Base from '@ohos.base'; 276 277// 通知slot对象 278let notificationSlot: NotificationManager.NotificationSlot = { 279 type: Notification.SlotType.SOCIAL_COMMUNICATION 280}; 281// 通知slot array 对象 282let notificationSlotArray: NotificationManager.NotificationSlot[] = new Array(); 283notificationSlotArray[0] = notificationSlot; 284 285Notification.addSlots(notificationSlotArray).then(() => { 286 console.info("addSlots success"); 287}).catch((err: Base.BusinessError) => { 288 console.error(`addSlot failed, code is ${err}`); 289}); 290``` 291 292## Notification.subscribe 293 294subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void 295 296订阅通知并指定订阅信息(callback形式)。 297 298**系统能力**:SystemCapability.Notification.Notification 299 300**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 301 302**系统API**: 此接口为系统接口,三方应用不支持调用。 303 304**参数:** 305 306| 参数名 | 类型 | 必填 | 说明 | 307| ---------- | ------------------------- | ---- | ---------------- | 308| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | 是 | 通知订阅对象。 | 309| info | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | 是 | 通知订阅信息。 | 310| callback | AsyncCallback\<void\> | 是 | 订阅动作回调函数。 | 311 312**示例:** 313 314```ts 315import Base from '@ohos.base'; 316import NotificationSubscribe from '@ohos.notificationSubscribe'; 317 318// subscribe回调 319let subscribeCallback = (err: Base.BusinessError) => { 320 if (err) { 321 console.info("subscribe failed " + JSON.stringify(err)); 322 } else { 323 console.info("subscribe success"); 324 } 325} 326let onConsumeCallback = (data: NotificationSubscribe.SubscribeCallbackData) => { 327 console.info("Consume callback: " + JSON.stringify(data)); 328} 329let subscriber: NotificationSubscribe.NotificationSubscriber = { 330 onConsume: onConsumeCallback 331}; 332let info: NotificationSubscribe.NotificationSubscribeInfo = { 333 bundleNames: ["bundleName1", "bundleName2"] 334}; 335Notification.subscribe(subscriber, info, subscribeCallback); 336``` 337 338## Notification.subscribe 339 340subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 341 342订阅当前用户下所有应用的通知(callback形式)。 343 344**系统能力**:SystemCapability.Notification.Notification 345 346**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 347 348**系统API**: 此接口为系统接口,三方应用不支持调用。 349 350**参数:** 351 352| 参数名 | 类型 | 必填 | 说明 | 353| ---------- | ---------------------- | ---- | ---------------- | 354| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | 是 | 通知订阅对象。 | 355| callback | AsyncCallback\<void\> | 是 | 订阅动作回调函数。 | 356 357**示例:** 358 359```ts 360import Base from '@ohos.base'; 361import NotificationSubscribe from '@ohos.notificationSubscribe'; 362 363let subscribeCallback = (err: Base.BusinessError) => { 364 if (err) { 365 console.info("subscribe failed " + JSON.stringify(err)); 366 } else { 367 console.info("subscribe success"); 368 } 369} 370function onConsumeCallback(data: NotificationSubscribe.SubscribeCallbackData) { 371 console.info("Consume callback: " + JSON.stringify(data)); 372} 373let subscriber: NotificationSubscribe.NotificationSubscriber = { 374 onConsume: onConsumeCallback 375}; 376Notification.subscribe(subscriber, subscribeCallback); 377``` 378 379## Notification.subscribe 380 381subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\> 382 383订阅通知并指定订阅信息(Promise形式)。 384 385**系统能力**:SystemCapability.Notification.Notification 386 387**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 388 389**系统API**: 此接口为系统接口,三方应用不支持调用。 390 391**参数:** 392 393| 参数名 | 类型 | 必填 | 说明 | 394| ---------- | ------------------------- | ---- | ------------ | 395| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | 是 | 通知订阅对象。 | 396| info | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | 否 | 通知订阅信息,默认为空。 | 397 398**返回值:** 399 400| 类型 | 说明 | 401| ------- |------------| 402| Promise\<void\> | 无返回结果的Promise对象。 | 403 404**示例:** 405 406```ts 407import Base from '@ohos.base'; 408import NotificationSubscribe from '@ohos.notificationSubscribe'; 409 410function onConsumeCallback(data: NotificationSubscribe.SubscribeCallbackData) { 411 console.info("Consume callback: " + JSON.stringify(data)); 412} 413let subscriber: NotificationSubscribe.NotificationSubscriber = { 414 onConsume: onConsumeCallback 415}; 416Notification.subscribe(subscriber).then(() => { 417 console.info("subscribe success"); 418}).catch((err: Base.BusinessError) => { 419 console.error(`subscribe failed, code is ${err}`); 420}); 421``` 422 423## Notification.unsubscribe 424 425unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 426 427取消订阅(callbcak形式)。 428 429**系统能力**:SystemCapability.Notification.Notification 430 431**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 432 433**系统API**: 此接口为系统接口,三方应用不支持调用。 434 435**参数:** 436 437| 参数名 | 类型 | 必填 | 说明 | 438| ---------- | ---------------------- | ---- | -------------------- | 439| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | 是 | 通知订阅对象。 | 440| callback | AsyncCallback\<void\> | 是 | 取消订阅动作回调函数。 | 441 442**示例:** 443 444```ts 445import Base from '@ohos.base'; 446import NotificationSubscribe from '@ohos.notificationSubscribe'; 447 448let unsubscribeCallback = (err: Base.BusinessError) => { 449 if (err) { 450 console.info("unsubscribe failed " + JSON.stringify(err)); 451 } else { 452 console.info("unsubscribe success"); 453 } 454} 455let onDisconnectCallback = () => { 456 console.info("subscribe disconnect"); 457} 458let subscriber: NotificationSubscribe.NotificationSubscriber = { 459 onDisconnect: onDisconnectCallback 460}; 461Notification.unsubscribe(subscriber, unsubscribeCallback); 462``` 463 464## Notification.unsubscribe 465 466unsubscribe(subscriber: NotificationSubscriber): Promise\<void\> 467 468取消订阅(Promise形式)。 469 470**系统能力**:SystemCapability.Notification.Notification 471 472**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 473 474**系统API**: 此接口为系统接口,三方应用不支持调用。 475 476**参数:** 477 478| 参数名 | 类型 | 必填 | 说明 | 479| ---------- | ---------------------- | ---- | ------------ | 480| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | 是 | 通知订阅对象。 | 481 482**返回值:** 483 484| 类型 | 说明 | 485| ------- |------------| 486| Promise\<void\> | 无返回结果的Promise对象。 | 487 488**示例:** 489 490```ts 491import Base from '@ohos.base'; 492import NotificationSubscribe from '@ohos.notificationSubscribe'; 493 494function onDisconnectCallback() { 495 console.info("subscribe disconnect"); 496} 497let subscriber: NotificationSubscribe.NotificationSubscriber = { 498 onDisconnect: onDisconnectCallback 499}; 500Notification.unsubscribe(subscriber).then(() => { 501 console.info("unsubscribe success"); 502}).catch((err: Base.BusinessError) => { 503 console.error(`unsubscribe failed, code is ${err}`); 504}); 505``` 506 507## Notification.enableNotification 508 509enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 510 511设定指定应用的通知使能状态(Callback形式)。 512 513**系统能力**:SystemCapability.Notification.Notification 514 515**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 516 517**系统API**: 此接口为系统接口,三方应用不支持调用。 518 519**参数:** 520 521| 参数名 | 类型 | 必填 | 说明 | 522| -------- | --------------------- | ---- | -------------------- | 523| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 524| enable | boolean | 是 | 使能状态。 | 525| callback | AsyncCallback\<void\> | 是 | 设定通知使能回调函数。 | 526 527**示例:** 528 529```ts 530import Base from '@ohos.base'; 531 532let enableNotificationCallback = (err: Base.BusinessError) => { 533 if (err) { 534 console.info("enableNotification failed " + JSON.stringify(err)); 535 } else { 536 console.info("enableNotification success"); 537 } 538} 539let bundle: Notification.BundleOption = { 540 bundle: "bundleName1", 541}; 542Notification.enableNotification(bundle, false, enableNotificationCallback); 543``` 544 545## Notification.enableNotification 546 547enableNotification(bundle: BundleOption, enable: boolean): Promise\<void\> 548 549设定指定应用的通知使能状态(Promise形式)。 550 551**系统能力**:SystemCapability.Notification.Notification 552 553**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 554 555**系统API**: 此接口为系统接口,三方应用不支持调用。 556 557**参数:** 558 559| 参数名 | 类型 | 必填 | 说明 | 560| ------ | ------------ | ---- | ---------- | 561| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 562| enable | boolean | 是 | 使能状态。 | 563 564**返回值:** 565 566| 类型 | 说明 | 567| ------- |------------| 568| Promise\<void\> | 无返回结果的Promise对象。 | 569 570**示例:** 571 572```ts 573import Base from '@ohos.base'; 574 575let bundle: Notification.BundleOption = { 576 bundle: "bundleName1", 577}; 578Notification.enableNotification(bundle, false).then(() => { 579 console.info("enableNotification success"); 580}).catch((err: Base.BusinessError) => { 581 console.error(`enableNotification failed, code is ${err}`); 582}); 583 584``` 585 586## Notification.isNotificationEnabled 587 588isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 589 590获取指定应用的通知使能状态(Callback形式)。 591 592**系统能力**:SystemCapability.Notification.Notification 593 594**系统API**:此接口为系统接口,三方应用不支持调用。 595 596**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 597 598**参数:** 599 600| 参数名 | 类型 | 必填 | 说明 | 601| -------- | --------------------- | ---- | ------------------------ | 602| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 603| callback | AsyncCallback\<void\> | 是 | 获取通知使能状态回调函数。 | 604 605**示例:** 606 607```ts 608import Base from '@ohos.base'; 609 610let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => { 611 if (err) { 612 console.info("isNotificationEnabled failed " + JSON.stringify(err)); 613 } else { 614 console.info("isNotificationEnabled success"); 615 } 616} 617let bundle: Notification.BundleOption = { 618 bundle: "bundleName1", 619}; 620Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); 621``` 622 623## Notification.isNotificationEnabled 624 625isNotificationEnabled(bundle: BundleOption): Promise\<boolean\> 626 627获取指定应用的通知使能状态(Promise形式)。 628 629**系统能力**:SystemCapability.Notification.Notification 630 631**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 632 633**系统API**: 此接口为系统接口,三方应用不支持调用。 634 635**参数:** 636 637| 参数名 | 类型 | 必填 | 说明 | 638| ------ | ------------ | ---- | ---------- | 639| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 640 641**返回值:** 642 643| 类型 | 说明 | 644| ------------------ | --------------------------------------------------- | 645| Promise\<boolean\> | 以Promise形式返回获取指定应用的通知使能状态的结果。 | 646 647**示例:** 648 649```ts 650import Base from '@ohos.base'; 651 652let bundle: Notification.BundleOption = { 653 bundle: "bundleName1", 654}; 655Notification.isNotificationEnabled(bundle).then((data) => { 656 console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 657}).catch((err: Base.BusinessError) => { 658 console.error(`isNotificationEnabled failed, code is ${err}`); 659}); 660``` 661 662## Notification.isNotificationEnabled 663 664isNotificationEnabled(callback: AsyncCallback\<boolean\>): void 665 666获取通知使能状态(Callback形式)。 667 668**系统能力**:SystemCapability.Notification.Notification 669 670**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 671 672**系统API**: 此接口为系统接口,三方应用不支持调用。 673 674**参数:** 675 676| 参数名 | 类型 | 必填 | 说明 | 677| -------- | --------------------- | ---- | ------------------------ | 678| callback | AsyncCallback\<void\> | 是 | 获取通知使能状态回调函数。 | 679 680**示例:** 681 682```ts 683import Base from '@ohos.base'; 684 685let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => { 686 if (err) { 687 console.info("isNotificationEnabled failed " + JSON.stringify(err)); 688 } else { 689 console.info("isNotificationEnabled success"); 690 } 691} 692 693Notification.isNotificationEnabled(isNotificationEnabledCallback); 694``` 695 696## Notification.isNotificationEnabled 697 698isNotificationEnabled(): Promise\<boolean\> 699 700获取通知使能状态(Promise形式)。 701 702**系统能力**:SystemCapability.Notification.Notification 703 704**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 705 706**系统API**: 此接口为系统接口,三方应用不支持调用。 707 708**参数:** 709 710| 参数名 | 类型 | 必填 | 说明 | 711| ------ | ------------ | ---- | ---------- | 712| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 713 714**返回值:** 715 716| 类型 | 说明 | 717| ----------------------------------------------------------- | ------------------------------------------------------------ | 718| Promise\<boolean\> | 以Promise形式返回获取通知使能状态的结果。 | 719 720**示例:** 721 722```ts 723import Base from '@ohos.base'; 724 725Notification.isNotificationEnabled().then((data: boolean) => { 726 console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 727}).catch((err: Base.BusinessError) => { 728 console.error(`isNotificationEnabled failed, code is ${err}`); 729}); 730``` 731 732## Notification.displayBadge 733 734displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void 735 736设定指定应用的角标使能状态(Callback形式)。 737 738**系统能力**:SystemCapability.Notification.Notification 739 740**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 741 742**系统API**: 此接口为系统接口,三方应用不支持调用。 743 744**参数:** 745 746| 参数名 | 类型 | 必填 | 说明 | 747| -------- | --------------------- | ---- | -------------------- | 748| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 749| enable | boolean | 是 | 使能状态。 | 750| callback | AsyncCallback\<void\> | 是 | 设定角标使能回调函数。 | 751 752**示例:** 753 754```ts 755import Base from '@ohos.base'; 756 757let displayBadgeCallback = (err: Base.BusinessError) => { 758 if (err) { 759 console.info("displayBadge failed " + JSON.stringify(err)); 760 } else { 761 console.info("displayBadge success"); 762 } 763} 764let bundle: Notification.BundleOption = { 765 bundle: "bundleName1", 766}; 767Notification.displayBadge(bundle, false, displayBadgeCallback); 768``` 769 770## Notification.displayBadge 771 772displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\> 773 774设定指定应用的角标使能状态(Promise形式)。 775 776**系统能力**:SystemCapability.Notification.Notification 777 778**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 779 780**系统API**: 此接口为系统接口,三方应用不支持调用。 781 782**参数:** 783 784| 参数名 | 类型 | 必填 | 说明 | 785| ------ | ------------ | ---- | ---------- | 786| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 787| enable | boolean | 是 | 使能状态。 | 788 789**返回值:** 790 791| 类型 | 说明 | 792| ------- |------------| 793| Promise\<void\> | 无返回结果的Promise对象。 | 794 795**示例:** 796 797```ts 798import Base from '@ohos.base'; 799 800let bundle: Notification.BundleOption = { 801 bundle: "bundleName1", 802}; 803Notification.displayBadge(bundle, false).then(() => { 804 console.info("displayBadge success"); 805}).catch((err: Base.BusinessError) => { 806 console.error(`displayBadge failed, code is ${err}`); 807}); 808``` 809 810## Notification.isBadgeDisplayed 811 812isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void 813 814获取指定应用的角标使能状态(Callback形式)。 815 816**系统能力**:SystemCapability.Notification.Notification 817 818**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 819 820**系统API**: 此接口为系统接口,三方应用不支持调用。 821 822**参数:** 823 824| 参数名 | 类型 | 必填 | 说明 | 825| -------- | --------------------- | ---- | ------------------------ | 826| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 827| callback | AsyncCallback\<void\> | 是 | 获取角标使能状态回调函数。 | 828 829**示例:** 830 831```ts 832import Base from '@ohos.base'; 833 834let isBadgeDisplayedCallback = (err: Base.BusinessError, data: boolean) => { 835 if (err) { 836 console.info("isBadgeDisplayed failed " + JSON.stringify(err)); 837 } else { 838 console.info("isBadgeDisplayed success"); 839 } 840} 841let bundle: Notification.BundleOption = { 842 bundle: "bundleName1", 843}; 844Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); 845``` 846 847## Notification.isBadgeDisplayed 848 849isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\> 850 851获取指定应用的角标使能状态(Promise形式)。 852 853**系统能力**:SystemCapability.Notification.Notification 854 855**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 856 857**系统API**: 此接口为系统接口,三方应用不支持调用。 858 859**参数:** 860 861| 参数名 | 类型 | 必填 | 说明 | 862| ------ | ------------ | ---- | ---------- | 863| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 864 865**返回值:** 866 867| 类型 | 说明 | 868| ----------------------------------------------------------- | ------------------------------------------------------------ | 869| Promise\<boolean\> | 以Promise形式返回获取指定应用的角标使能状态。 | 870 871**示例:** 872 873```ts 874import Base from '@ohos.base'; 875 876let bundle: Notification.BundleOption = { 877 bundle: "bundleName1", 878}; 879Notification.isBadgeDisplayed(bundle).then((data) => { 880 console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); 881}).catch((err: Base.BusinessError) => { 882 console.error(`isBadgeDisplayed failed, code is ${err}`); 883}); 884``` 885 886## Notification.setSlotByBundle 887 888setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void 889 890设定指定应用的通知通道(Callback形式)。 891 892**系统能力**:SystemCapability.Notification.Notification 893 894**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 895 896**系统API**: 此接口为系统接口,三方应用不支持调用。 897 898**参数:** 899 900| 参数名 | 类型 | 必填 | 说明 | 901| -------- | --------------------- | ---- | -------------------- | 902| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 903| slot | [NotificationSlot](./js-apis-notification.md#notificationslot) | 是 | 通知通道。 | 904| callback | AsyncCallback\<void\> | 是 | 设定通知通道回调函数。 | 905 906**示例:** 907 908```ts 909import Base from '@ohos.base'; 910import NotificationManager from '@ohos.notificationManager'; 911 912let setSlotByBundleCallback = (err: Base.BusinessError) => { 913 if (err) { 914 console.info("setSlotByBundle failed " + JSON.stringify(err)); 915 } else { 916 console.info("setSlotByBundle success"); 917 } 918} 919let bundle: Notification.BundleOption = { 920 bundle: "bundleName1", 921}; 922let notificationSlot: NotificationManager.NotificationSlot = { 923 type: Notification.SlotType.SOCIAL_COMMUNICATION 924}; 925Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); 926``` 927 928## Notification.setSlotByBundle 929 930setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\> 931 932设定指定应用的通知通道(Promise形式)。 933 934**系统能力**:SystemCapability.Notification.Notification 935 936**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 937 938**系统API**: 此接口为系统接口,三方应用不支持调用。 939 940**参数:** 941 942| 参数名 | 类型 | 必填 | 说明 | 943| ------ | ------------ | ---- | ---------- | 944| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 945| slot | [NotificationSlot](./js-apis-notification.md#notificationslot) | 是 | 通知通道。 | 946 947**返回值:** 948 949| 类型 | 说明 | 950| ------- |------------| 951| Promise\<void\> | 无返回结果的Promise对象。 | 952 953**示例:** 954 955```ts 956import Base from '@ohos.base'; 957import NotificationManager from '@ohos.notificationManager'; 958 959let bundle: Notification.BundleOption = { 960 bundle: "bundleName1", 961}; 962let notificationSlot: NotificationManager.NotificationSlot = { 963 type: Notification.SlotType.SOCIAL_COMMUNICATION 964}; 965Notification.setSlotByBundle(bundle, notificationSlot).then(() => { 966 console.info("setSlotByBundle success"); 967}).catch((err: Base.BusinessError) => { 968 console.error(`setSlotByBundle failed, code is ${err}`); 969}); 970``` 971 972## Notification.getSlotsByBundle 973 974getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<NotificationSlot>>): void 975 976获取指定应用的所有通知通道(Callback形式)。 977 978**系统能力**:SystemCapability.Notification.Notification 979 980**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 981 982**系统API**: 此接口为系统接口,三方应用不支持调用。 983 984**参数:** 985 986| 参数名 | 类型 | 必填 | 说明 | 987| -------- | ---------------------------------------- | ---- | -------------------- | 988| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 989| callback | AsyncCallback\<Array\<[NotificationSlot](./js-apis-notification.md#notificationslot)>> | 是 | 获取通知通道回调函数。 | 990 991**示例:** 992 993```ts 994import Base from '@ohos.base'; 995import NotificationManager from '@ohos.notificationManager'; 996 997let getSlotsByBundleCallback = (err: Base.BusinessError, data: NotificationManager.NotificationSlot[]) => { 998 if (err) { 999 console.info("getSlotsByBundle failed " + JSON.stringify(err)); 1000 } else { 1001 console.info("getSlotsByBundle success"); 1002 } 1003} 1004let bundle: Notification.BundleOption = { 1005 bundle: "bundleName1", 1006}; 1007Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); 1008``` 1009 1010## Notification.getSlotsByBundle 1011 1012getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>> 1013 1014获取指定应用的所有通知通道(Promise形式)。 1015 1016**系统能力**:SystemCapability.Notification.Notification 1017 1018**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1019 1020**系统API**: 此接口为系统接口,三方应用不支持调用。 1021 1022**参数:** 1023 1024| 参数名 | 类型 | 必填 | 说明 | 1025| ------ | ------------ | ---- | ---------- | 1026| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1027 1028**返回值:** 1029 1030| 类型 | 说明 | 1031| ----------------------------------------------------------- | ------------------------------------------------------------ | 1032| Promise\<Array\<[NotificationSlot](./js-apis-notification.md#notificationslot)>> | 以Promise形式返回获取指定应用的通知通道。 | 1033 1034**示例:** 1035 1036```ts 1037import Base from '@ohos.base'; 1038import NotificationManager from '@ohos.notificationManager'; 1039 1040let bundle: Notification.BundleOption = { 1041 bundle: "bundleName1", 1042}; 1043Notification.getSlotsByBundle(bundle).then((data: NotificationManager.NotificationSlot[]) => { 1044 console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); 1045}).catch((err: Base.BusinessError) => { 1046 console.error(`getSlotsByBundle failed, code is ${err}`); 1047}); 1048``` 1049 1050## Notification.getSlotNumByBundle 1051 1052getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void 1053 1054获取指定应用的通知通道数量(Callback形式)。 1055 1056**系统能力**:SystemCapability.Notification.Notification 1057 1058**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1059 1060**系统API**: 此接口为系统接口,三方应用不支持调用。 1061 1062**参数:** 1063 1064| 参数名 | 类型 | 必填 | 说明 | 1065| -------- | ------------------------- | ---- | ---------------------- | 1066| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1067| callback | AsyncCallback\<number\> | 是 | 获取通知通道数量回调函数。 | 1068 1069**示例:** 1070 1071```ts 1072import Base from '@ohos.base'; 1073import NotificationManager from '@ohos.notificationManager'; 1074 1075let getSlotNumByBundleCallback = (err: Base.BusinessError, data: number) => { 1076 if (err) { 1077 console.info("getSlotNumByBundle failed " + JSON.stringify(err)); 1078 } else { 1079 console.info("getSlotNumByBundle success"); 1080 } 1081} 1082let bundle: Notification.BundleOption = { 1083 bundle: "bundleName1", 1084}; 1085Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); 1086``` 1087 1088## Notification.getSlotNumByBundle 1089 1090getSlotNumByBundle(bundle: BundleOption): Promise\<number\> 1091 1092获取指定应用的通知通道数量(Promise形式)。 1093 1094**系统能力**:SystemCapability.Notification.Notification 1095 1096**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1097 1098**系统API**: 此接口为系统接口,三方应用不支持调用。 1099 1100**参数:** 1101 1102| 参数名 | 类型 | 必填 | 说明 | 1103| ------ | ------------ | ---- | ---------- | 1104| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1105 1106**返回值:** 1107 1108| 类型 | 说明 | 1109| ----------------------------------------------------------- | ------------------------------------------------------------ | 1110| Promise\<number\> | 以Promise形式返回获取指定应用的通知通道数量。 | 1111 1112**示例:** 1113 1114```ts 1115import Base from '@ohos.base'; 1116import NotificationManager from '@ohos.notificationManager'; 1117 1118let bundle: Notification.BundleOption = { 1119 bundle: "bundleName1", 1120}; 1121Notification.getSlotNumByBundle(bundle).then((data: number) => { 1122 console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); 1123}).catch((err: Base.BusinessError) => { 1124 console.error(`getSlotNumByBundle failed, code is ${err}`); 1125}); 1126``` 1127 1128## Notification.remove 1129 1130remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void 1131 1132删除指定通知(Callback形式)。 1133 1134**系统能力**:SystemCapability.Notification.Notification 1135 1136**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1137 1138**系统API**: 此接口为系统接口,三方应用不支持调用。 1139 1140**参数:** 1141 1142| 参数名 | 类型 | 必填 | 说明 | 1143| --------------- | ----------------------------------| ---- | -------------------- | 1144| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1145| notificationKey | [NotificationKey](./js-apis-notification.md#notificationkeydeprecated) | 是 | 通知键值。 | 1146| reason | [RemoveReason](#removereason-deprecated) | 是 | 通知删除原因。 | 1147| callback | AsyncCallback\<void\> | 是 | 删除指定通知回调函数。 | 1148 1149**示例:** 1150 1151```ts 1152import Base from '@ohos.base'; 1153 1154let removeCallback = (err: Base.BusinessError) => { 1155 if (err) { 1156 console.info("remove failed " + JSON.stringify(err)); 1157 } else { 1158 console.info("remove success"); 1159 } 1160} 1161let bundle: Notification.BundleOption = { 1162 bundle: "bundleName1", 1163}; 1164let notificationKey: Notification.NotificationKey = { 1165 id: 0, 1166 label: "label", 1167}; 1168let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE; 1169Notification.remove(bundle, notificationKey, reason, removeCallback); 1170``` 1171 1172## Notification.remove 1173 1174remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\> 1175 1176删除指定通知(Promise形式)。 1177 1178**系统能力**:SystemCapability.Notification.Notification 1179 1180**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1181 1182**系统API**: 此接口为系统接口,三方应用不支持调用。 1183 1184**参数:** 1185 1186| 参数名 | 类型 | 必填 | 说明 | 1187| --------------- | --------------- | ---- | ---------- | 1188| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1189| notificationKey | [NotificationKey](./js-apis-notification.md#notificationkeydeprecated) | 是 | 通知键值。 | 1190| reason | [RemoveReason](#removereason-deprecated) | 是 | 通知删除原因。 | 1191 1192**返回值:** 1193 1194| 类型 | 说明 | 1195| ------- |------------| 1196| Promise\<void\> | 无返回结果的Promise对象。 | 1197 1198**示例:** 1199 1200```ts 1201import Base from '@ohos.base'; 1202 1203let bundle: Notification.BundleOption = { 1204 bundle: "bundleName1", 1205}; 1206let notificationKey: Notification.NotificationKey = { 1207 id: 0, 1208 label: "label", 1209}; 1210let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE; 1211Notification.remove(bundle, notificationKey, reason).then(() => { 1212 console.info("remove success"); 1213}).catch((err: Base.BusinessError) => { 1214 console.error(`remove failed, code is ${err}`); 1215}); 1216``` 1217 1218## Notification.remove 1219 1220remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void 1221 1222删除指定通知(Callback形式)。 1223 1224**系统能力**:SystemCapability.Notification.Notification 1225 1226**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1227 1228**系统API**: 此接口为系统接口,三方应用不支持调用。 1229 1230**参数:** 1231 1232| 参数名 | 类型 | 必填 | 说明 | 1233| -------- | --------------------- | ---- | -------------------- | 1234| hashCode | string | 是 | 通知唯一ID。可以通过[onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume)回调的入参[SubscribeCallbackData](#subscribecallbackdata)获取其内部[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象中的hashCode。 | 1235| reason | [RemoveReason](#removereason-deprecated) | 是 | 通知删除原因。 | 1236| callback | AsyncCallback\<void\> | 是 | 删除指定通知回调函数。 | 1237 1238**示例:** 1239 1240```ts 1241import Base from '@ohos.base'; 1242 1243let hashCode: string = 'hashCode'; 1244 1245let removeCallback = (err: Base.BusinessError) => { 1246 if (err) { 1247 console.info("remove failed " + JSON.stringify(err)); 1248 } else { 1249 console.info("remove success"); 1250 } 1251} 1252let reason: Notification.RemoveReason = Notification.RemoveReason.CANCEL_REASON_REMOVE; 1253Notification.remove(hashCode, reason, removeCallback); 1254``` 1255 1256## Notification.remove 1257 1258remove(hashCode: string, reason: RemoveReason): Promise\<void\> 1259 1260删除指定通知(Promise形式)。 1261 1262**系统能力**:SystemCapability.Notification.Notification 1263 1264**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1265 1266**系统API**: 此接口为系统接口,三方应用不支持调用。 1267 1268**参数:** 1269 1270| 参数名 | 类型 | 必填 | 说明 | 1271| -------- | ---------- | ---- | ---------- | 1272| hashCode | string | 是 | 通知唯一ID。 | 1273| reason | [RemoveReason](#removereason-deprecated) | 是 | 通知删除原因。 | 1274 1275**返回值:** 1276 1277| 类型 | 说明 | 1278| ------- |------------| 1279| Promise\<void\> | 无返回结果的Promise对象。 | 1280 1281**示例:** 1282 1283```ts 1284import Base from '@ohos.base'; 1285 1286let hashCode: string = 'hashCode'; 1287let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE; 1288Notification.remove(hashCode, reason).then(() => { 1289 console.info("remove success"); 1290}).catch((err: Base.BusinessError) => { 1291 console.error(`remove failed, code is ${err}`); 1292}); 1293``` 1294 1295## Notification.removeAll 1296 1297removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void 1298 1299删除指定应用的所有通知(Callback形式)。 1300 1301**系统能力**:SystemCapability.Notification.Notification 1302 1303**系统API**:此接口为系统接口,三方应用不支持调用。 1304 1305**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1306 1307**参数:** 1308 1309| 参数名 | 类型 | 必填 | 说明 | 1310| -------- | --------------------- | ---- | ---------------------------- | 1311| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 指定应用的包信息。 | 1312| callback | AsyncCallback\<void\> | 是 | 删除指定应用的所有通知回调函数。 | 1313 1314**示例:** 1315 1316```ts 1317import Base from '@ohos.base'; 1318 1319let removeAllCallback = (err: Base.BusinessError) => { 1320 if (err) { 1321 console.info("removeAll failed " + JSON.stringify(err)); 1322 } else { 1323 console.info("removeAll success"); 1324 } 1325} 1326let bundle: Notification.BundleOption = { 1327 bundle: "bundleName1", 1328}; 1329Notification.removeAll(bundle, removeAllCallback); 1330``` 1331 1332## Notification.removeAll 1333 1334removeAll(callback: AsyncCallback\<void\>): void 1335 1336删除所有通知(Callback形式)。 1337 1338**系统能力**:SystemCapability.Notification.Notification 1339 1340**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1341 1342**系统API**: 此接口为系统接口,三方应用不支持调用。 1343 1344**参数:** 1345 1346| 参数名 | 类型 | 必填 | 说明 | 1347| -------- | --------------------- | ---- | -------------------- | 1348| callback | AsyncCallback\<void\> | 是 | 删除所有通知回调函数。 | 1349 1350**示例:** 1351 1352```ts 1353import Base from '@ohos.base'; 1354 1355let removeAllCallback = (err: Base.BusinessError) => { 1356 if (err) { 1357 console.info("removeAll failed " + JSON.stringify(err)); 1358 } else { 1359 console.info("removeAll success"); 1360 } 1361} 1362 1363Notification.removeAll(removeAllCallback); 1364``` 1365 1366## Notification.removeAll 1367 1368removeAll(bundle?: BundleOption): Promise\<void\> 1369 1370删除指定应用的所有通知(Promise形式)。 1371 1372**系统能力**:SystemCapability.Notification.Notification 1373 1374**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1375 1376**系统API**: 此接口为系统接口,三方应用不支持调用。 1377 1378**参数:** 1379 1380| 参数名 | 类型 | 必填 | 说明 | 1381| ------ | ------------ | ---- | ---------- | 1382| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 否 | 指定应用的包信息。默认为空,表示删除所有通知。 | 1383 1384**返回值:** 1385 1386| 类型 | 说明 | 1387| ------- |------------| 1388| Promise\<void\> | 无返回结果的Promise对象。 | 1389 1390**示例:** 1391 1392```ts 1393import Base from '@ohos.base'; 1394 1395// 不指定应用时,删除所有通知 1396Notification.removeAll().then(() => { 1397 console.info("removeAll success"); 1398}).catch((err: Base.BusinessError) => { 1399 console.error(`removeAll failed, code is ${err}`); 1400}); 1401``` 1402 1403## Notification.removeAll<sup>8+</sup> 1404 1405removeAll(userId: number, callback: AsyncCallback\<void>): void 1406 1407删除指定用户下的所有通知(callback形式)。 1408 1409**系统能力**:SystemCapability.Notification.Notification 1410 1411**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1412 1413**系统API**: 此接口为系统接口,三方应用不支持调用。 1414 1415**参数:** 1416 1417| 参数名 | 类型 | 必填 | 说明 | 1418| ------ | ------------ | ---- | ---------- | 1419| userId | number | 是 | 用户ID。 | 1420| callback | AsyncCallback\<void\> | 是 | 删除指定用户所有通知回调函数。 | 1421 1422**示例:** 1423 1424```ts 1425import Base from '@ohos.base'; 1426 1427function removeAllCallback(err: Base.BusinessError) { 1428 if (err) { 1429 console.info("removeAll failed " + JSON.stringify(err)); 1430 } else { 1431 console.info("removeAll success"); 1432 } 1433} 1434 1435let userId: number = 1; 1436Notification.removeAll(userId, removeAllCallback); 1437``` 1438 1439## Notification.removeAll<sup>8+</sup> 1440 1441removeAll(userId: number): Promise\<void> 1442 1443删除指定用户下的所有通知(Promise形式)。 1444 1445**系统能力**:SystemCapability.Notification.Notification 1446 1447**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1448 1449**系统API**: 此接口为系统接口,三方应用不支持调用。 1450 1451**参数:** 1452 1453| 参数名 | 类型 | 必填 | 说明 | 1454| ------ | ------------ | ---- | ---------- | 1455| userId | number | 是 | 用户ID。 | 1456 1457**示例:** 1458 1459```ts 1460import Base from '@ohos.base'; 1461 1462let userId: number = 1; 1463Notification.removeAll(userId).then(() => { 1464 console.info("removeAll success"); 1465}).catch((err: Base.BusinessError) => { 1466 console.error(`removeAll failed, code is ${err}`); 1467}); 1468``` 1469 1470 1471## Notification.getAllActiveNotifications 1472 1473getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void 1474 1475获取当前未删除的所有通知(Callback形式)。 1476 1477**系统能力**:SystemCapability.Notification.Notification 1478 1479**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1480 1481**系统API**: 此接口为系统接口,三方应用不支持调用。 1482 1483**参数:** 1484 1485| 参数名 | 类型 | 必填 | 说明 | 1486| -------- | ------------------------------------------------------------ | ---- | -------------------- | 1487| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | 是 | 获取活动通知回调函数。 | 1488 1489**示例:** 1490 1491```ts 1492import Base from '@ohos.base'; 1493import NotificationManager from '@ohos.notificationManager'; 1494 1495function getAllActiveNotificationsCallback(err: Base.BusinessError, data: NotificationManager.NotificationRequest[]) { 1496 if (err) { 1497 console.info("getAllActiveNotifications failed " + JSON.stringify(err)); 1498 } else { 1499 console.info("getAllActiveNotifications success"); 1500 } 1501} 1502 1503Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); 1504``` 1505 1506## Notification.getAllActiveNotifications 1507 1508getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> 1509 1510获取当前未删除的所有通知(Promise形式)。 1511 1512**系统能力**:SystemCapability.Notification.Notification 1513 1514**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1515 1516**系统API**: 此接口为系统接口,三方应用不支持调用。 1517 1518**返回值:** 1519 1520| 类型 | 说明 | 1521| ----------------------------------------------------------- | ------------------------------------------------------------ | 1522| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | 以Promise形式返回获取活动通知。 | 1523 1524**示例:** 1525 1526```ts 1527import Base from '@ohos.base'; 1528import NotificationManager from '@ohos.notificationManager'; 1529 1530Notification.getAllActiveNotifications().then((data: NotificationManager.NotificationRequest[]) => { 1531 console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); 1532}).catch((err: Base.BusinessError) => { 1533 console.error(`getAllActiveNotifications failed, code is ${err}`); 1534}); 1535``` 1536 1537## Notification.removeGroupByBundle<sup>8+</sup> 1538 1539removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void 1540 1541删除指定应用的指定组下的通知(Callback形式)。 1542 1543**系统能力**:SystemCapability.Notification.Notification 1544 1545**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1546 1547**系统API**: 此接口为系统接口,三方应用不支持调用。 1548 1549**参数:** 1550 1551| 参数名 | 类型 | 必填 | 说明 | 1552| --------- | --------------------- | ---- | ---------------------------- | 1553| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 1554| groupName | string | 是 | 通知组名称。 | 1555| callback | AsyncCallback\<void\> | 是 | 删除指定应用指定组下通知的回调函数。 | 1556 1557**示例:** 1558 1559```ts 1560import Base from '@ohos.base'; 1561 1562let removeGroupByBundleCallback = (err: Base.BusinessError) => { 1563 if (err) { 1564 console.info("removeGroupByBundle failed " + JSON.stringify(err)); 1565 } else { 1566 console.info("removeGroupByBundle success"); 1567 } 1568} 1569 1570let bundleOption: Notification.BundleOption = {bundle: "Bundle"}; 1571let groupName: string = "GroupName"; 1572 1573Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); 1574``` 1575 1576## Notification.removeGroupByBundle<sup>8+</sup> 1577 1578removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\> 1579 1580删除指定应用的指定组下的通知(Promise形式)。 1581 1582**系统能力**:SystemCapability.Notification.Notification 1583 1584**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1585 1586**系统API**: 此接口为系统接口,三方应用不支持调用。 1587 1588**参数:** 1589 1590| 参数名 | 类型 | 必填 | 说明 | 1591| --------- | ------------ | ---- | -------------- | 1592| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 1593| groupName | string | 是 | 通知组名称。 | 1594 1595**返回值:** 1596 1597| 类型 | 说明 | 1598| ------- |------------| 1599| Promise\<void\> | 无返回结果的Promise对象。 | 1600 1601**示例:** 1602 1603```ts 1604import Base from '@ohos.base'; 1605 1606let bundleOption: Notification.BundleOption = {bundle: "Bundle"}; 1607let groupName: string = "GroupName"; 1608Notification.removeGroupByBundle(bundleOption, groupName).then(() => { 1609 console.info("removeGroupByBundle success"); 1610}).catch((err: Base.BusinessError) => { 1611 console.error(`removeGroupByBundle failed, code is ${err}`); 1612}); 1613``` 1614 1615## Notification.setDoNotDisturbDate<sup>8+</sup> 1616 1617setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void 1618 1619设置免打扰时间(Callback形式)。 1620 1621**系统能力**:SystemCapability.Notification.Notification 1622 1623**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1624 1625**系统API**: 此接口为系统接口,三方应用不支持调用。 1626 1627**参数:** 1628 1629| 参数名 | 类型 | 必填 | 说明 | 1630| -------- | --------------------- | ---- | ---------------------- | 1631| date | [DoNotDisturbDate](#donotdisturbdate8-deprecated) | 是 | 免打扰时间选项。 | 1632| callback | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 | 1633 1634**示例:** 1635 1636```ts 1637import Base from '@ohos.base'; 1638 1639let setDoNotDisturbDateCallback = (err: Base.BusinessError) => { 1640 if (err) { 1641 console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); 1642 } else { 1643 console.info("setDoNotDisturbDate success"); 1644 } 1645} 1646 1647let doNotDisturbDate: Notification.DoNotDisturbDate = { 1648 type: Notification.DoNotDisturbType.TYPE_ONCE, 1649 begin: new Date(), 1650 end: new Date(2021, 11, 15, 18, 0) 1651}; 1652 1653Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); 1654``` 1655 1656## Notification.setDoNotDisturbDate<sup>8+</sup> 1657 1658setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\> 1659 1660设置免打扰时间(Promise形式)。 1661 1662**系统能力**:SystemCapability.Notification.Notification 1663 1664**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1665 1666**系统API**: 此接口为系统接口,三方应用不支持调用。 1667 1668**参数:** 1669 1670| 参数名 | 类型 | 必填 | 说明 | 1671| ---- | ---------------- | ---- | -------------- | 1672| date | [DoNotDisturbDate](#donotdisturbdate8-deprecated) | 是 | 免打扰时间选项。 | 1673 1674**返回值:** 1675 1676| 类型 | 说明 | 1677| ------- |------------| 1678| Promise\<void\> | 无返回结果的Promise对象。 | 1679 1680**示例:** 1681 1682```ts 1683import Base from '@ohos.base'; 1684 1685let doNotDisturbDate: Notification.DoNotDisturbDate = { 1686 type: Notification.DoNotDisturbType.TYPE_ONCE, 1687 begin: new Date(), 1688 end: new Date(2021, 11, 15, 18, 0) 1689}; 1690Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { 1691 console.info("setDoNotDisturbDate success"); 1692}).catch((err: Base.BusinessError) => { 1693 console.error(`setDoNotDisturbDate failed, code is ${err}`); 1694}); 1695``` 1696 1697 1698## Notification.setDoNotDisturbDate<sup>8+</sup> 1699 1700setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): void 1701 1702指定用户设置免打扰时间(Callback形式)。 1703 1704**系统能力**:SystemCapability.Notification.Notification 1705 1706**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1707 1708**系统API**: 此接口为系统接口,三方应用不支持调用。 1709 1710**参数:** 1711 1712| 参数名 | 类型 | 必填 | 说明 | 1713| -------- | --------------------- | ---- | ---------------------- | 1714| date | [DoNotDisturbDate](#donotdisturbdate8-deprecated) | 是 | 免打扰时间选项。 | 1715| userId | number | 是 | 设置免打扰时间的用户ID。 | 1716| callback | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 | 1717 1718**示例:** 1719 1720```ts 1721import Base from '@ohos.base'; 1722 1723let setDoNotDisturbDateCallback = (err: Base.BusinessError) => { 1724 if (err) { 1725 console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); 1726 } else { 1727 console.info("setDoNotDisturbDate success"); 1728 } 1729} 1730 1731let doNotDisturbDate: Notification.DoNotDisturbDate = { 1732 type: Notification.DoNotDisturbType.TYPE_ONCE, 1733 begin: new Date(), 1734 end: new Date(2021, 11, 15, 18, 0) 1735}; 1736 1737let userId: number = 1; 1738Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); 1739``` 1740 1741## Notification.setDoNotDisturbDate<sup>8+</sup> 1742 1743setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\> 1744 1745指定用户设置免打扰时间(Promise形式)。 1746 1747**系统能力**:SystemCapability.Notification.Notification 1748 1749**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1750 1751**系统API**: 此接口为系统接口,三方应用不支持调用。 1752 1753**参数:** 1754 1755| 参数名 | 类型 | 必填 | 说明 | 1756| ------ | ---------------- | ---- | -------------- | 1757| date | [DoNotDisturbDate](#donotdisturbdate8-deprecated) | 是 | 免打扰时间选项。 | 1758| userId | number | 是 | 设置免打扰时间的用户ID。 | 1759 1760**返回值:** 1761 1762| 类型 | 说明 | 1763| ------- |------------| 1764| Promise\<void\> | 无返回结果的Promise对象。 | 1765 1766**示例:** 1767 1768```ts 1769import Base from '@ohos.base'; 1770 1771let doNotDisturbDate: Notification.DoNotDisturbDate = { 1772 type: Notification.DoNotDisturbType.TYPE_ONCE, 1773 begin: new Date(), 1774 end: new Date(2021, 11, 15, 18, 0) 1775}; 1776 1777let userId: number = 1; 1778 1779Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { 1780 console.info("setDoNotDisturbDate success"); 1781}).catch((err: Base.BusinessError) => { 1782 console.error(`setDoNotDisturbDate failed, code is ${err}`); 1783}); 1784``` 1785 1786 1787## Notification.getDoNotDisturbDate<sup>8+</sup> 1788 1789getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void 1790 1791查询免打扰时间(Callback形式)。 1792 1793**系统能力**:SystemCapability.Notification.Notification 1794 1795**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1796 1797**系统API**: 此接口为系统接口,三方应用不支持调用。 1798 1799**参数:** 1800 1801| 参数名 | 类型 | 必填 | 说明 | 1802| -------- | --------------------------------- | ---- | ---------------------- | 1803| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8-deprecated)\> | 是 | 查询免打扰时间回调函数。 | 1804 1805**示例:** 1806 1807```ts 1808import Base from '@ohos.base'; 1809 1810let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: Notification.DoNotDisturbDate) => { 1811 if (err) { 1812 console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); 1813 } else { 1814 console.info("getDoNotDisturbDate success"); 1815 } 1816} 1817 1818Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); 1819``` 1820 1821## Notification.getDoNotDisturbDate<sup>8+</sup> 1822 1823getDoNotDisturbDate(): Promise\<DoNotDisturbDate\> 1824 1825查询免打扰时间(Promise形式)。 1826 1827**系统能力**:SystemCapability.Notification.Notification 1828 1829**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1830 1831**系统API**: 此接口为系统接口,三方应用不支持调用。 1832 1833**返回值:** 1834 1835| 类型 | 说明 | 1836| ------------------------------------------------- | ----------------------------------------- | 1837| Promise\<[DoNotDisturbDate](#donotdisturbdate8-deprecated)\> | 以Promise形式返回查询到的免打扰时间。 | 1838 1839**示例:** 1840 1841```ts 1842import Base from '@ohos.base'; 1843 1844Notification.getDoNotDisturbDate().then((data: Notification.DoNotDisturbDate) => { 1845 console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); 1846}).catch((err: Base.BusinessError) => { 1847 console.error(`getDoNotDisturbDate failed, code is ${err}`); 1848}); 1849``` 1850 1851 1852## Notification.getDoNotDisturbDate<sup>8+</sup> 1853 1854getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): void 1855 1856查询指定用户的免打扰时间(Callback形式)。 1857 1858**系统能力**:SystemCapability.Notification.Notification 1859 1860**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1861 1862**系统API**: 此接口为系统接口,三方应用不支持调用。 1863 1864**参数:** 1865 1866| 参数名 | 类型 | 必填 | 说明 | 1867| -------- | --------------------------------- | ---- | ---------------------- | 1868| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8-deprecated)\> | 是 | 查询免打扰时间回调函数。 | 1869| userId | number | 是 | 用户ID。 | 1870 1871**示例:** 1872 1873```ts 1874import Base from '@ohos.base'; 1875 1876let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: Notification.DoNotDisturbDate) => { 1877 if (err) { 1878 console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); 1879 } else { 1880 console.info("getDoNotDisturbDate success"); 1881 } 1882} 1883 1884let userId: number = 1; 1885 1886Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); 1887``` 1888 1889## Notification.getDoNotDisturbDate<sup>8+</sup> 1890 1891getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\> 1892 1893查询指定用户的免打扰时间(Promise形式)。 1894 1895**系统能力**:SystemCapability.Notification.Notification 1896 1897**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1898 1899**系统API**: 此接口为系统接口,三方应用不支持调用。 1900 1901**参数:** 1902 1903| 参数名 | 类型 | 必填 | 说明 | 1904| -------- | --------------------------------- | ---- | ---------------------- | 1905| userId | number | 是 | 用户ID。 | 1906 1907**返回值:** 1908 1909| 类型 | 说明 | 1910| ------------------------------------------------- | ----------------------------------------- | 1911| Promise\<[DoNotDisturbDate](#donotdisturbdate8-deprecated)\> | 以Promise形式返回查询到的免打扰时间。 | 1912 1913**示例:** 1914 1915```ts 1916import Base from '@ohos.base'; 1917 1918let userId: number = 1; 1919 1920Notification.getDoNotDisturbDate(userId).then((data: Notification.DoNotDisturbDate) => { 1921 console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); 1922}).catch((err: Base.BusinessError) => { 1923 console.error(`getDoNotDisturbDate failed, code is ${err}`); 1924}); 1925``` 1926 1927 1928## Notification.supportDoNotDisturbMode<sup>8+</sup> 1929 1930supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void 1931 1932查询是否支持免打扰功能(Callback形式)。 1933 1934**系统能力**:SystemCapability.Notification.Notification 1935 1936**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1937 1938**系统API**: 此接口为系统接口,三方应用不支持调用。 1939 1940**参数:** 1941 1942| 参数名 | 类型 | 必填 | 说明 | 1943| -------- | ------------------------ | ---- | -------------------------------- | 1944| callback | AsyncCallback\<boolean\> | 是 | 查询是否支持免打扰功能回调函数。 | 1945 1946**示例:** 1947 1948```ts 1949import Base from '@ohos.base'; 1950 1951let supportDoNotDisturbModeCallback = (err: Base.BusinessError, data: boolean) => { 1952 if (err) { 1953 console.info("supportDoNotDisturbMode failed " + JSON.stringify(err)); 1954 } else { 1955 console.info("supportDoNotDisturbMode success"); 1956 } 1957} 1958 1959Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); 1960``` 1961 1962## Notification.supportDoNotDisturbMode<sup>8+</sup> 1963 1964supportDoNotDisturbMode(): Promise\<boolean\> 1965 1966查询是否支持免打扰功能(Promise形式)。 1967 1968**系统能力**:SystemCapability.Notification.Notification 1969 1970**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 1971 1972**系统API**: 此接口为系统接口,三方应用不支持调用。 1973 1974**返回值:** 1975 1976| 类型 | 说明 | 1977| ----------------------------------------------------------- | ------------------------------------------------------------ | 1978| Promise\<boolean\> | 以Promise形式返回获取是否支持免打扰功能的结果。 | 1979 1980**示例:** 1981 1982```ts 1983import Base from '@ohos.base'; 1984 1985Notification.supportDoNotDisturbMode().then((data: boolean) => { 1986 console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); 1987}).catch((err: Base.BusinessError) => { 1988 console.error(`supportDoNotDisturbMode failed, code is ${err}`); 1989}); 1990``` 1991 1992## Notification.enableDistributed<sup>8+</sup> 1993 1994enableDistributed(enable: boolean, callback: AsyncCallback\<void\>): void 1995 1996设置设备是否支持分布式通知(Callback形式)。 1997 1998**系统能力**:SystemCapability.Notification.Notification 1999 2000**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2001 2002**系统API**: 此接口为系统接口,三方应用不支持调用。 2003 2004**参数:** 2005 2006| 参数名 | 类型 | 必填 | 说明 | 2007| -------- | ------------------------ | ---- | -------------------------- | 2008| enable | boolean | 是 | 是否支持。 | 2009| callback | AsyncCallback\<void\> | 是 | 设置设备是否支持分布式通知的回调函数。 | 2010 2011**示例:** 2012 2013```ts 2014import Base from '@ohos.base'; 2015 2016let enabledNotificationCallback = (err: Base.BusinessError) => { 2017 if (err) { 2018 console.info("enableDistributed failed " + JSON.stringify(err)); 2019 } else { 2020 console.info("enableDistributed success"); 2021 } 2022}; 2023 2024let enable: boolean = true; 2025 2026Notification.enableDistributed(enable, enabledNotificationCallback); 2027``` 2028 2029## Notification.enableDistributed<sup>8+</sup> 2030 2031enableDistributed(enable: boolean): Promise\<void> 2032 2033设置设备是否支持分布式通知(Promise形式)。 2034 2035**系统能力**:SystemCapability.Notification.Notification 2036 2037**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2038 2039**系统API**: 此接口为系统接口,三方应用不支持调用。 2040 2041**参数:** 2042 2043| 参数名 | 类型 | 必填 | 说明 | 2044| -------- | ------------------------ | ---- | -------------------------- | 2045| enable | boolean | 是 | 是否支持。 | 2046 2047**示例:** 2048 2049```ts 2050import Base from '@ohos.base'; 2051 2052let enable: boolean = true; 2053Notification.enableDistributed(enable).then(() => { 2054 console.info("enableDistributed success"); 2055}).catch((err: Base.BusinessError) => { 2056 console.error(`enableDistributed failed, code is ${err}`); 2057}); 2058``` 2059 2060## Notification.enableDistributedByBundle<sup>8+</sup> 2061 2062enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void 2063 2064设置指定应用是否支持分布式通知(Callback形式)。 2065 2066**系统能力**:SystemCapability.Notification.Notification 2067 2068**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2069 2070**系统API**: 此接口为系统接口,三方应用不支持调用。 2071 2072**参数:** 2073 2074| 参数名 | 类型 | 必填 | 说明 | 2075| -------- | ------------------------ | ---- | -------------------------- | 2076| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包信息。 | 2077| enable | boolean | 是 | 是否支持。 | 2078| callback | AsyncCallback\<void\> | 是 | 应用程序是否支持分布式通知的回调函数。 | 2079 2080**示例:** 2081 2082```ts 2083import Base from '@ohos.base'; 2084 2085let enableDistributedByBundleCallback = (err: Base.BusinessError) => { 2086 if (err) { 2087 console.info("enableDistributedByBundle failed " + JSON.stringify(err)); 2088 } else { 2089 console.info("enableDistributedByBundle success"); 2090 } 2091}; 2092 2093let bundle: Notification.BundleOption = { 2094 bundle: "bundleName1", 2095}; 2096 2097let enable: boolean = true; 2098 2099Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundleCallback); 2100``` 2101 2102## Notification.enableDistributedByBundle<sup>8+</sup> 2103 2104enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void> 2105 2106设置指定应用是否支持分布式通知(Promise形式)。 2107 2108**系统能力**:SystemCapability.Notification.Notification 2109 2110**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2111 2112**系统API**: 此接口为系统接口,三方应用不支持调用。 2113 2114**参数:** 2115 2116| 参数名 | 类型 | 必填 | 说明 | 2117| -------- | ------------------------ | ---- | -------------------------- | 2118| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包。 | 2119| enable | boolean | 是 | 是否支持。 | 2120 2121**示例:** 2122 2123```ts 2124import Base from '@ohos.base'; 2125 2126let enable: boolean = true; 2127 2128let bundle: Notification.BundleOption = { 2129 bundle: "bundleName1", 2130}; 2131 2132Notification.enableDistributedByBundle(bundle, enable).then(() => { 2133 console.info("enableDistributedByBundle success"); 2134}).catch((err: Base.BusinessError) => { 2135 console.error(`enableDistributedByBundle failed, code is ${err}`); 2136}); 2137 2138``` 2139 2140## Notification.isDistributedEnabledByBundle<sup>8+</sup> 2141 2142isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void 2143 2144根据应用的包获取应用程序是否支持分布式通知(Callback形式)。 2145 2146**系统能力**:SystemCapability.Notification.Notification 2147 2148**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2149 2150**系统API**: 此接口为系统接口,三方应用不支持调用。 2151 2152**参数:** 2153 2154| 参数名 | 类型 | 必填 | 说明 | 2155| -------- | ------------------------ | ---- | -------------------------- | 2156| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包。 | 2157| callback | AsyncCallback\<boolean\> | 是 | 查询指定应用是否支持分布式通知的回调函数。 | 2158 2159**示例:** 2160 2161```ts 2162import Base from '@ohos.base'; 2163 2164let isDistributedEnabledByBundleCallback = (err: Base.BusinessError, data: boolean) => { 2165 if (err) { 2166 console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err)); 2167 } else { 2168 console.info("isDistributedEnabledByBundle success" + JSON.stringify(data)); 2169 } 2170}; 2171 2172let bundle: Notification.BundleOption = { 2173 bundle: "bundleName1", 2174}; 2175 2176Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback); 2177``` 2178 2179## Notification.isDistributedEnabledByBundle<sup>8+</sup> 2180 2181isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean> 2182 2183查询指定应用是否支持分布式通知(Promise形式)。 2184 2185**系统能力**:SystemCapability.Notification.Notification 2186 2187**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2188 2189**系统API**: 此接口为系统接口,三方应用不支持调用。 2190 2191**参数:** 2192 2193| 参数名 | 类型 | 必填 | 说明 | 2194| -------- | ------------------------ | ---- | -------------------------- | 2195| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是 | 应用的包。 | 2196 2197**返回值:** 2198 2199| 类型 | 说明 | 2200| ------------------ | ------------------------------------------------- | 2201| Promise\<boolean\> | Promise方式返回指定应用是否支持分布式通知的结果。 | 2202 2203**示例:** 2204 2205```ts 2206import Base from '@ohos.base'; 2207 2208let bundle: Notification.BundleOption = { 2209 bundle: "bundleName1", 2210}; 2211 2212Notification.isDistributedEnabledByBundle(bundle).then((data: boolean) => { 2213 console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); 2214}).catch((err: Base.BusinessError) => { 2215 console.error(`isDistributedEnabledByBundle failed, code is ${err}`); 2216}); 2217``` 2218 2219 2220## Notification.getDeviceRemindType<sup>8+</sup> 2221 2222getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void 2223 2224获取通知的提醒方式(Callback形式)。 2225 2226**系统能力**:SystemCapability.Notification.Notification 2227 2228**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2229 2230**系统API**: 此接口为系统接口,三方应用不支持调用。 2231 2232**参数:** 2233 2234| 参数名 | 类型 | 必填 | 说明 | 2235| -------- | --------------------------------- | ---- | -------------------------- | 2236| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype8-deprecated)\> | 是 | 获取通知提醒方式的回调函数。 | 2237 2238**示例:** 2239 2240```ts 2241import Base from '@ohos.base'; 2242 2243let getDeviceRemindTypeCallback = (err: Base.BusinessError, data: Notification.DeviceRemindType) => { 2244 if (err) { 2245 console.info("getDeviceRemindType failed " + JSON.stringify(err)); 2246 } else { 2247 console.info("getDeviceRemindType success"); 2248 } 2249}; 2250 2251Notification.getDeviceRemindType(getDeviceRemindTypeCallback); 2252``` 2253 2254## Notification.getDeviceRemindType<sup>8+</sup> 2255 2256getDeviceRemindType(): Promise\<DeviceRemindType\> 2257 2258获取通知的提醒方式(Promise形式)。 2259 2260**系统能力**:SystemCapability.Notification.Notification 2261 2262**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER 2263 2264**系统API**: 此接口为系统接口,三方应用不支持调用。 2265 2266**返回值:** 2267 2268| 类型 | 说明 | 2269| ------------------ | --------------- | 2270| Promise\<[DeviceRemindType](#deviceremindtype8-deprecated)\> | Promise方式返回获取通知提醒方式的结果。 | 2271 2272**示例:** 2273 2274```ts 2275import Base from '@ohos.base'; 2276 2277Notification.getDeviceRemindType().then((data: Notification.DeviceRemindType) => { 2278 console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); 2279}).catch((err: Base.BusinessError) => { 2280 console.error(`getDeviceRemindType failed, code is ${err}`); 2281}); 2282``` 2283 2284## DoNotDisturbDate<sup>8+</sup> <sup>deprecated</sup> 2285 2286**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 2287 2288> **说明:** 2289> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DoNotDisturbDate](js-apis-notificationManager-sys.md#donotdisturbdate)替代 2290 2291**系统API**:此接口为系统接口,三方应用不支持调用。 2292 2293| 名称 | 类型 | 可读 | 可写 | 说明 | 2294| ----- | -------------------------------------- | ---- | ---- | ---------------------- | 2295| type | [DoNotDisturbType](./js-apis-notificationManager-sys.md#donotdisturbtype) | 是 | 是 | 免打扰设置的时间类型。 | 2296| begin | Date | 是 | 是 | 免打扰设置的起点时间。 | 2297| end | Date | 是 | 是 | 免打扰设置的终点时间。 | 2298 2299## DoNotDisturbType<sup>8+</sup> <sup>deprecated</sup> 2300 2301**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 2302 2303> **说明:** 2304> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DoNotDisturbType](js-apis-notificationManager-sys.md#donotdisturbtype)替代 2305 2306**系统API**: 此接口为系统接口,三方应用不支持调用。 2307 2308| 名称 | 值 | 说明 | 2309| ------------ | ---------------- | ------------------------------------------ | 2310| TYPE_NONE | 0 | 非通知勿扰类型。 | 2311| TYPE_ONCE | 1 | 以设置时间段(只看小时和分钟)一次执行勿扰。 | 2312| TYPE_DAILY | 2 | 以设置时间段(只看小时和分钟)每天执行勿扰。 | 2313| TYPE_CLEARLY | 3 | 以设置时间段(明确年月日时分)执行勿扰。 | 2314 2315## DeviceRemindType<sup>8+</sup> <sup>deprecated</sup> 2316 2317**系统能力**:SystemCapability.Notification.Notification 2318 2319**系统API**: 此接口为系统接口,三方应用不支持调用。 2320 2321> **说明:** 2322> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DeviceRemindType](js-apis-notificationManager-sys.md#deviceremindtype)替代 2323 2324| 名称 | 值 | 说明 | 2325| -------------------- | --- | --------------------------------- | 2326| IDLE_DONOT_REMIND | 0 | 设备未被使用,无需提醒。 | 2327| IDLE_REMIND | 1 | 提醒设备未被使用。 | 2328| ACTIVE_DONOT_REMIND | 2 | 设备正在使用,无需提醒。 | 2329| ACTIVE_REMIND | 3 | 提醒设备正在使用。 | 2330 2331 2332## SourceType<sup>8+</sup> <sup>deprecated</sup> 2333 2334**系统能力**:SystemCapability.Notification.Notification 2335 2336**系统API**: 此接口为系统接口,三方应用不支持调用。 2337 2338> **说明:** 2339> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.SourceType](js-apis-notificationManager-sys.md#sourcetype)替代 2340 2341| 名称 | 值 | 说明 | 2342| -------------------- | --- | -------------------- | 2343| TYPE_NORMAL | 0 | 一般通知。 | 2344| TYPE_CONTINUOUS | 1 | 连续通知。 | 2345| TYPE_TIMER | 2 | 计划通知。 | 2346 2347## RemoveReason <sup>deprecated</sup> 2348 2349**系统能力**:SystemCapability.Notification.Notification 2350 2351**系统API**: 此接口为系统接口,三方应用不支持调用。 2352 2353> **说明:** 2354> 从 API version 7开始支持,从API version 9开始废弃。建议使用[notificationManager.RemoveReason](js-apis-notificationSubscribe-sys.md#removereason)替代 2355 2356| 名称 | 值 | 说明 | 2357| -------------------- | --- | -------------------- | 2358| CLICK_REASON_REMOVE | 1 | 点击通知后删除通知。 | 2359| CANCEL_REASON_REMOVE | 2 | 用户删除通知。 |