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