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