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