1# @ohos.notificationSubscribe (NotificationSubscribe) 2 3The **notificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```ts 14import notificationSubscribe from '@ohos.notificationSubscribe'; 15``` 16 17## notificationSubscribe.subscribe 18 19subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void 20 21Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. 22 23**System capability**: SystemCapability.Notification.Notification 24 25**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 26 27**System API**: This is a system API. 28 29**Parameters** 30 31| Name | Type | Mandatory| Description | 32| ---------- | ------------------------- | ---- | ---------------- | 33| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber. | 34| info | [NotificationSubscribeInfo](js-apis-notification.md#notificationsubscribeinfo) | Yes | Notification subscription information.| 35| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 36 37**Error codes** 38 39For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 40 41| ID| Error Message | 42| -------- | ----------------------------------- | 43| 1600001 | Internal error. | 44| 1600002 | Marshalling or unmarshalling error. | 45| 1600003 | Failed to connect service. | 46| 1600012 | No memory space. | 47 48**Example** 49 50```ts 51import Base from '@ohos.base'; 52 53// subscribe callback 54let subscribeCallback = (err: Base.BusinessError) => { 55 if (err) { 56 console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); 57 } else { 58 console.info("subscribe success"); 59 } 60} 61let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 62 console.info("Consume callback: " + JSON.stringify(data)); 63} 64let subscriber: notificationSubscribe.NotificationSubscriber = { 65 onConsume: onConsumeCallback 66}; 67// Bundle names are not verified. You need to determine the target bundle names. 68let info: notificationSubscribe.NotificationSubscribeInfo = { 69 bundleNames: ["bundleName1","bundleName2"] 70}; 71notificationSubscribe.subscribe(subscriber, info, subscribeCallback); 72``` 73 74## notificationSubscribe.subscribe 75 76subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 77 78Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. 79 80**System capability**: SystemCapability.Notification.Notification 81 82**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 83 84**System API**: This is a system API. 85 86**Parameters** 87 88| Name | Type | Mandatory| Description | 89| ---------- | ---------------------- | ---- | ---------------- | 90| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber. | 91| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 92 93**Error codes** 94 95For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 96 97| ID| Error Message | 98| -------- | ----------------------------------- | 99| 1600001 | Internal error. | 100| 1600002 | Marshalling or unmarshalling error. | 101| 1600003 | Failed to connect service. | 102| 1600012 | No memory space. | 103 104**Example** 105 106```ts 107import Base from '@ohos.base'; 108 109let subscribeCallback = (err: Base.BusinessError) => { 110 if (err) { 111 console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); 112 } else { 113 console.info("subscribe success"); 114 } 115} 116let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 117 console.info("Consume callback: " + JSON.stringify(data)); 118} 119let subscriber: notificationSubscribe.NotificationSubscriber = { 120 onConsume: onConsumeCallback 121}; 122notificationSubscribe.subscribe(subscriber, subscribeCallback); 123``` 124 125 126 127## notificationSubscribe.subscribe 128 129subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\> 130 131Subscribes to a notification with the subscription information specified. This API uses a promise to return the result. 132 133**System capability**: SystemCapability.Notification.Notification 134 135**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 136 137**System API**: This is a system API. 138 139**Parameters** 140 141| Name | Type | Mandatory| Description | 142| ---------- | ------------------------- | ---- | ------------ | 143| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber.| 144| info | [NotificationSubscribeInfo](js-apis-notification.md#notificationsubscribeinfo) | No | Notification subscription information. By default, this parameter is left empty, which means to subscribe to notifications of all applications under this user. | 145 146**Return value** 147 148| Type | Description | 149| ------- |------------------| 150| Promise\<void\> | Promise that returns no value.| 151 152**Error codes** 153 154For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 155 156| ID| Error Message | 157| -------- | ----------------------------------- | 158| 1600001 | Internal error. | 159| 1600002 | Marshalling or unmarshalling error. | 160| 1600003 | Failed to connect service. | 161| 1600012 | No memory space. | 162 163**Example** 164 165```ts 166import Base from '@ohos.base'; 167 168let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 169 console.info("Consume callback: " + JSON.stringify(data)); 170} 171let subscriber: notificationSubscribe.NotificationSubscriber = { 172 onConsume: onConsumeCallback 173}; 174notificationSubscribe.subscribe(subscriber).then(() => { 175 console.info("subscribe success"); 176}).catch((err: Base.BusinessError) => { 177 console.error("subscribe fail: " + JSON.stringify(err)); 178}); 179``` 180 181 182## notificationSubscribe.subscribeSelf<sup>11+</sup> 183 184subscribeSelf(subscriber: NotificationSubscriber): Promise\<void\> 185 186Subscribes to a notification with the subscription information specified. This API uses a promise to return the result. 187 188**System capability**: SystemCapability.Notification.Notification 189 190**System API**: This is a system API. 191 192**Parameters** 193 194| Name | Type | Mandatory| Description | 195| ---------- | ------------------------- | ---- | ------------ | 196| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber.| 197 198**Return value** 199 200| Type | Description | 201| ------- |------------------| 202| Promise\<void\> | Promise that returns no value.| 203 204**Error codes** 205 206For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 207 208| ID| Error Message | 209| -------- | ----------------------------------- | 210| 1600001 | Internal error. | 211| 1600002 | Marshalling or unmarshalling error. | 212| 1600003 | Failed to connect service. | 213| 1600012 | No memory space. | 214 215**Example** 216 217```ts 218import Base from '@ohos.base'; 219 220let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 221 console.info("Consume callback: " + JSON.stringify(data)); 222} 223let subscriber: notificationSubscribe.NotificationSubscriber = { 224 onConsume: onConsumeCallback 225}; 226notificationSubscribe.subscribeSelf(subscriber).then(() => { 227 console.info("subscribeSelf success"); 228}).catch((err: Base.BusinessError) => { 229 console.error("subscribeSelf fail: " + JSON.stringify(err)); 230}); 231``` 232 233 234 235## notificationSubscribe.unsubscribe 236 237unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 238 239Unsubscribes from a notification. This API uses an asynchronous callback to return the result. 240 241**System capability**: SystemCapability.Notification.Notification 242 243**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 244 245**System API**: This is a system API. 246 247**Parameters** 248 249| Name | Type | Mandatory| Description | 250| ---------- | ---------------------- | ---- | -------------------- | 251| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber. | 252| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 253 254**Error codes** 255 256For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 257 258| ID| Error Message | 259| -------- | ----------------------------------- | 260| 1600001 | Internal error. | 261| 1600002 | Marshalling or unmarshalling error. | 262| 1600003 | Failed to connect service. | 263 264**Example** 265 266```ts 267import Base from '@ohos.base'; 268 269let unsubscribeCallback = (err: Base.BusinessError) => { 270 if (err) { 271 console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); 272 } else { 273 console.info("unsubscribe success"); 274 } 275} 276let onDisconnectCallback = () => { 277 console.info("subscribe disconnect"); 278} 279let subscriber: notificationSubscribe.NotificationSubscriber = { 280 onDisconnect: onDisconnectCallback 281}; 282notificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); 283``` 284 285## notificationSubscribe.unsubscribe 286 287unsubscribe(subscriber: NotificationSubscriber): Promise\<void\> 288 289Unsubscribes from a notification. This API uses a promise to return the result. 290 291**System capability**: SystemCapability.Notification.Notification 292 293**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 294 295**System API**: This is a system API. 296 297**Parameters** 298 299| Name | Type | Mandatory| Description | 300| ---------- | ---------------------- | ---- | ------------ | 301| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber.| 302 303**Return value** 304 305| Type | Description | 306| ------- |------------| 307| Promise\<void\> | Promise that returns no value.| 308 309**Error codes** 310 311For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 312 313| ID| Error Message | 314| -------- | ----------------------------------- | 315| 1600001 | Internal error. | 316| 1600002 | Marshalling or unmarshalling error. | 317| 1600003 | Failed to connect service. | 318 319**Example** 320 321```ts 322import Base from '@ohos.base'; 323 324let onDisconnectCallback = () => { 325 console.info("subscribe disconnect"); 326} 327let subscriber: notificationSubscribe.NotificationSubscriber = { 328 onDisconnect: onDisconnectCallback 329}; 330notificationSubscribe.unsubscribe(subscriber).then(() => { 331 console.info("unsubscribe success"); 332}).catch((err: Base.BusinessError) => { 333 console.error("unsubscribe fail: " + JSON.stringify(err)); 334}); 335``` 336 337## notificationSubscribe.remove 338 339remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void 340 341Removes a notification based on the bundle information and notification key. This API uses an asynchronous callback to return the result. 342 343**System capability**: SystemCapability.Notification.Notification 344 345**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 346 347**System API**: This is a system API. 348 349**Parameters** 350 351| Name | Type | Mandatory| Description | 352| --------------- | ----------------------------------| ---- | -------------------- | 353| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 354| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 355| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 356| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 357 358**Error codes** 359 360For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 361 362| ID| Error Message | 363| -------- | ---------------------------------------- | 364| 1600001 | Internal error. | 365| 1600002 | Marshalling or unmarshalling error. | 366| 1600003 | Failed to connect service. | 367| 1600007 | The notification is not exist. | 368| 17700001 | The specified bundle name was not found. | 369 370**Example** 371 372```ts 373import Base from '@ohos.base'; 374import NotificationManager from '@ohos.notificationManager'; 375 376let removeCallback = (err: Base.BusinessError) => { 377 if (err) { 378 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 379 } else { 380 console.info("remove success"); 381 } 382} 383let bundle: NotificationManager.BundleOption = { 384 bundle: "bundleName1", 385}; 386let notificationKey: notificationSubscribe.NotificationKey = { 387 id: 0, 388 label: "label", 389}; 390let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 391notificationSubscribe.remove(bundle, notificationKey, reason, removeCallback); 392``` 393 394 395 396## notificationSubscribe.remove 397 398remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\> 399 400Removes a notification based on the specified bundle information and notification key. This API uses a promise to return the result. 401 402**System capability**: SystemCapability.Notification.Notification 403 404**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 405 406**System API**: This is a system API. 407 408**Parameters** 409 410| Name | Type | Mandatory| Description | 411| --------------- | --------------- | ---- | ---------- | 412| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 413| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 414| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 415 416**Return value** 417 418| Type | Description | 419| ------- |------------| 420| Promise\<void\> | Promise that returns no value.| 421 422**Error codes** 423 424For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 425 426| ID| Error Message | 427| -------- | ---------------------------------------- | 428| 1600001 | Internal error. | 429| 1600002 | Marshalling or unmarshalling error. | 430| 1600003 | Failed to connect service. | 431| 1600007 | The notification is not exist. | 432| 17700001 | The specified bundle name was not found. | 433 434**Example** 435 436```ts 437import Base from '@ohos.base'; 438import NotificationManager from '@ohos.notificationManager'; 439 440let bundle: NotificationManager.BundleOption = { 441 bundle: "bundleName1", 442}; 443let notificationKey: notificationSubscribe.NotificationKey = { 444 id: 0, 445 label: "label", 446}; 447let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 448notificationSubscribe.remove(bundle, notificationKey, reason).then(() => { 449 console.info("remove success"); 450}).catch((err: Base.BusinessError) => { 451 console.error("remove fail: " + JSON.stringify(err)); 452}); 453``` 454 455## notificationSubscribe.remove 456 457remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void 458 459Removes a notification based on the specified unique notification ID. This API uses an asynchronous callback to return the result. 460 461**System capability**: SystemCapability.Notification.Notification 462 463**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 464 465**System API**: This is a system API. 466 467**Parameters** 468 469| Name | Type | Mandatory| Description | 470| -------- | --------------------- | ---- | -------------------- | 471| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) object of [SubscribeCallbackData](js-apis-notification.md#subscribecallbackdata) of the [onConsume](js-apis-inner-notification-notificationSubscriber.md#onConsume) callback.| 472| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 473| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 474 475**Error codes** 476 477For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 478 479| ID| Error Message | 480| -------- | ----------------------------------- | 481| 1600001 | Internal error. | 482| 1600002 | Marshalling or unmarshalling error. | 483| 1600003 | Failed to connect service. | 484| 1600007 | The notification is not exist. | 485 486**Example** 487 488```ts 489import Base from '@ohos.base'; 490 491let hashCode: string = 'hashCode'; 492let removeCallback = (err: Base.BusinessError) => { 493 if (err) { 494 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 495 } else { 496 console.info("remove success"); 497 } 498} 499let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 500notificationSubscribe.remove(hashCode, reason, removeCallback); 501``` 502 503## notificationSubscribe.remove 504 505remove(hashCode: string, reason: RemoveReason): Promise\<void\> 506 507Removes a notification based on the specified unique notification ID. This API uses a promise to return the result. 508 509**System capability**: SystemCapability.Notification.Notification 510 511**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 512 513**System API**: This is a system API. 514 515**Parameters** 516 517| Name | Type | Mandatory| Description | 518| -------- | ---------- | ---- | ---------- | 519| hashCode | string | Yes | Unique notification ID.| 520| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 521 522**Return value** 523 524| Type | Description| 525| ------- |--| 526| Promise\<void\> | Promise that returns no value.| 527 528**Error codes** 529 530For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 531 532| ID| Error Message | 533| -------- | ----------------------------------- | 534| 1600001 | Internal error. | 535| 1600002 | Marshalling or unmarshalling error. | 536| 1600003 | Failed to connect service. | 537| 1600007 | The notification is not exist. | 538 539**Example** 540 541```ts 542import Base from '@ohos.base'; 543 544let hashCode: string = 'hashCode'; 545let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 546notificationSubscribe.remove(hashCode, reason).then(() => { 547 console.info("remove success"); 548}).catch((err: Base.BusinessError) => { 549 console.error("remove fail: " + JSON.stringify(err)); 550}); 551``` 552## notificationSubscribe.remove<sup>10+<sup> 553 554remove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback\<void\>): void 555 556Removes specified notifications. This API uses an asynchronous callback to return the result. 557 558**System capability**: SystemCapability.Notification.Notification 559 560**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 561 562**System API**: This is a system API. 563 564**Parameters** 565 566| Name | Type | Mandatory| Description | 567|-----------|-------------------------------| ---- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 568| hashCodes | Array\<String\> | Yes | Array of unique notification IDs. It is the **hashCode** in the [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) object of [SubscribeCallbackData](js-apis-notification.md#subscribecallbackdata) of the [onConsume](js-apis-inner-notification-notificationSubscriber.md#onConsume) callback.| 569| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 570| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 571 572**Error codes** 573 574For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 575 576| ID| Error Message | 577| -------- | ----------------------------------- | 578| 1600001 | Internal error. | 579| 1600002 | Marshalling or unmarshalling error. | 580| 1600003 | Failed to connect service. | 581 582**Example** 583 584```ts 585import Base from '@ohos.base'; 586 587let hashCodes: string[] = ['hashCode1', 'hashCode2']; 588let removeCallback = (err: Base.BusinessError) => { 589 if (err) { 590 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 591 } else { 592 console.info("remove success"); 593 } 594} 595let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 596notificationSubscribe.remove(hashCodes, reason, removeCallback); 597``` 598 599## notificationSubscribe.remove<sup>10+<sup> 600 601remove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\> 602 603Removes specified notifications. This API uses a promise to return the result. 604 605**System capability**: SystemCapability.Notification.Notification 606 607**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 608 609**System API**: This is a system API. 610 611**Parameters** 612 613| Name | Type | Mandatory| Description | 614|-----------|-------------------------------| ---- |-------------| 615| hashCodes | Array\<String\> | Yes | Array of unique notification IDs.| 616| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 617 618**Return value** 619 620| Type | Description | 621| ------- |------------------| 622| Promise\<void\> | Promise that returns no value.| 623 624**Error codes** 625 626For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 627 628| ID| Error Message | 629| -------- | ----------------------------------- | 630| 1600001 | Internal error. | 631| 1600002 | Marshalling or unmarshalling error. | 632| 1600003 | Failed to connect service. | 633 634**Example** 635 636```ts 637import Base from '@ohos.base'; 638 639let hashCodes: string[] = ['hashCode1','hashCode2']; 640let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 641notificationSubscribe.remove(hashCodes, reason).then(() => { 642 console.info("remove success"); 643}).catch((err: Base.BusinessError) => { 644 console.error("remove fail: " + JSON.stringify(err)); 645}); 646``` 647 648## notificationSubscribe.removeAll 649 650removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void 651 652Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. 653 654**System capability**: SystemCapability.Notification.Notification 655 656**System API**: This is a system API. 657 658**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 659 660**Parameters** 661 662| Name | Type | Mandatory| Description | 663| -------- | --------------------- | ---- | ---------------------------- | 664| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 665| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 666 667**Error codes** 668 669For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 670 671| ID| Error Message | 672| -------- | ---------------------------------------- | 673| 1600001 | Internal error. | 674| 1600002 | Marshalling or unmarshalling error. | 675| 1600003 | Failed to connect service. | 676| 17700001 | The specified bundle name was not found. | 677 678**Example** 679 680```ts 681import Base from '@ohos.base'; 682 683let removeAllCallback = (err: Base.BusinessError) => { 684 if (err) { 685 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 686 } else { 687 console.info("removeAll success"); 688 } 689} 690let bundle: notificationSubscribe.BundleOption = { 691 bundle: "bundleName1", 692}; 693notificationSubscribe.removeAll(bundle, removeAllCallback); 694``` 695 696## notificationSubscribe.removeAll 697 698removeAll(callback: AsyncCallback\<void\>): void 699 700Removes all notifications. This API uses an asynchronous callback to return the result. 701 702**System capability**: SystemCapability.Notification.Notification 703 704**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 705 706**System API**: This is a system API. 707 708**Parameters** 709 710| Name | Type | Mandatory| Description | 711| -------- | --------------------- | ---- | -------------------- | 712| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 713 714**Error codes** 715 716For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 717 718| ID| Error Message | 719| -------- | ----------------------------------- | 720| 1600001 | Internal error. | 721| 1600002 | Marshalling or unmarshalling error. | 722| 1600003 | Failed to connect service. | 723 724**Example** 725 726```ts 727import Base from '@ohos.base'; 728 729let removeAllCallback = (err: Base.BusinessError) => { 730 if (err) { 731 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 732 } else { 733 console.info("removeAll success"); 734 } 735} 736notificationSubscribe.removeAll(removeAllCallback); 737``` 738 739## notificationSubscribe.removeAll 740 741removeAll(bundle?: BundleOption): Promise\<void\> 742 743Removes all notifications for a specified application. This API uses a promise to return the result. 744 745**System capability**: SystemCapability.Notification.Notification 746 747**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 748 749**System API**: This is a system API. 750 751**Parameters** 752 753| Name | Type | Mandatory| Description | 754| ------ | ------------ | ---- | ---------- | 755| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | No | Bundle information of the application. By default, this parameter is left empty, indicating that all notifications will be removed.| 756 757**Return value** 758 759| Type | Description | 760| ------- |------------| 761| Promise\<void\> | Promise that returns no value.| 762 763**Error codes** 764 765For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 766 767| ID| Error Message | 768| -------- | ---------------------------------------- | 769| 1600001 | Internal error. | 770| 1600002 | Marshalling or unmarshalling error. | 771| 1600003 | Failed to connect service. | 772| 17700001 | The specified bundle name was not found. | 773 774**Example** 775 776```ts 777import Base from '@ohos.base'; 778 779// If no application is specified, notifications of all applications are deleted. 780notificationSubscribe.removeAll().then(() => { 781 console.info("removeAll success"); 782}).catch((err: Base.BusinessError) => { 783 console.error("removeAll fail: " + JSON.stringify(err)); 784}); 785``` 786 787## notificationSubscribe.removeAll 788 789removeAll(userId: number, callback: AsyncCallback\<void>): void 790 791Removes all notifications for a specified user. This API uses an asynchronous callback to return the result. 792 793**System capability**: SystemCapability.Notification.Notification 794 795**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 796 797**System API**: This is a system API. 798 799**Parameters** 800 801| Name | Type | Mandatory| Description | 802| ------ | ------------ | ---- | ---------- | 803| userId | number | Yes | User ID.| 804| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 805 806**Error codes** 807 808For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 809 810| ID| Error Message | 811| -------- | ----------------------------------- | 812| 1600001 | Internal error. | 813| 1600002 | Marshalling or unmarshalling error. | 814| 1600003 | Failed to connect service. | 815| 1600008 | The user is not exist. | 816 817**Example** 818 819```ts 820import Base from '@ohos.base'; 821 822let removeAllCallback = (err: Base.BusinessError) => { 823 if (err) { 824 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 825 } else { 826 console.info("removeAll success"); 827 } 828} 829let userId: number = 1; 830notificationSubscribe.removeAll(userId, removeAllCallback); 831``` 832 833## notificationSubscribe.removeAll 834 835removeAll(userId: number): Promise\<void> 836 837Removes all notifications for a specified user. This API uses a promise to return the result. 838 839**System capability**: SystemCapability.Notification.Notification 840 841**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 842 843**System API**: This is a system API. 844 845**Parameters** 846 847| Name | Type | Mandatory| Description | 848| ------ | ------------ | ---- | ---------- | 849| userId | number | Yes | User ID.| 850 851**Error codes** 852 853For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 854 855| ID| Error Message | 856| -------- | ----------------------------------- | 857| 1600001 | Internal error. | 858| 1600002 | Marshalling or unmarshalling error. | 859| 1600003 | Failed to connect service. | 860| 1600008 | The user is not exist. | 861 862**Example** 863 864```ts 865import Base from '@ohos.base'; 866 867let userId: number = 1; 868notificationSubscribe.removeAll(userId).then(() => { 869 console.info("removeAll success"); 870}).catch((err: Base.BusinessError) => { 871 console.error("removeAll fail: " + JSON.stringify(err)); 872}); 873``` 874 875## NotificationKey 876 877**System capability**: SystemCapability.Notification.Notification 878 879**System API**: This is a system API. 880 881| Name | Type | Mandatory| Description | 882| ----- | ------ | --- | -------- | 883| id | number | Yes | Notification ID. | 884| label | string | No | Notification label. This parameter is left empty by default.| 885 886## RemoveReason 887 888**System capability**: SystemCapability.Notification.Notification 889 890**System API**: This is a system API. 891 892| Name | Value | Description | 893| -------------------- | --- | -------------------- | 894| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | 895| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | 896