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 and cannot be called by third-party applications. 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) | No | 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 183## notificationSubscribe.unsubscribe 184 185unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 186 187Unsubscribes from a notification. This API uses an asynchronous callback to return the result. 188 189**System capability**: SystemCapability.Notification.Notification 190 191**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 192 193**System API**: This is a system API and cannot be called by third-party applications. 194 195**Parameters** 196 197| Name | Type | Mandatory| Description | 198| ---------- | ---------------------- | ---- | -------------------- | 199| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber. | 200| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 201 202**Error codes** 203 204For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 205 206| ID| Error Message | 207| -------- | ----------------------------------- | 208| 1600001 | Internal error. | 209| 1600002 | Marshalling or unmarshalling error. | 210| 1600003 | Failed to connect service. | 211 212**Example** 213 214```ts 215import Base from '@ohos.base'; 216 217let unsubscribeCallback = (err: Base.BusinessError) => { 218 if (err) { 219 console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); 220 } else { 221 console.info("unsubscribe success"); 222 } 223} 224let onDisconnectCallback = () => { 225 console.info("subscribe disconnect"); 226} 227let subscriber: notificationSubscribe.NotificationSubscriber = { 228 onDisconnect: onDisconnectCallback 229}; 230notificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); 231``` 232 233## notificationSubscribe.unsubscribe 234 235unsubscribe(subscriber: NotificationSubscriber): Promise\<void\> 236 237Unsubscribes from a notification. This API uses a promise to return the result. 238 239**System capability**: SystemCapability.Notification.Notification 240 241**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 242 243**System API**: This is a system API and cannot be called by third-party applications. 244 245**Parameters** 246 247| Name | Type | Mandatory| Description | 248| ---------- | ---------------------- | ---- | ------------ | 249| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber.md#notificationsubscriber) | Yes | Notification subscriber.| 250 251**Return value** 252 253| Type | Description | 254| ------- |------------| 255| Promise\<void\> | Promise that returns no value.| 256 257**Error codes** 258 259For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 260 261| ID| Error Message | 262| -------- | ----------------------------------- | 263| 1600001 | Internal error. | 264| 1600002 | Marshalling or unmarshalling error. | 265| 1600003 | Failed to connect service. | 266 267**Example** 268 269```ts 270import Base from '@ohos.base'; 271 272let onDisconnectCallback = () => { 273 console.info("subscribe disconnect"); 274} 275let subscriber: notificationSubscribe.NotificationSubscriber = { 276 onDisconnect: onDisconnectCallback 277}; 278notificationSubscribe.unsubscribe(subscriber).then(() => { 279 console.info("unsubscribe success"); 280}).catch((err: Base.BusinessError) => { 281 console.error("unsubscribe fail: " + JSON.stringify(err)); 282}); 283``` 284 285## notificationSubscribe.remove 286 287remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void 288 289Removes a notification based on the bundle information and notification key. This API uses an asynchronous callback 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 and cannot be called by third-party applications. 296 297**Parameters** 298 299| Name | Type | Mandatory| Description | 300| --------------- | ----------------------------------| ---- | -------------------- | 301| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 302| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 303| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 304| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 305 306**Error codes** 307 308For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 309 310| ID| Error Message | 311| -------- | ---------------------------------------- | 312| 1600001 | Internal error. | 313| 1600002 | Marshalling or unmarshalling error. | 314| 1600003 | Failed to connect service. | 315| 1600007 | The notification is not exist. | 316| 17700001 | The specified bundle name was not found. | 317 318**Example** 319 320```ts 321import Base from '@ohos.base'; 322import NotificationManager from '@ohos.notificationManager'; 323 324let removeCallback = (err: Base.BusinessError) => { 325 if (err) { 326 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 327 } else { 328 console.info("remove success"); 329 } 330} 331let bundle: NotificationManager.BundleOption = { 332 bundle: "bundleName1", 333}; 334let notificationKey: notificationSubscribe.NotificationKey = { 335 id: 0, 336 label: "label", 337}; 338let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 339notificationSubscribe.remove(bundle, notificationKey, reason, removeCallback); 340``` 341 342 343 344## notificationSubscribe.remove 345 346remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\> 347 348Removes a notification based on the specified bundle information and notification key. This API uses a promise to return the result. 349 350**System capability**: SystemCapability.Notification.Notification 351 352**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 353 354**System API**: This is a system API and cannot be called by third-party applications. 355 356**Parameters** 357 358| Name | Type | Mandatory| Description | 359| --------------- | --------------- | ---- | ---------- | 360| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application.| 361| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 362| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 363 364**Return value** 365 366| Type | Description | 367| ------- |------------| 368| Promise\<void\> | Promise that returns no value.| 369 370**Error codes** 371 372For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 373 374| ID| Error Message | 375| -------- | ---------------------------------------- | 376| 1600001 | Internal error. | 377| 1600002 | Marshalling or unmarshalling error. | 378| 1600003 | Failed to connect service. | 379| 1600007 | The notification is not exist. | 380| 17700001 | The specified bundle name was not found. | 381 382**Example** 383 384```ts 385import Base from '@ohos.base'; 386import NotificationManager from '@ohos.notificationManager'; 387 388let bundle: NotificationManager.BundleOption = { 389 bundle: "bundleName1", 390}; 391let notificationKey: notificationSubscribe.NotificationKey = { 392 id: 0, 393 label: "label", 394}; 395let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 396notificationSubscribe.remove(bundle, notificationKey, reason).then(() => { 397 console.info("remove success"); 398}).catch((err: Base.BusinessError) => { 399 console.error("remove fail: " + JSON.stringify(err)); 400}); 401``` 402 403## notificationSubscribe.remove 404 405remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void 406 407Removes a notification based on the specified unique notification ID. This API uses an asynchronous callback to return the result. 408 409**System capability**: SystemCapability.Notification.Notification 410 411**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 412 413**System API**: This is a system API and cannot be called by third-party applications. 414 415**Parameters** 416 417| Name | Type | Mandatory| Description | 418| -------- | --------------------- | ---- | -------------------- | 419| 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.| 420| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 421| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 422 423**Error codes** 424 425For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 426 427| ID| Error Message | 428| -------- | ----------------------------------- | 429| 1600001 | Internal error. | 430| 1600002 | Marshalling or unmarshalling error. | 431| 1600003 | Failed to connect service. | 432| 1600007 | The notification is not exist. | 433 434**Example** 435 436```ts 437import Base from '@ohos.base'; 438 439let hashCode: string = 'hashCode'; 440let removeCallback = (err: Base.BusinessError) => { 441 if (err) { 442 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 443 } else { 444 console.info("remove success"); 445 } 446} 447let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 448notificationSubscribe.remove(hashCode, reason, removeCallback); 449``` 450 451## notificationSubscribe.remove 452 453remove(hashCode: string, reason: RemoveReason): Promise\<void\> 454 455Removes a notification based on the specified unique notification ID. This API uses a promise to return the result. 456 457**System capability**: SystemCapability.Notification.Notification 458 459**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 460 461**System API**: This is a system API and cannot be called by third-party applications. 462 463**Parameters** 464 465| Name | Type | Mandatory| Description | 466| -------- | ---------- | ---- | ---------- | 467| hashCode | string | Yes | Unique notification ID.| 468| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 469 470**Return value** 471 472| Type | Description| 473| ------- |--| 474| Promise\<void\> | Promise that returns no value.| 475 476**Error codes** 477 478For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 479 480| ID| Error Message | 481| -------- | ----------------------------------- | 482| 1600001 | Internal error. | 483| 1600002 | Marshalling or unmarshalling error. | 484| 1600003 | Failed to connect service. | 485| 1600007 | The notification is not exist. | 486 487**Example** 488 489```ts 490import Base from '@ohos.base'; 491 492let hashCode: string = 'hashCode'; 493let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 494notificationSubscribe.remove(hashCode, reason).then(() => { 495 console.info("remove success"); 496}).catch((err: Base.BusinessError) => { 497 console.error("remove fail: " + JSON.stringify(err)); 498}); 499``` 500## notificationSubscribe.remove<sup>10+<sup> 501 502remove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback\<void\>): void 503 504Removes specified notifications. This API uses an asynchronous callback to return the result. 505 506**System capability**: SystemCapability.Notification.Notification 507 508**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 509 510**System API**: This is a system API and cannot be called by third-party applications. 511 512**Parameters** 513 514| Name | Type | Mandatory| Description | 515|-----------|-------------------------------| ---- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 516| 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.| 517| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 518| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 519 520**Error codes** 521 522For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 523 524| ID| Error Message | 525| -------- | ----------------------------------- | 526| 1600001 | Internal error. | 527| 1600002 | Marshalling or unmarshalling error. | 528| 1600003 | Failed to connect service. | 529 530**Example** 531 532```ts 533import Base from '@ohos.base'; 534 535let hashCodes: string[] = ['hashCode1', 'hashCode2']; 536let removeCallback = (err: Base.BusinessError) => { 537 if (err) { 538 console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 539 } else { 540 console.info("remove success"); 541 } 542} 543let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 544notificationSubscribe.remove(hashCodes, reason, removeCallback); 545``` 546 547## notificationSubscribe.remove<sup>10+<sup> 548 549remove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\> 550 551Removes specified notifications. This API uses a promise to return the result. 552 553**System capability**: SystemCapability.Notification.Notification 554 555**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 556 557**System API**: This is a system API and cannot be called by third-party applications. 558 559**Parameters** 560 561| Name | Type | Mandatory| Description | 562|-----------|-------------------------------| ---- |-------------| 563| hashCodes | Array\<String\> | Yes | Array of unique notification IDs.| 564| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 565 566**Return value** 567 568| Type | Description | 569| ------- |------------------| 570| Promise\<void\> | Promise that returns no value.| 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 reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 589notificationSubscribe.remove(hashCodes, reason).then(() => { 590 console.info("remove success"); 591}).catch((err: Base.BusinessError) => { 592 console.error("remove fail: " + JSON.stringify(err)); 593}); 594``` 595 596## notificationSubscribe.removeAll 597 598removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void 599 600Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. 601 602**System capability**: SystemCapability.Notification.Notification 603 604**System API**: This is a system API and cannot be called by third-party applications. 605 606**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 607 608**Parameters** 609 610| Name | Type | Mandatory| Description | 611| -------- | --------------------- | ---- | ---------------------------- | 612| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 613| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 614 615**Error codes** 616 617For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 618 619| ID| Error Message | 620| -------- | ---------------------------------------- | 621| 1600001 | Internal error. | 622| 1600002 | Marshalling or unmarshalling error. | 623| 1600003 | Failed to connect service. | 624| 17700001 | The specified bundle name was not found. | 625 626**Example** 627 628```ts 629import Base from '@ohos.base'; 630 631let removeAllCallback = (err: Base.BusinessError) => { 632 if (err) { 633 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 634 } else { 635 console.info("removeAll success"); 636 } 637} 638let bundle: notificationSubscribe.BundleOption = { 639 bundle: "bundleName1", 640}; 641notificationSubscribe.removeAll(bundle, removeAllCallback); 642``` 643 644## notificationSubscribe.removeAll 645 646removeAll(callback: AsyncCallback\<void\>): void 647 648Removes all notifications. This API uses an asynchronous callback to return the result. 649 650**System capability**: SystemCapability.Notification.Notification 651 652**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 653 654**System API**: This is a system API and cannot be called by third-party applications. 655 656**Parameters** 657 658| Name | Type | Mandatory| Description | 659| -------- | --------------------- | ---- | -------------------- | 660| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 661 662**Error codes** 663 664For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 665 666| ID| Error Message | 667| -------- | ----------------------------------- | 668| 1600001 | Internal error. | 669| 1600002 | Marshalling or unmarshalling error. | 670| 1600003 | Failed to connect service. | 671 672**Example** 673 674```ts 675import Base from '@ohos.base'; 676 677let removeAllCallback = (err: Base.BusinessError) => { 678 if (err) { 679 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 680 } else { 681 console.info("removeAll success"); 682 } 683} 684notificationSubscribe.removeAll(removeAllCallback); 685``` 686 687## notificationSubscribe.removeAll 688 689removeAll(bundle?: BundleOption): Promise\<void\> 690 691Removes all notifications for a specified application. This API uses a promise to return the result. 692 693**System capability**: SystemCapability.Notification.Notification 694 695**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 696 697**System API**: This is a system API and cannot be called by third-party applications. 698 699**Parameters** 700 701| Name | Type | Mandatory| Description | 702| ------ | ------------ | ---- | ---------- | 703| 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.| 704 705**Return value** 706 707| Type | Description | 708| ------- |------------| 709| Promise\<void\> | Promise that returns no value.| 710 711**Error codes** 712 713For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 714 715| ID| Error Message | 716| -------- | ---------------------------------------- | 717| 1600001 | Internal error. | 718| 1600002 | Marshalling or unmarshalling error. | 719| 1600003 | Failed to connect service. | 720| 17700001 | The specified bundle name was not found. | 721 722**Example** 723 724```ts 725import Base from '@ohos.base'; 726 727// If no application is specified, notifications of all applications are deleted. 728notificationSubscribe.removeAll().then(() => { 729 console.info("removeAll success"); 730}).catch((err: Base.BusinessError) => { 731 console.error("removeAll fail: " + JSON.stringify(err)); 732}); 733``` 734 735## notificationSubscribe.removeAll 736 737removeAll(userId: number, callback: AsyncCallback\<void>): void 738 739Removes all notifications for a specified user. This API uses an asynchronous callback to return the result. 740 741**System capability**: SystemCapability.Notification.Notification 742 743**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 744 745**System API**: This is a system API and cannot be called by third-party applications. 746 747**Parameters** 748 749| Name | Type | Mandatory| Description | 750| ------ | ------------ | ---- | ---------- | 751| userId | number | Yes | User ID.| 752| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 753 754**Error codes** 755 756For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 757 758| ID| Error Message | 759| -------- | ----------------------------------- | 760| 1600001 | Internal error. | 761| 1600002 | Marshalling or unmarshalling error. | 762| 1600003 | Failed to connect service. | 763| 1600008 | The user is not exist. | 764 765**Example** 766 767```ts 768import Base from '@ohos.base'; 769 770let removeAllCallback = (err: Base.BusinessError) => { 771 if (err) { 772 console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 773 } else { 774 console.info("removeAll success"); 775 } 776} 777let userId: number = 1; 778notificationSubscribe.removeAll(userId, removeAllCallback); 779``` 780 781## notificationSubscribe.removeAll 782 783removeAll(userId: number): Promise\<void> 784 785Removes all notifications for a specified user. This API uses a promise to return the result. 786 787**System capability**: SystemCapability.Notification.Notification 788 789**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 790 791**System API**: This is a system API and cannot be called by third-party applications. 792 793**Parameters** 794 795| Name | Type | Mandatory| Description | 796| ------ | ------------ | ---- | ---------- | 797| userId | number | Yes | User ID.| 798 799**Error codes** 800 801For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md). 802 803| ID| Error Message | 804| -------- | ----------------------------------- | 805| 1600001 | Internal error. | 806| 1600002 | Marshalling or unmarshalling error. | 807| 1600003 | Failed to connect service. | 808| 1600008 | The user is not exist. | 809 810**Example** 811 812```ts 813import Base from '@ohos.base'; 814 815let userId: number = 1; 816notificationSubscribe.removeAll(userId).then(() => { 817 console.info("removeAll success"); 818}).catch((err: Base.BusinessError) => { 819 console.error("removeAll fail: " + JSON.stringify(err)); 820}); 821``` 822 823## NotificationKey 824 825**System capability**: SystemCapability.Notification.Notification 826 827**System API**: This is a system API and cannot be called by third-party applications. 828 829| Name | Type | Mandatory| Description | 830| ----- | ------ | --- | -------- | 831| id | number | Yes | Notification ID. | 832| label | string | No | Notification label. This parameter is left empty by default.| 833 834## RemoveReason 835 836**System capability**: SystemCapability.Notification.Notification 837 838**System API**: This is a system API and cannot be called by third-party applications. 839 840| Name | Value | Description | 841| -------------------- | --- | -------------------- | 842| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | 843| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | 844