• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.notificationSubscribe (NotificationSubscribe模块)(系统接口)
2
3<!--Kit: Notification Kit-->
4<!--Subsystem: Notification-->
5<!--Owner: @peixu-->
6<!--Designer: @dongqingran; @wulong158-->
7<!--Tester: @wanghong1997-->
8<!--Adviser: @huipeizi-->
9
10本模块提供通知订阅、取消订阅、通知移除等,一般情况下,只有系统应用具有这些操作权限。
11
12> **说明:**
13>
14> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
15>
16> 本模块接口均为系统接口。
17
18## 导入模块
19
20```ts
21import { notificationSubscribe } from '@kit.NotificationKit';
22```
23
24## notificationSubscribe.subscribe
25
26subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void
27
28订阅通知并指定订阅信息。使用callback异步回调。
29
30**系统能力**:SystemCapability.Notification.Notification
31
32**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
33
34**系统接口**:此接口为系统接口。
35
36**参数:**
37
38| 参数名       | 类型                      | 必填 | 说明             |
39| ---------- | ------------------------- | ---- | ---------------- |
40| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md)    | 是   | 通知订阅对象。     |
41| info       | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | 是   | 通知订阅信息。 |
42| callback   | AsyncCallback\<void\>     | 是   | 订阅动作回调函数。 |
43
44**错误码:**
45
46以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
47
48| 错误码ID | 错误信息                             |
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**示例:**
59
60```ts
61import { BusinessError } from '@kit.BasicServicesKit';
62
63//subscribe回调
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//不会对bundleNames进行校验,开发者自己确定需要订阅哪些bundleName
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
88订阅当前用户下所有应用的通知。使用callback异步回调。
89
90**系统能力**:SystemCapability.Notification.Notification
91
92**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
93
94**系统接口**:此接口为系统接口。
95
96**参数:**
97
98| 参数名       | 类型                   | 必填 | 说明             |
99| ---------- | ---------------------- | ---- | ---------------- |
100| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md) | 是   | 通知订阅对象。     |
101| callback   | AsyncCallback\<void\>  | 是   | 订阅动作回调函数。 |
102
103**错误码:**
104
105以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
106
107| 错误码ID | 错误信息                            |
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**示例:**
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
144订阅通知并指定订阅信息。使用Promise异步回调。
145
146**系统能力**:SystemCapability.Notification.Notification
147
148**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
149
150**系统接口**:此接口为系统接口。
151
152**参数:**
153
154| 参数名       | 类型                      | 必填 | 说明         |
155| ---------- | ------------------------- | ---- | ------------ |
156| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md)    | 是   | 通知订阅对象。 |
157| info       | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | 否   | 通知订阅信息,默认为空(当为空时,表示订阅当前用户下所有应用的通知,否则表示订阅通知并指定订阅信息)。   |
158
159**返回值:**
160
161| 类型     | 说明               |
162| ------- |------------------|
163| Promise\<void\> | 无返回结果的Promise对象。 |
164
165**错误码:**
166
167以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
168
169| 错误码ID | 错误信息                            |
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**示例:**
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
202订阅本应用的通知并指定订阅信息。使用Promise异步回调。
203
204**系统能力**:SystemCapability.Notification.Notification
205
206**系统接口**:此接口为系统接口。
207
208**参数:**
209
210| 参数名       | 类型                      | 必填 | 说明         |
211| ---------- | ------------------------- | ---- | ------------ |
212| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md)    | 是   | 通知订阅对象。 |
213
214**返回值:**
215
216| 类型     | 说明               |
217| ------- |------------------|
218| Promise\<void\> | 无返回结果的Promise对象。 |
219
220**错误码:**
221
222以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
223
224| 错误码ID | 错误信息                            |
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**示例:**
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
257取消订阅。使用callback异步回调。
258
259**系统能力**:SystemCapability.Notification.Notification
260
261**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
262
263**系统接口**:此接口为系统接口。
264
265**参数:**
266
267| 参数名       | 类型                   | 必填 | 说明                 |
268| ---------- | ---------------------- | ---- | -------------------- |
269| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md) | 是   | 通知订阅对象。         |
270| callback   | AsyncCallback\<void\>  | 是   | 取消订阅动作回调函数。 |
271
272**错误码:**
273
274以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
275
276| 错误码ID | 错误信息                            |
277| -------- | ----------------------------------- |
278| 202      | Not system application to call the interface.                                      |
279| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
280| 1600001  | Internal error.                     |
281| 1600002  | Marshalling or unmarshalling error. |
282| 1600003  | Failed to connect to the service.          |
283
284**示例:**
285
286```ts
287import { BusinessError } from '@kit.BasicServicesKit';
288
289let unsubscribeCallback = (err: BusinessError) => {
290  if (err) {
291    console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
292  } else {
293    console.info("unsubscribe success");
294  }
295}
296let onDisconnectCallback = () => {
297  console.info("subscribe disconnect");
298}
299let subscriber: notificationSubscribe.NotificationSubscriber = {
300  onDisconnect: onDisconnectCallback
301};
302notificationSubscribe.unsubscribe(subscriber, unsubscribeCallback);
303```
304
305## notificationSubscribe.unsubscribe
306
307unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
308
309取消订阅。使用Promise异步回调。
310
311**系统能力**:SystemCapability.Notification.Notification
312
313**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
314
315**系统接口**:此接口为系统接口。
316
317**参数:**
318
319| 参数名       | 类型                   | 必填 | 说明         |
320| ---------- | ---------------------- | ---- | ------------ |
321| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md) | 是   | 通知订阅对象。 |
322
323**返回值:**
324
325| 类型     | 说明         |
326| ------- |------------|
327| Promise\<void\> | 无返回结果的Promise对象。 |
328
329**错误码:**
330
331以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
332
333| 错误码ID | 错误信息                            |
334| -------- | ----------------------------------- |
335| 202      | Not system application to call the interface.                                      |
336| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
337| 1600001  | Internal error.                     |
338| 1600002  | Marshalling or unmarshalling error. |
339| 1600003  | Failed to connect to the service.          |
340
341**示例:**
342
343```ts
344import { BusinessError } from '@kit.BasicServicesKit';
345
346let onDisconnectCallback = () => {
347  console.info("subscribe disconnect");
348}
349let subscriber: notificationSubscribe.NotificationSubscriber = {
350  onDisconnect: onDisconnectCallback
351};
352notificationSubscribe.unsubscribe(subscriber).then(() => {
353  console.info("unsubscribe success");
354}).catch((err: BusinessError) => {
355  console.error(`unsubscribe fail: ${JSON.stringify(err)}`);
356});
357```
358
359## notificationSubscribe.remove
360
361remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void
362
363根据应用的包信息和通知键值,删除指定通知。使用callback异步回调。
364
365**系统能力**:SystemCapability.Notification.Notification
366
367**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
368
369**系统接口**:此接口为系统接口。
370
371**参数:**
372
373| 参数名            | 类型                                | 必填 | 说明                 |
374| --------------- |   ----------------------------------| ---- | -------------------- |
375| bundle          | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)       | 是   | 指定应用的包信息。           |
376| notificationKey | [NotificationKey](#notificationkey) | 是   | 通知键值。             |
377| reason          | [RemoveReason](#removereason)      | 是   | 通知删除原因。         |
378| callback        | AsyncCallback\<void\>               | 是   | 删除指定通知回调函数。 |
379
380**错误码:**
381
382以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)、[通知错误码](./errorcode-notification.md)、[包管理子系统通用错误码](../../reference/apis-ability-kit/errorcode-bundle.md)。
383
384| 错误码ID | 错误信息                                 |
385| -------- | ---------------------------------------- |
386| 201      | Permission denied.     |
387| 202      | Not system application to call the interface.                                      |
388| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
389| 1600001  | Internal error.                          |
390| 1600002  | Marshalling or unmarshalling error.      |
391| 1600003  | Failed to connect to the service.               |
392| 1600007  | The notification does not exist.           |
393| 17700001 | The specified bundle name was not found. |
394
395**示例:**
396
397```ts
398import { BusinessError } from '@kit.BasicServicesKit';
399import { notificationManager } from '@kit.NotificationKit';
400
401let removeCallback = (err: BusinessError) => {
402  if (err) {
403    console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
404  } else {
405    console.info("remove success");
406  }
407}
408let bundle: notificationManager.BundleOption = {
409  bundle: "bundleName1",
410};
411let notificationKey: notificationSubscribe.NotificationKey = {
412  id: 0,
413  label: "label",
414};
415let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
416notificationSubscribe.remove(bundle, notificationKey, reason, removeCallback);
417```
418
419
420
421## notificationSubscribe.remove
422
423remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\>
424
425根据应用的包信息和通知键值,删除指定通知。使用Promise异步回调。
426
427**系统能力**:SystemCapability.Notification.Notification
428
429**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
430
431**系统接口**:此接口为系统接口。
432
433**参数:**
434
435| 参数名            | 类型            | 必填 | 说明       |
436| --------------- | --------------- | ---- | ---------- |
437| bundle          | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)    | 是   | 指定应用的包信息。 |
438| notificationKey | [NotificationKey](#notificationkey) | 是   | 通知键值。   |
439| reason          | [RemoveReason](#removereason) | 是   | 通知删除原因。         |
440
441**返回值:**
442
443| 类型     | 说明         |
444| ------- |------------|
445| Promise\<void\> | 无返回结果的Promise对象。 |
446
447**错误码:**
448
449以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)、[通知错误码](./errorcode-notification.md)、[包管理子系统通用错误码](../../reference/apis-ability-kit/errorcode-bundle.md)。
450
451| 错误码ID | 错误信息                                 |
452| -------- | ---------------------------------------- |
453| 201      | Permission denied.     |
454| 202      | Not system application to call the interface.                                      |
455| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
456| 1600001  | Internal error.                          |
457| 1600002  | Marshalling or unmarshalling error.      |
458| 1600003  | Failed to connect to the service.               |
459| 1600007  | The notification does not exist.           |
460| 17700001 | The specified bundle name was not found. |
461
462**示例:**
463
464```ts
465import { BusinessError } from '@kit.BasicServicesKit';
466import { notificationManager } from '@kit.NotificationKit';
467
468let bundle: notificationManager.BundleOption = {
469  bundle: "bundleName1",
470};
471let notificationKey: notificationSubscribe.NotificationKey = {
472  id: 0,
473  label: "label",
474};
475let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
476notificationSubscribe.remove(bundle, notificationKey, reason).then(() => {
477  console.info("remove success");
478}).catch((err: BusinessError) => {
479  console.error(`remove fail: ${JSON.stringify(err)}`);
480});
481```
482
483## notificationSubscribe.remove
484
485remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void
486
487通过通知的唯一ID,删除指定通知。使用callback异步回调。
488
489**系统能力**:SystemCapability.Notification.Notification
490
491**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
492
493**系统接口**:此接口为系统接口。
494
495**参数:**
496
497| 参数名     | 类型                  | 必填 | 说明                 |
498| -------- | --------------------- | ---- | -------------------- |
499| hashCode | string                | 是   | 通知唯一ID。可以通过[onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume)回调的入参[SubscribeCallbackData](js-apis-inner-notification-notificationSubscriber-sys.md#subscribecallbackdata)获取其内部[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest-1)对象中的hashCode。 |
500| reason   | [RemoveReason](#removereason) | 是   | 通知删除原因。         |
501| callback | AsyncCallback\<void\> | 是   | 删除指定通知回调函数。 |
502
503**错误码:**
504
505以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
506
507| 错误码ID | 错误信息                            |
508| -------- | ----------------------------------- |
509| 201      | Permission denied.     |
510| 202      | Not system application to call the interface.                                      |
511| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
512| 1600001  | Internal error.                     |
513| 1600002  | Marshalling or unmarshalling error. |
514| 1600003  | Failed to connect to the service.          |
515| 1600007  | The notification does not exist.      |
516
517**示例:**
518
519```ts
520import { BusinessError } from '@kit.BasicServicesKit';
521
522let hashCode: string = 'hashCode';
523let removeCallback = (err: BusinessError) => {
524  if (err) {
525    console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
526  } else {
527    console.info("remove success");
528  }
529}
530let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
531notificationSubscribe.remove(hashCode, reason, removeCallback);
532```
533
534## notificationSubscribe.remove
535
536remove(hashCode: string, reason: RemoveReason): Promise\<void\>
537
538通过通知的唯一ID,删除指定通知。使用Promise异步回调。
539
540**系统能力**:SystemCapability.Notification.Notification
541
542**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
543
544**系统接口**:此接口为系统接口。
545
546**参数:**
547
548| 参数名     | 类型       | 必填 | 说明       |
549| -------- | ---------- | ---- | ---------- |
550| hashCode | string | 是   | 通知唯一ID。可以通过[onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume)回调的入参[SubscribeCallbackData](js-apis-inner-notification-notificationSubscriber-sys.md#subscribecallbackdata)获取其内部[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest-1)对象中的hashCode。 |
551| reason   | [RemoveReason](#removereason) | 是   | 通知删除原因。         |
552
553**返回值:**
554
555| 类型     | 说明 |
556| ------- |--|
557| Promise\<void\> | 无返回结果的Promise对象。 |
558
559**错误码:**
560
561以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
562
563| 错误码ID | 错误信息                            |
564| -------- | ----------------------------------- |
565| 201      | Permission denied.     |
566| 202      | Not system application to call the interface.                                      |
567| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
568| 1600001  | Internal error.                     |
569| 1600002  | Marshalling or unmarshalling error. |
570| 1600003  | Failed to connect to the service.          |
571| 1600007  | The notification does not exist.      |
572
573**示例:**
574
575```ts
576import { BusinessError } from '@kit.BasicServicesKit';
577
578let hashCode: string = 'hashCode';
579let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
580notificationSubscribe.remove(hashCode, reason).then(() => {
581	console.info("remove success");
582}).catch((err: BusinessError) => {
583  console.error(`remove fail: ${JSON.stringify(err)}`);
584});
585```
586
587## notificationSubscribe.remove<sup>10+</sup>
588
589remove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback\<void\>): void
590
591批量删除指定通知。使用callback异步回调。
592
593**系统能力**:SystemCapability.Notification.Notification
594
595**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
596
597**系统接口**:此接口为系统接口。
598
599**参数:**
600
601| 参数名       | 类型                            | 必填 | 说明                                                                                                                                                                                                                                                                                  |
602|-----------|-------------------------------| ---- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
603| hashCodes | Array\<String\>               | 是   | 通知唯一ID数组集合。可以通过[onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume)回调的入参[SubscribeCallbackData](js-apis-inner-notification-notificationSubscriber-sys.md#subscribecallbackdata)获取其内部[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest-1)对象中的hashCode。 |
604| reason    | [RemoveReason](#removereason) | 是   | 通知删除原因。                                                                                                                                                                                                                                                                             |
605| callback  | AsyncCallback\<void\>         | 是   | 删除指定通知回调函数。                                                                                                                                                                                                                                                                         |
606
607**错误码:**
608
609以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
610
611| 错误码ID | 错误信息                            |
612| -------- | ----------------------------------- |
613| 201      | Permission denied.     |
614| 202      | Not system application to call the interface.                                      |
615| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
616| 1600001  | Internal error.                     |
617| 1600002  | Marshalling or unmarshalling error. |
618| 1600003  | Failed to connect to the service.          |
619
620**示例:**
621
622```ts
623import { BusinessError } from '@kit.BasicServicesKit';
624
625let hashCodes: string[] = ['hashCode1', 'hashCode2'];
626let removeCallback = (err: BusinessError) => {
627  if (err) {
628    console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
629  } else {
630    console.info("remove success");
631  }
632}
633let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
634notificationSubscribe.remove(hashCodes, reason, removeCallback);
635```
636
637## notificationSubscribe.remove<sup>10+</sup>
638
639remove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\>
640
641批量删除指定通知。使用Promise异步回调。
642
643**系统能力**:SystemCapability.Notification.Notification
644
645**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
646
647**系统接口**:此接口为系统接口。
648
649**参数:**
650
651| 参数名       | 类型                            | 必填 | 说明          |
652|-----------|-------------------------------| ---- |-------------|
653| hashCodes | Array\<String\>               | 是   | 通知唯一ID数组集合。 |
654| reason    | [RemoveReason](#removereason) | 是   | 通知删除原因。     |
655
656**返回值:**
657
658| 类型     | 说明               |
659| ------- |------------------|
660| Promise\<void\> | 无返回结果的Promise对象。 |
661
662**错误码:**
663
664以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
665
666| 错误码ID | 错误信息                            |
667| -------- | ----------------------------------- |
668| 201      | Permission denied.     |
669| 202      | Not system application to call the interface.                                      |
670| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
671| 1600001  | Internal error.                     |
672| 1600002  | Marshalling or unmarshalling error. |
673| 1600003  | Failed to connect to the service.          |
674
675**示例:**
676
677```ts
678import { BusinessError } from '@kit.BasicServicesKit';
679
680let hashCodes: string[] = ['hashCode1','hashCode2'];
681let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
682notificationSubscribe.remove(hashCodes, reason).then(() => {
683  console.info("remove success");
684}).catch((err: BusinessError) => {
685  console.error(`remove fail: ${JSON.stringify(err)}`);
686});
687```
688
689## notificationSubscribe.removeAll
690
691removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
692
693删除指定应用的所有通知。使用callback异步回调。
694
695**系统能力**:SystemCapability.Notification.Notification
696
697**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
698
699**系统接口**:此接口为系统接口。
700
701**参数:**
702
703| 参数名     | 类型                  | 必填 | 说明                         |
704| -------- | --------------------- | ---- | ---------------------------- |
705| bundle   | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)        | 是   | 指定应用的包信息。                   |
706| callback | AsyncCallback\<void\> | 是   | 删除指定应用的所有通知回调函数。 |
707
708**错误码:**
709
710以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)、[通知错误码](./errorcode-notification.md)、[包管理子系统通用错误码](../../reference/apis-ability-kit/errorcode-bundle.md)。
711
712| 错误码ID | 错误信息                                 |
713| -------- | ---------------------------------------- |
714| 201      | Permission denied.     |
715| 202      | Not system application to call the interface.                                      |
716| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
717| 1600001  | Internal error.                          |
718| 1600002  | Marshalling or unmarshalling error.      |
719| 1600003  | Failed to connect to the service.               |
720| 17700001 | The specified bundle name was not found. |
721
722**示例:**
723
724```ts
725import { BusinessError } from '@kit.BasicServicesKit';
726
727let removeAllCallback = (err: BusinessError) => {
728  if (err) {
729    console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
730  } else {
731    console.info("removeAll success");
732  }
733}
734let bundle: notificationSubscribe.BundleOption = {
735  bundle: "bundleName1",
736};
737notificationSubscribe.removeAll(bundle, removeAllCallback);
738```
739
740## notificationSubscribe.removeAll
741
742removeAll(callback: AsyncCallback\<void\>): void
743
744删除所有通知。使用callback异步回调。
745
746**系统能力**:SystemCapability.Notification.Notification
747
748**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
749
750**系统接口**:此接口为系统接口。
751
752**参数:**
753
754| 参数名     | 类型                  | 必填 | 说明                 |
755| -------- | --------------------- | ---- | -------------------- |
756| callback | AsyncCallback\<void\> | 是   | 删除所有通知回调函数。 |
757
758**错误码:**
759
760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
761
762| 错误码ID | 错误信息                            |
763| -------- | ----------------------------------- |
764| 201      | Permission denied.     |
765| 202      | Not system application to call the interface.                                      |
766| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
767| 1600001  | Internal error.                     |
768| 1600002  | Marshalling or unmarshalling error. |
769| 1600003  | Failed to connect to the service.          |
770
771**示例:**
772
773```ts
774import { BusinessError } from '@kit.BasicServicesKit';
775
776let removeAllCallback = (err: BusinessError) => {
777    if (err) {
778        console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
779    } else {
780        console.info("removeAll success");
781    }
782}
783notificationSubscribe.removeAll(removeAllCallback);
784```
785
786## notificationSubscribe.removeAll
787
788removeAll(bundle?: BundleOption): Promise\<void\>
789
790删除指定应用的所有通知。使用Promise异步回调。
791
792**系统能力**:SystemCapability.Notification.Notification
793
794**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
795
796**系统接口**:此接口为系统接口。
797
798**参数:**
799
800| 参数名   | 类型         | 必填 | 说明       |
801| ------ | ------------ | ---- | ---------- |
802| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 否   | 指定应用的包信息。默认为空,表示删除所有通知。 |
803
804**返回值:**
805
806| 类型     | 说明         |
807| ------- |------------|
808| Promise\<void\> | 无返回结果的Promise对象。 |
809
810**错误码:**
811
812以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)、[通知错误码](./errorcode-notification.md)、[包管理子系统通用错误码](../../reference/apis-ability-kit/errorcode-bundle.md)。
813
814| 错误码ID | 错误信息                                 |
815| -------- | ---------------------------------------- |
816| 201      | Permission denied.     |
817| 202      | Not system application to call the interface.                                      |
818| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
819| 1600001  | Internal error.                          |
820| 1600002  | Marshalling or unmarshalling error.      |
821| 1600003  | Failed to connect to the service.               |
822| 17700001 | The specified bundle name was not found. |
823
824**示例:**
825
826```ts
827import { BusinessError } from '@kit.BasicServicesKit';
828
829// 不指定应用时,删除所有通知
830notificationSubscribe.removeAll().then(() => {
831	console.info("removeAll success");
832}).catch((err: BusinessError) => {
833  console.error(`removeAll fail: ${JSON.stringify(err)}`);
834});
835```
836
837## notificationSubscribe.removeAll
838
839removeAll(userId: number, callback: AsyncCallback\<void>): void
840
841删除指定用户下的所有通知。使用callback异步回调。
842
843**系统能力**:SystemCapability.Notification.Notification
844
845**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
846
847**系统接口**:此接口为系统接口。
848
849**参数:**
850
851| 参数名   | 类型         | 必填 | 说明       |
852| ------ | ------------ | ---- | ---------- |
853| userId | number | 是   | 用户ID。 |
854| callback | AsyncCallback\<void\> | 是   | 删除指定用户所有通知回调函数。 |
855
856**错误码:**
857
858以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
859
860| 错误码ID | 错误信息                            |
861| -------- | ----------------------------------- |
862| 201      | Permission denied.     |
863| 202      | Not system application to call the interface.                                      |
864| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
865| 1600001  | Internal error.                     |
866| 1600002  | Marshalling or unmarshalling error. |
867| 1600003  | Failed to connect to the service.          |
868| 1600008  | The user does not exist.              |
869
870**示例:**
871
872```ts
873import { BusinessError } from '@kit.BasicServicesKit';
874
875let removeAllCallback = (err: BusinessError) => {
876  if (err) {
877    console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
878  } else {
879    console.info("removeAll success");
880  }
881}
882// 用户ID,使用时需替换为真实的userId。
883let userId: number = 1;
884notificationSubscribe.removeAll(userId, removeAllCallback);
885```
886
887## notificationSubscribe.removeAll
888
889removeAll(userId: number): Promise\<void>
890
891删除指定用户下的所有通知。使用Promise异步回调。
892
893**系统能力**:SystemCapability.Notification.Notification
894
895**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
896
897**系统接口**:此接口为系统接口。
898
899**参数:**
900
901| 参数名   | 类型         | 必填 | 说明       |
902| ------ | ------------ | ---- | ---------- |
903| userId | number | 是   | 用户ID。 |
904
905**返回值:**
906
907| 类型     | 说明         |
908| ------- |------------|
909| Promise\<void\> | 无返回结果的Promise对象。 |
910
911**错误码:**
912
913以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
914
915| 错误码ID | 错误信息                            |
916| -------- | ----------------------------------- |
917| 201      | Permission denied.     |
918| 202      | Not system application to call the interface.                                      |
919| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
920| 1600001  | Internal error.                     |
921| 1600002  | Marshalling or unmarshalling error. |
922| 1600003  | Failed to connect to the service.          |
923| 1600008  | The user does not exist.              |
924
925**示例:**
926
927```ts
928import { BusinessError } from '@kit.BasicServicesKit';
929
930let userId: number = 1;
931notificationSubscribe.removeAll(userId).then(() => {
932	console.info("removeAll success");
933}).catch((err: BusinessError) => {
934  console.error(`removeAll fail: ${JSON.stringify(err)}`);
935});
936```
937
938## notificationSubscribe.distributeOperation<sup>18+</sup>
939
940distributeOperation(hashcode: string, operationInfo?: OperationInfo): Promise\<void>
941
942触发指定通知的跨设备协同操作(例如通知跨设备点击跳转、通知跨设备快捷回复等)。使用Promise异步回调。
943
944**系统能力**:SystemCapability.Notification.Notification
945
946**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
947
948**系统接口**:此接口为系统接口。
949
950**参数:**
951
952| 参数名   | 类型         | 必填 | 说明       |
953| ------ | ------------ | ---- | ---------- |
954| hashcode | string | 是   | 通知唯一ID。 |
955| operationInfo | [OperationInfo](#operationinfo18) | 否   | 跨设备协同操作信息。 |
956
957**返回值:**
958
959| 类型     | 说明         |
960| ------- |------------|
961| Promise\<void\> | 无返回结果的Promise对象。 |
962
963**错误码:**
964
965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
966
967| 错误码ID | 错误信息                            |
968| -------- | ----------------------------------- |
969| 201      | Permission denied.     |
970| 202      | Not system application to call the interface.                                      |
971| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
972| 1600010  | Distributed operation failed.                     |
973| 1600021  | Distributed operation timed out.                    |
974
975**示例:**
976
977```ts
978import { BusinessError } from '@kit.BasicServicesKit';
979
980let hashcode: string = 'hashcode';
981let operationInfo: notificationSubscribe.OperationInfo = {
982  actionName: "actionName",
983  userInput: "userInput",
984};
985notificationSubscribe.distributeOperation(hashcode, operationInfo).then(() => {
986	console.info("distributeOperation success");
987}).catch((err: BusinessError) => {
988  console.error(`distributeOperation fail: ${JSON.stringify(err)}`);
989});
990```
991
992## NotificationKey
993
994**系统能力**:SystemCapability.Notification.Notification
995
996**系统接口**:此接口为系统接口。
997
998| 名称  | 类型   | 只读 | 可选 | 说明                |
999| ----- | ------ | --- | ---- | ------------------ |
1000| id    | number | 否  |  否  | 通知ID。            |
1001| label | string | 否  |  是  | 通知标签,默认为空。 |
1002
1003## RemoveReason
1004
1005**系统能力**:SystemCapability.Notification.Notification
1006
1007**系统接口**:此接口为系统接口。
1008
1009| 名称                 | 值  | 说明                  |
1010| -------------------- | --- | -------------------- |
1011| CLICK_REASON_REMOVE  | 1   | 点击通知后删除通知。    |
1012| CANCEL_REASON_REMOVE | 2   | 用户删除通知。         |
1013
1014## OperationInfo<sup>18+</sup>
1015
1016**系统能力**:SystemCapability.Notification.Notification
1017
1018**系统接口**:此接口为系统接口。
1019
1020| 名称  | 类型   | 只读 | 可选 | 说明     |
1021| ----- | ------ | --- | ---- | -------- |
1022| actionName    | string | 否 | 是 | 描述通知中显示的操作按钮(与通知[NotificationActionButton](js-apis-inner-notification-notificationActionButton.md#notificationactionbutton-1)中title字段保持一致)。   |
1023| userInput | string | 否 | 是 | 用户输入(用于通知跨设备快捷回复场景传递用户输入,与通知[NotificationUserInput](js-apis-inner-notification-notificationUserInput.md#notificationuserinput-1)中inputKey字段保持一致)。 |
1024