1# @ohos.notificationManager (NotificationManager模块)
2
3本模块提供通知管理的能力,包括发布、取消发布通知,创建、获取、移除通知渠道,获取通知的使能状态、角标使能状态,获取通知的相关信息等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import { notificationManager } from '@kit.NotificationKit';
13```
14
15## notificationManager.publish
16
17publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
18
19发布通知。使用callback异步回调。
20
21如果新发布通知与已发布通知的ID相同,且label相同,则新通知将取代原有通知。
22
23**系统能力**:SystemCapability.Notification.Notification
24
25**参数:**
26
27| 参数名     | 类型                                        | 必填 | 说明                                        |
28| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
29| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
30| callback | AsyncCallback\<void\>                       | 是   | 发布通知的回调方法。                        |
31
32**错误码:**
33
34以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
35
36| 错误码ID | 错误信息                                              |
37| -------- | ---------------------------------------------------- |
38| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
39| 1600001  | Internal error.                                      |
40| 1600002  | Marshalling or unmarshalling error.                  |
41| 1600003  | Failed to connect to the service.                    |
42| 1600004  | Notification disabled.                               |
43| 1600005  | Notification slot disabled.                          |
44| 1600007  | The notification does not exist.                     |
45| 1600009  | The notification sending frequency reaches the upper limit.            |
46| 1600012  | No memory space.                                     |
47| 1600014  | No permission.                                       |
48| 1600015  | The current notification status does not support duplicate configurations. |
49| 1600016  | The notification version for this update is too low. |
50| 2300007  | Network unreachable.                                 |
51
52**示例:**
53
54```ts
55import { BusinessError } from '@kit.BasicServicesKit';
56
57// publish回调
58let publishCallback = (err: BusinessError): void => {
59  if (err) {
60    console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
61  } else {
62    console.info("publish success");
63  }
64}
65// 通知Request对象
66let notificationRequest: notificationManager.NotificationRequest = {
67  id: 1,
68  content: {
69    notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
70    normal: {
71      title: "test_title",
72      text: "test_text",
73      additionalText: "test_additionalText"
74    }
75  }
76};
77notificationManager.publish(notificationRequest, publishCallback);
78```
79
80## notificationManager.publish
81
82publish(request: NotificationRequest): Promise\<void\>
83
84发布通知。使用Promise异步回调。
85
86如果新发布通知与已发布通知的ID相同,且label相同,则新通知将取代原有通知。
87
88**系统能力**:SystemCapability.Notification.Notification
89
90**参数:**
91
92| 参数名     | 类型                                        | 必填 | 说明                                        |
93| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
94| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
95
96**返回值:**
97
98| 类型     | 说明 |
99| ------- |--|
100| Promise\<void\> | 无返回结果的Promise对象。 |
101
102**错误码:**
103
104以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
105
106| 错误码ID | 错误信息                                              |
107| -------- | ---------------------------------------------------- |
108| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
109| 1600001  | Internal error.                                      |
110| 1600002  | Marshalling or unmarshalling error.                  |
111| 1600003  | Failed to connect to the service.                    |
112| 1600004  | Notification disabled.                               |
113| 1600005  | Notification slot disabled.                          |
114| 1600007  | The notification does not exist.                     |
115| 1600009  | The notification sending frequency reaches the upper limit.            |
116| 1600012  | No memory space.                                     |
117| 1600014  | No permission.                                       |
118| 1600015  | The current notification status does not support duplicate configurations. |
119| 1600016  | The notification version for this update is too low. |
120| 2300007  | Network unreachable.                                 |
121
122**示例:**
123
124```ts
125import { BusinessError } from '@kit.BasicServicesKit';
126
127// 通知Request对象
128let notificationRequest: notificationManager.NotificationRequest = {
129  id: 1,
130  content: {
131    notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
132    normal: {
133      title: "test_title",
134      text: "test_text",
135      additionalText: "test_additionalText"
136    }
137  }
138};
139notificationManager.publish(notificationRequest).then(() => {
140  console.info("publish success");
141}).catch((err: BusinessError) => {
142  console.error(`publish fail: ${JSON.stringify(err)}`);
143});
144
145```
146
147## notificationManager.cancel
148
149cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
150
151通过通知ID和通知标签取消已发布的通知。使用callback异步回调。
152
153**系统能力**:SystemCapability.Notification.Notification
154
155**参数:**
156
157| 参数名     | 类型                  | 必填 | 说明                 |
158| -------- | --------------------- | ---- | -------------------- |
159| id       | number                | 是   | 通知ID。               |
160| label    | string                | 是   | 通知标签。             |
161| callback | AsyncCallback\<void\> | 是   | 表示被指定通知的回调方法。 |
162
163**错误码:**
164
165以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
166
167| 错误码ID | 错误信息                            |
168| -------- | ----------------------------------- |
169| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
170| 1600001  | Internal error.                     |
171| 1600002  | Marshalling or unmarshalling error. |
172| 1600003  | Failed to connect to the service.          |
173| 1600007  | The notification does not exist.      |
174
175**示例:**
176
177```ts
178import { BusinessError } from '@kit.BasicServicesKit';
179
180// cancel回调
181let cancelCallback = (err: BusinessError): void => {
182  if (err) {
183    console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
184  } else {
185    console.info("cancel success");
186  }
187}
188notificationManager.cancel(0, "label", cancelCallback);
189```
190
191## notificationManager.cancel
192
193cancel(id: number, label?: string): Promise\<void\>
194
195通过通知ID和通知标签取消已发布的通知,若label为空表示取消与指定通知ID相匹配的已发布通知。使用Promise异步回调。
196
197**系统能力**:SystemCapability.Notification.Notification
198
199**参数:**
200
201| 参数名  | 类型   | 必填 | 说明     |
202| ----- | ------ | ---- | -------- |
203| id    | number | 是   | 通知ID。   |
204| label | string | 否   | 通知标签,默认为空。 |
205
206**返回值:**
207
208| 类型     | 说明        |
209| ------- |-----------|
210| Promise\<void\> | 无返回结果的Promise对象。 |
211
212**错误码:**
213
214以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
215
216| 错误码ID | 错误信息                            |
217| -------- | ----------------------------------- |
218| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
219| 1600001  | Internal error.                     |
220| 1600002  | Marshalling or unmarshalling error. |
221| 1600003  | Failed to connect to the service.          |
222| 1600007  | The notification does not exist.      |
223
224**示例:**
225
226```ts
227import { BusinessError } from '@kit.BasicServicesKit';
228
229notificationManager.cancel(0).then(() => {
230  console.info("cancel success");
231}).catch((err: BusinessError) => {
232  console.error(`cancel fail: ${JSON.stringify(err)}`);
233});
234```
235
236## notificationManager.cancel
237
238cancel(id: number, callback: AsyncCallback\<void\>): void
239
240取消与指定通知ID相匹配的已发布通知。使用callback异步回调。
241
242**系统能力**:SystemCapability.Notification.Notification
243
244**参数:**
245
246| 参数名     | 类型                  | 必填 | 说明                 |
247| -------- | --------------------- | ---- | -------------------- |
248| id       | number                | 是   | 通知ID。               |
249| callback | AsyncCallback\<void\> | 是   | 表示被指定通知的回调方法。 |
250
251**错误码:**
252
253以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
254
255| 错误码ID | 错误信息                            |
256| -------- | ----------------------------------- |
257| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
258| 1600001  | Internal error.                     |
259| 1600002  | Marshalling or unmarshalling error. |
260| 1600003  | Failed to connect to the service.          |
261| 1600007  | The notification does not exist.      |
262
263**示例:**
264
265```ts
266import { BusinessError } from '@kit.BasicServicesKit';
267
268// cancel回调
269let cancelCallback = (err: BusinessError): void => {
270  if (err) {
271    console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
272  } else {
273    console.info("cancel success");
274  }
275}
276notificationManager.cancel(0, cancelCallback);
277```
278
279## notificationManager.cancelAll
280
281cancelAll(callback: AsyncCallback\<void\>): void
282
283取消当前应用所有已发布的通知。使用callback异步回调。
284
285**系统能力**:SystemCapability.Notification.Notification
286
287**参数:**
288
289| 参数名     | 类型                  | 必填 | 说明                 |
290| -------- | --------------------- | ---- | -------------------- |
291| callback | AsyncCallback\<void\> | 是   | 表示被指定通知的回调方法。 |
292
293**错误码:**
294
295以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
296
297| 错误码ID | 错误信息                            |
298| -------- | ----------------------------------- |
299| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
300| 1600001  | Internal error.                     |
301| 1600002  | Marshalling or unmarshalling error. |
302| 1600003  | Failed to connect to the service.          |
303
304**示例:**
305
306```ts
307import { BusinessError } from '@kit.BasicServicesKit';
308
309// cancel回调
310let cancelAllCallback = (err: BusinessError): void => {
311  if (err) {
312    console.error(`cancelAll failed, code is ${err.code}, message is ${err.message}`);
313  } else {
314    console.info("cancelAll success");
315  }
316}
317notificationManager.cancelAll(cancelAllCallback);
318```
319
320## notificationManager.cancelAll
321
322cancelAll(): Promise\<void\>
323
324取消当前应用所有已发布的通知。使用Promise异步回调。
325
326**系统能力**:SystemCapability.Notification.Notification
327
328**返回值:**
329
330| 类型     | 说明        |
331| ------- |-----------|
332| Promise\<void\> | 无返回结果的Promise对象。 |
333
334**错误码:**
335
336以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
337
338| 错误码ID | 错误信息                            |
339| -------- | ----------------------------------- |
340| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
341| 1600001  | Internal error.                     |
342| 1600002  | Marshalling or unmarshalling error. |
343| 1600003  | Failed to connect to the service.          |
344
345**示例:**
346
347```ts
348import { BusinessError } from '@kit.BasicServicesKit';
349
350notificationManager.cancelAll().then(() => {
351  console.info("cancelAll success");
352}).catch((err: BusinessError) => {
353  console.error(`cancelAll fail: ${JSON.stringify(err)}`);
354});
355```
356
357## notificationManager.addSlot
358
359addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
360
361创建指定类型的通知渠道。使用callback异步回调。
362
363**系统能力**:SystemCapability.Notification.Notification
364
365**参数:**
366
367| 参数名     | 类型                  | 必填 | 说明                   |
368| -------- | --------------------- | ---- | ---------------------- |
369| type     | [SlotType](#slottype)              | 是   | 要创建的通知渠道的类型。 |
370| callback | AsyncCallback\<void\> | 是   | 表示被指定通道的回调方法。   |
371
372**错误码:**
373
374以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
375
376| 错误码ID | 错误信息                            |
377| -------- | ----------------------------------- |
378| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
379| 1600001  | Internal error.                     |
380| 1600002  | Marshalling or unmarshalling error. |
381| 1600003  | Failed to connect to the service.          |
382| 1600012  | No memory space.                    |
383
384**示例:**
385
386```ts
387import { BusinessError } from '@kit.BasicServicesKit';
388
389// addslot回调
390let addSlotCallBack = (err: BusinessError): void => {
391  if (err) {
392    console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
393  } else {
394    console.info("addSlot success");
395  }
396}
397notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
398```
399
400## notificationManager.addSlot
401
402addSlot(type: SlotType): Promise\<void\>
403
404创建指定类型的通知渠道。使用Promise异步回调。
405
406**系统能力**:SystemCapability.Notification.Notification
407
408**参数:**
409
410| 参数名 | 类型     | 必填 | 说明                   |
411| ---- | -------- | ---- | ---------------------- |
412| type | [SlotType](#slottype) | 是   | 要创建的通知渠道的类型。 |
413
414**返回值:**
415
416| 类型     | 说明        |
417| ------- |-----------|
418| Promise\<void\> | 无返回结果的Promise对象。 |
419
420**错误码:**
421
422以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
423
424| 错误码ID | 错误信息                            |
425| -------- | ----------------------------------- |
426| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
427| 1600001  | Internal error.                     |
428| 1600002  | Marshalling or unmarshalling error. |
429| 1600003  | Failed to connect to the service.          |
430| 1600012  | No memory space.                    |
431
432**示例:**
433
434```ts
435import { BusinessError } from '@kit.BasicServicesKit';
436
437notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION).then(() => {
438  console.info("addSlot success");
439}).catch((err: BusinessError) => {
440  console.error(`addSlot fail: ${JSON.stringify(err)}`);
441});
442```
443
444## notificationManager.getSlot
445
446getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
447
448获取一个指定类型的通知渠道。使用callback异步回调。
449
450**系统能力**:SystemCapability.Notification.Notification
451
452**参数:**
453
454| 参数名     | 类型                              | 必填 | 说明                                                        |
455| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
456| slotType | [SlotType](#slottype)                          | 是   | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 |
457| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 是   | 表示被指定通道的回调方法。                                        |
458
459**错误码:**
460
461以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
462
463| 错误码ID | 错误信息                            |
464| -------- | ----------------------------------- |
465| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
466| 1600001  | Internal error.                     |
467| 1600002  | Marshalling or unmarshalling error. |
468| 1600003  | Failed to connect to the service.          |
469
470**示例:**
471
472```ts
473import { BusinessError } from '@kit.BasicServicesKit';
474
475// getSlot回调
476let getSlotCallback = (err: BusinessError, data: notificationManager.NotificationSlot): void => {
477  if (err) {
478    console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`);
479  } else {
480    console.info(`getSlot success, data is ${JSON.stringify(data)}`);
481  }
482}
483let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
484notificationManager.getSlot(slotType, getSlotCallback);
485```
486
487## notificationManager.getSlot
488
489getSlot(slotType: SlotType): Promise\<NotificationSlot\>
490
491获取一个指定类型的通知渠道。使用Promise异步回调。
492
493**系统能力**:SystemCapability.Notification.Notification
494
495**参数:**
496
497| 参数名     | 类型     | 必填 | 说明                                                        |
498| -------- | -------- | ---- | ----------------------------------------------------------- |
499| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 |
500
501**返回值:**
502
503| 类型                                                        | 说明                                                         |
504| ----------------------------------------------------------- | ------------------------------------------------------------ |
505| Promise\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 以Promise形式返回获取一个通知渠道。 |
506
507**错误码:**
508
509以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
510
511| 错误码ID | 错误信息                            |
512| -------- | ----------------------------------- |
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
518**示例:**
519
520```ts
521import { BusinessError } from '@kit.BasicServicesKit';
522
523let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
524notificationManager.getSlot(slotType).then((data: notificationManager.NotificationSlot) => {
525  console.info("getSlot success, data: " + JSON.stringify(data));
526}).catch((err: BusinessError) => {
527  console.error(`getSlot fail: ${JSON.stringify(err)}`);
528});
529```
530
531## notificationManager.getSlots
532
533getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void
534
535获取此应用程序的所有通知渠道。使用callback异步回调。
536
537**系统能力**:SystemCapability.Notification.Notification
538
539**参数:**
540
541| 参数名     | 类型                              | 必填 | 说明                 |
542| -------- | --------------------------------- | ---- | -------------------- |
543| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 是   | 以callback形式返回获取此应用程序的所有通知渠道的结果。 |
544
545**错误码:**
546
547以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
548
549
550| 错误码ID | 错误信息                            |
551| -------- | ----------------------------------- |
552| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
553| 1600001  | Internal error.                     |
554| 1600002  | Marshalling or unmarshalling error. |
555| 1600003  | Failed to connect to the service.          |
556
557**示例:**
558
559```ts
560import { BusinessError } from '@kit.BasicServicesKit';
561
562// getSlots回调
563let getSlotsCallback = (err: BusinessError, data: Array<notificationManager.NotificationSlot>): void => {
564  if (err) {
565    console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`);
566  } else {
567    console.info(`getSlots success, data is ${JSON.stringify(data)}`);
568  }
569}
570notificationManager.getSlots(getSlotsCallback);
571```
572
573## notificationManager.getSlots
574
575getSlots(): Promise\<Array\<NotificationSlot>>
576
577获取此应用程序的所有通知渠道。使用Promise异步回调。
578
579**系统能力**:SystemCapability.Notification.Notification
580
581**返回值:**
582
583| 类型                                                        | 说明                                                         |
584| ----------------------------------------------------------- | ------------------------------------------------------------ |
585| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 以Promise形式返回获取此应用程序的所有通知渠道的结果。 |
586
587**错误码:**
588
589以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
590
591| 错误码ID | 错误信息                            |
592| -------- | ----------------------------------- |
593| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
594| 1600001  | Internal error.                     |
595| 1600002  | Marshalling or unmarshalling error. |
596| 1600003  | Failed to connect to the service.          |
597
598**示例:**
599
600```ts
601import { BusinessError } from '@kit.BasicServicesKit';
602
603notificationManager.getSlots().then((data: Array<notificationManager.NotificationSlot>) => {
604  console.info("getSlots success, data: " + JSON.stringify(data));
605}).catch((err: BusinessError) => {
606  console.error(`getSlots fail: ${JSON.stringify(err)}`);
607});
608```
609
610## notificationManager.removeSlot
611
612removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
613
614删除此应用程序指定类型的通知渠道。使用callback异步回调。
615
616**系统能力**:SystemCapability.Notification.Notification
617
618**参数:**
619
620| 参数名     | 类型                  | 必填 | 说明                                                        |
621| -------- | --------------------- | ---- | ----------------------------------------------------------- |
622| slotType | [SlotType](#slottype)              | 是   | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 |
623| callback | AsyncCallback\<void\> | 是   | 表示被指定通道的回调方法。                                        |
624
625**错误码:**
626
627以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
628
629| 错误码ID | 错误信息                            |
630| -------- | ----------------------------------- |
631| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
632| 1600001  | Internal error.                     |
633| 1600002  | Marshalling or unmarshalling error. |
634| 1600003  | Failed to connect to the service.          |
635
636**示例:**
637
638```ts
639import { BusinessError } from '@kit.BasicServicesKit';
640
641// removeSlot回调
642let removeSlotCallback = (err: BusinessError): void => {
643  if (err) {
644    console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`);
645  } else {
646    console.info("removeSlot success");
647  }
648}
649let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
650notificationManager.removeSlot(slotType, removeSlotCallback);
651```
652
653## notificationManager.removeSlot
654
655removeSlot(slotType: SlotType): Promise\<void\>
656
657删除此应用程序指定类型的通知渠道。使用Promise异步回调。
658
659**系统能力**:SystemCapability.Notification.Notification
660
661**参数:**
662
663| 参数名     | 类型     | 必填 | 说明                                                        |
664| -------- | -------- | ---- | ----------------------------------------------------------- |
665| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 |
666
667**返回值:**
668
669| 类型      | 说明        |
670|---------|-----------|
671| Promise\<void\> | 无返回结果的Promise对象。 |
672
673**错误码:**
674
675以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
676
677| 错误码ID | 错误信息                            |
678| -------- | ----------------------------------- |
679| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
680| 1600001  | Internal error.                     |
681| 1600002  | Marshalling or unmarshalling error. |
682| 1600003  | Failed to connect to the service.          |
683
684**示例:**
685
686```ts
687import { BusinessError } from '@kit.BasicServicesKit';
688
689let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
690notificationManager.removeSlot(slotType).then(() => {
691  console.info("removeSlot success");
692}).catch((err: BusinessError) => {
693  console.error(`removeSlot fail: ${JSON.stringify(err)}`);
694});
695```
696
697## notificationManager.removeAllSlots
698
699removeAllSlots(callback: AsyncCallback\<void\>): void
700
701删除此应用程序所有通知渠道。使用callback异步回调。
702
703**系统能力**:SystemCapability.Notification.Notification
704
705**参数:**
706
707| 参数名     | 类型                  | 必填 | 说明                 |
708| -------- | --------------------- | ---- | -------------------- |
709| callback | AsyncCallback\<void\> | 是   | 表示被指定通道的回调方法。 |
710
711**错误码:**
712
713以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
714
715| 错误码ID | 错误信息                            |
716| -------- | ----------------------------------- |
717| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
718| 1600001  | Internal error.                     |
719| 1600002  | Marshalling or unmarshalling error. |
720| 1600003  | Failed to connect to the service.          |
721
722**示例:**
723
724```ts
725import { BusinessError } from '@kit.BasicServicesKit';
726
727let removeAllSlotsCallback = (err: BusinessError): void => {
728  if (err) {
729    console.error(`removeAllSlots failed, code is ${err.code}, message is ${err.message}`);
730  } else {
731    console.info("removeAllSlots success");
732  }
733}
734notificationManager.removeAllSlots(removeAllSlotsCallback);
735```
736
737## notificationManager.removeAllSlots
738
739removeAllSlots(): Promise\<void\>
740
741删除此应用程序所有通知渠道。使用Promise异步回调。
742
743**系统能力**:SystemCapability.Notification.Notification
744
745**返回值:**
746
747| 类型      | 说明        |
748|---------|-----------|
749| Promise\<void\> | 无返回结果的Promise对象。 |
750
751**错误码:**
752
753以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
754
755| 错误码ID | 错误信息                            |
756| -------- | ----------------------------------- |
757| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
758| 1600001  | Internal error.                     |
759| 1600002  | Marshalling or unmarshalling error. |
760| 1600003  | Failed to connect to the service.          |
761
762**示例:**
763
764```ts
765import { BusinessError } from '@kit.BasicServicesKit';
766
767notificationManager.removeAllSlots().then(() => {
768  console.info("removeAllSlots success");
769}).catch((err: BusinessError) => {
770  console.error(`removeAllSlots fail: ${JSON.stringify(err)}`);
771});
772```
773
774## notificationManager.isNotificationEnabled<sup>11+</sup>
775
776isNotificationEnabled(callback: AsyncCallback\<boolean\>): void
777
778获取通知使能状态。使用callback异步回调。
779
780**系统能力**:SystemCapability.Notification.Notification
781
782**参数:**
783
784| 参数名     | 类型                  | 必填 | 说明                     |
785| -------- | --------------------- | ---- | ------------------------ |
786| callback | AsyncCallback\<boolean\> | 是   | 获取通知使能状态回调函数(true:使能,false:禁止)。 |
787
788**错误码:**
789
790以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
791
792| 错误码ID | 错误信息                                  |
793| -------- | ---------------------------------------- |
794| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
795| 1600001  | Internal error.                          |
796| 1600002  | Marshalling or unmarshalling error.      |
797| 1600003  | Failed to connect to the service.               |
798| 1600008  | The user does not exist.                   |
799| 17700001 | The specified bundle name was not found. |
800
801**示例:**
802
803```ts
804import { BusinessError } from '@kit.BasicServicesKit';
805
806let isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => {
807  if (err) {
808    console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
809  } else {
810    console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`);
811  }
812}
813
814notificationManager.isNotificationEnabled(isNotificationEnabledCallback);
815```
816
817## notificationManager.isNotificationEnabled<sup>11+</sup>
818
819isNotificationEnabled(): Promise\<boolean\>
820
821获取通知使能状态。使用Promise异步回调。
822
823**系统能力**:SystemCapability.Notification.Notification
824
825**返回值:**
826
827| 类型                                                        | 说明                                                         |
828| ----------------------------------------------------------- | ------------------------------------------------------------ |
829| Promise\<boolean\> | 以Promise形式返回获取通知使能状态的结果(true:使能,false:禁止)。 |
830
831**错误码:**
832
833以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
834
835| 错误码ID | 错误信息                                 |
836| -------- | ---------------------------------------- |
837| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
838| 1600001  | Internal error.                          |
839| 1600002  | Marshalling or unmarshalling error.      |
840| 1600003  | Failed to connect to the service.               |
841| 1600008  | The user does not exist.                   |
842| 17700001 | The specified bundle name was not found. |
843
844**示例:**
845
846```ts
847import { BusinessError } from '@kit.BasicServicesKit';
848
849notificationManager.isNotificationEnabled().then((data: boolean) => {
850  console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
851}).catch((err: BusinessError) => {
852  console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`);
853});
854```
855
856## notificationManager.isNotificationEnabledSync<sup>12+</sup>
857
858isNotificationEnabledSync(): boolean
859
860同步获取通知使能状态。
861
862**系统能力**:SystemCapability.Notification.Notification
863
864**返回值:**
865
866| 类型                                                        | 说明                                                     |
867| ----------------------------------------------------------- |--------------------------------------------------------- |
868| boolean | 返回获取通知使能状态的结果。返回true,表示通知使能状态为开;返回false,表示通知使能状态为关。 |
869
870**错误码:**
871
872以下错误码的详细介绍请参见[通知错误码](./errorcode-notification.md)。
873
874| 错误码ID | 错误信息                                 |
875| -------- | ---------------------------------------- |
876| 1600001  | Internal error.                          |
877| 1600002  | Marshalling or unmarshalling error.      |
878| 1600003  | Failed to connect to the service.               |
879
880**示例:**
881
882```ts
883let enabled = notificationManager.isNotificationEnabledSync();
884console.info(`isNotificationEnabledSync success, data is : ${JSON.stringify(enabled)}`);
885```
886
887## notificationManager.setBadgeNumber<sup>10+</sup>
888
889setBadgeNumber(badgeNumber: number): Promise\<void\>
890
891设定角标个数,在应用的桌面图标上呈现。使用Promise异步回调。
892
893当角标设定个数取值0时,表示清除角标。取值大于99时,通知角标将显示99+。
894
895**系统能力**:SystemCapability.Notification.Notification
896
897**参数:**
898
899| 参数名      | 类型   | 必填 | 说明       |
900| ----------- | ------ | ---- | ---------- |
901| badgeNumber | number | 是   | 角标个数。 |
902
903**返回值:**
904
905| 类型      | 说明        |
906|---------|-----------|
907| Promise\<void\> | 无返回结果的Promise对象。 |
908
909**错误码:**
910
911以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
912
913| 错误码ID | 错误信息                            |
914| -------- | ----------------------------------- |
915| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
916| 1600001  | Internal error.                     |
917| 1600002  | Marshalling or unmarshalling error. |
918| 1600003  | Failed to connect to the service.          |
919| 1600012  | No memory space.                          |
920
921**示例:**
922
923```ts
924import { BusinessError } from '@kit.BasicServicesKit';
925
926let badgeNumber: number = 10;
927notificationManager.setBadgeNumber(badgeNumber).then(() => {
928  console.info("setBadgeNumber success");
929}).catch((err: BusinessError) => {
930  console.error(`setBadgeNumber fail: ${JSON.stringify(err)}`);
931});
932```
933
934## notificationManager.setBadgeNumber<sup>10+</sup>
935
936setBadgeNumber(badgeNumber: number, callback: AsyncCallback\<void\>): void
937
938设定角标个数,在应用的桌面图标上呈现。使用callback异步回调。
939
940当角标设定个数取值0时,表示清除角标。取值大于99时,通知角标将显示99+。
941
942**系统能力**:SystemCapability.Notification.Notification
943
944**参数:**
945
946| 参数名      | 类型                  | 必填 | 说明               |
947| ----------- | --------------------- | ---- | ------------------ |
948| badgeNumber | number                | 是   | 角标个数。         |
949| callback    | AsyncCallback\<void\> | 是   | 设定角标回调函数。 |
950
951**错误码:**
952
953以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
954
955| 错误码ID | 错误信息                            |
956| -------- | ----------------------------------- |
957| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
958| 1600001  | Internal error.                     |
959| 1600002  | Marshalling or unmarshalling error. |
960| 1600003  | Failed to connect to the service.          |
961| 1600012  | No memory space.                          |
962
963**示例:**
964
965```ts
966import { BusinessError } from '@kit.BasicServicesKit';
967
968let setBadgeNumberCallback = (err: BusinessError): void => {
969  if (err) {
970    console.error(`setBadgeNumber failed code is ${err.code}, message is ${err.message}`);
971  } else {
972    console.info("setBadgeNumber success");
973  }
974}
975let badgeNumber: number = 10;
976notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback);
977```
978
979## notificationManager.getActiveNotificationCount
980
981getActiveNotificationCount(callback: AsyncCallback\<number\>): void
982
983获取当前应用未删除的通知数。使用callback异步回调。
984
985**系统能力**:SystemCapability.Notification.Notification
986
987**参数:**
988
989| 参数名     | 类型                   | 必填 | 说明                   |
990| -------- | ---------------------- | ---- | ---------------------- |
991| callback | AsyncCallback\<number\> | 是   | 获取未删除通知数回调函数。 |
992
993**错误码:**
994
995以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
996
997| 错误码ID | 错误信息                            |
998| -------- | ----------------------------------- |
999| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1000| 1600001  | Internal error.                     |
1001| 1600002  | Marshalling or unmarshalling error. |
1002| 1600003  | Failed to connect to the service.          |
1003
1004**示例:**
1005
1006```ts
1007import { BusinessError } from '@kit.BasicServicesKit';
1008
1009let getActiveNotificationCountCallback = (err: BusinessError, data: number): void => {
1010  if (err) {
1011    console.error(`getActiveNotificationCount failed, code is ${err.code}, message is ${err.message}`);
1012  } else {
1013    console.info(`getActiveNotificationCount success, data is ${JSON.stringify(data)}`);
1014  }
1015}
1016
1017notificationManager.getActiveNotificationCount(getActiveNotificationCountCallback);
1018```
1019
1020## notificationManager.getActiveNotificationCount
1021
1022getActiveNotificationCount(): Promise\<number\>
1023
1024获取当前应用未删除的通知数。使用Promise异步回调。
1025
1026**系统能力**:SystemCapability.Notification.Notification
1027
1028**返回值:**
1029
1030| 类型              | 说明                                        |
1031| ----------------- | ------------------------------------------- |
1032| Promise\<number\> | 以Promise形式返回获取当前应用未删除通知数。 |
1033
1034**错误码:**
1035
1036以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1037
1038| 错误码ID | 错误信息                            |
1039| -------- | ----------------------------------- |
1040| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1041| 1600001  | Internal error.                     |
1042| 1600002  | Marshalling or unmarshalling error. |
1043| 1600003  | Failed to connect to the service.          |
1044
1045**示例:**
1046
1047```ts
1048import { BusinessError } from '@kit.BasicServicesKit';
1049
1050notificationManager.getActiveNotificationCount().then((data: number) => {
1051  console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
1052}).catch((err: BusinessError) => {
1053  console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`);
1054});
1055```
1056
1057## notificationManager.getActiveNotifications
1058
1059getActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void
1060
1061获取当前应用未删除的通知列表。使用callback异步回调。
1062
1063**系统能力**:SystemCapability.Notification.Notification
1064
1065**参数:**
1066
1067| 参数名     | 类型                                                         | 必填 | 说明                           |
1068| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
1069| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | 是   | 获取当前应用通知列表回调函数。 |
1070
1071**错误码:**
1072
1073以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1074
1075| 错误码ID | 错误信息                            |
1076| -------- | ----------------------------------- |
1077| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1078| 1600001  | Internal error.                     |
1079| 1600002  | Marshalling or unmarshalling error. |
1080| 1600003  | Failed to connect to the service.          |
1081
1082**示例:**
1083
1084```ts
1085import { BusinessError } from '@kit.BasicServicesKit';
1086
1087let getActiveNotificationsCallback = (err: BusinessError, data: Array<notificationManager.NotificationRequest>): void => {
1088  if (err) {
1089    console.error(`getActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
1090  } else {
1091    console.info("getActiveNotifications success" + JSON.stringify(data));
1092  }
1093}
1094notificationManager.getActiveNotifications(getActiveNotificationsCallback);
1095```
1096
1097## notificationManager.getActiveNotifications
1098
1099getActiveNotifications(): Promise\<Array\<NotificationRequest\>\>
1100
1101获取当前应用未删除的通知列表。使用Promise异步回调。
1102
1103**系统能力**:SystemCapability.Notification.Notification
1104
1105**返回值:**
1106
1107| 类型                                                         | 说明                                    |
1108| ------------------------------------------------------------ | --------------------------------------- |
1109| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | 以Promise形式返回获取当前应用通知列表。 |
1110
1111**错误码:**
1112
1113以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1114
1115| 错误码ID | 错误信息                            |
1116| -------- | ----------------------------------- |
1117| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1118| 1600001  | Internal error.                     |
1119| 1600002  | Marshalling or unmarshalling error. |
1120| 1600003  | Failed to connect to the service.          |
1121
1122**示例:**
1123
1124```ts
1125import { BusinessError } from '@kit.BasicServicesKit';
1126
1127notificationManager.getActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => {
1128  console.info("getActiveNotifications success, data: " + JSON.stringify(data));
1129}).catch((err: BusinessError) => {
1130  console.error(`getActiveNotifications fail: ${JSON.stringify(err)}`);
1131});
1132```
1133
1134## notificationManager.cancelGroup
1135
1136cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
1137
1138取消本应用指定组下的通知。使用callback异步回调。
1139
1140**系统能力**:SystemCapability.Notification.Notification
1141
1142**参数:**
1143
1144| 参数名      | 类型                  | 必填 | 说明                         |
1145| --------- | --------------------- | ---- | ---------------------------- |
1146| groupName | string                | 是   | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象指定。 |
1147| callback  | AsyncCallback\<void\> | 是   | 取消本应用指定组下通知的回调函数。 |
1148
1149**错误码:**
1150
1151以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1152
1153| 错误码ID | 错误信息                            |
1154| -------- | ----------------------------------- |
1155| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1156| 1600001  | Internal error.                     |
1157| 1600002  | Marshalling or unmarshalling error. |
1158| 1600003  | Failed to connect to the service.          |
1159
1160**示例:**
1161
1162```ts
1163import { BusinessError } from '@kit.BasicServicesKit';
1164
1165let cancelGroupCallback = (err: BusinessError): void => {
1166  if (err) {
1167    console.error(`cancelGroup failed, code is ${err.code}, message is ${err.message}`);
1168  } else {
1169    console.info("cancelGroup success");
1170  }
1171}
1172let groupName: string = "GroupName";
1173notificationManager.cancelGroup(groupName, cancelGroupCallback);
1174```
1175
1176## notificationManager.cancelGroup
1177
1178cancelGroup(groupName: string): Promise\<void\>
1179
1180取消本应用指定组下的通知。使用Promise异步回调。
1181
1182**系统能力**:SystemCapability.Notification.Notification
1183
1184**参数:**
1185
1186| 参数名      | 类型   | 必填 | 说明           |
1187| --------- | ------ | ---- | -------------- |
1188| groupName | string | 是   | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象指定。 |
1189
1190**返回值:**
1191
1192| 类型      | 说明        |
1193|---------|-----------|
1194| Promise\<void\> | 无返回结果的Promise对象。 |
1195
1196**错误码:**
1197
1198以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1199
1200| 错误码ID | 错误信息                            |
1201| -------- | ----------------------------------- |
1202| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1203| 1600001  | Internal error.                     |
1204| 1600002  | Marshalling or unmarshalling error. |
1205| 1600003  | Failed to connect to the service.          |
1206
1207**示例:**
1208
1209```ts
1210import { BusinessError } from '@kit.BasicServicesKit';
1211
1212let groupName: string = "GroupName";
1213notificationManager.cancelGroup(groupName).then(() => {
1214  console.info("cancelGroup success");
1215}).catch((err: BusinessError) => {
1216  console.error(`cancelGroup fail: ${JSON.stringify(err)}`);
1217});
1218```
1219
1220## notificationManager.isSupportTemplate
1221
1222isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void
1223
1224查询模板是否存在。使用callback异步回调。
1225
1226**系统能力**:SystemCapability.Notification.Notification
1227
1228**参数:**
1229
1230| 参数名       | 类型                     | 必填 | 说明                       |
1231| ------------ | ------------------------ | ---- | -------------------------- |
1232| templateName | string                   | 是   | 模板名称。当前仅支持'downloadTemplate'。                   |
1233| callback     | AsyncCallback\<boolean\> | 是   | 查询模板是否存在的回调函数(true:存在,false:不存在)。 |
1234
1235**错误码:**
1236
1237以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1238
1239| 错误码ID | 错误信息                            |
1240| -------- | ----------------------------------- |
1241| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1242| 1600001  | Internal error.                     |
1243| 1600002  | Marshalling or unmarshalling error. |
1244| 1600003  | Failed to connect to the service.          |
1245
1246**示例:**
1247
1248```ts
1249import { BusinessError } from '@kit.BasicServicesKit';
1250
1251let templateName: string = 'downloadTemplate';
1252let isSupportTemplateCallback = (err: BusinessError, data: boolean): void => {
1253  if (err) {
1254    console.error(`isSupportTemplate failed, code is ${err.code}, message is ${err.message}`);
1255  } else {
1256    console.info("isSupportTemplate success, data: " + JSON.stringify(data));
1257  }
1258}
1259notificationManager.isSupportTemplate(templateName, isSupportTemplateCallback);
1260```
1261
1262## notificationManager.isSupportTemplate
1263
1264isSupportTemplate(templateName: string): Promise\<boolean\>
1265
1266查询模板是否存在。使用Promise异步回调。
1267
1268**系统能力**:SystemCapability.Notification.Notification
1269
1270**参数:**
1271
1272| 参数名       | 类型   | 必填 | 说明     |
1273| ------------ | ------ | ---- | -------- |
1274| templateName | string | 是   | 模板名称。当前仅支持'downloadTemplate'。 |
1275
1276**返回值:**
1277
1278| 类型               | 说明            |
1279| ------------------ | --------------- |
1280| Promise\<boolean\> | Promise方式返回模板是否存在的结果(true:存在,false:不存在)。 |
1281
1282**错误码:**
1283
1284以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1285
1286| 错误码ID | 错误信息                            |
1287| -------- | ----------------------------------- |
1288| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1289| 1600001  | Internal error.                     |
1290| 1600002  | Marshalling or unmarshalling error. |
1291| 1600003  | Failed to connect to the service.          |
1292
1293**示例:**
1294
1295```ts
1296import { BusinessError } from '@kit.BasicServicesKit';
1297
1298let templateName: string = 'downloadTemplate';
1299notificationManager.isSupportTemplate(templateName).then((data: boolean) => {
1300  console.info("isSupportTemplate success, data: " + JSON.stringify(data));
1301}).catch((err: BusinessError) => {
1302  console.error(`isSupportTemplate fail: ${JSON.stringify(err)}`);
1303});
1304```
1305
1306## notificationManager.requestEnableNotification<sup>(deprecated)</sup>
1307
1308requestEnableNotification(callback: AsyncCallback\<void\>): void
1309
1310应用请求通知使能。使用callback异步回调。
1311
1312> **说明:**
1313>
1314> 从API version 12开始不再维护,建议使用有context入参的[requestEnableNotification](#notificationmanagerrequestenablenotification10)代替。
1315
1316**系统能力**:SystemCapability.Notification.Notification
1317
1318**参数:**
1319
1320| 参数名   | 类型                     | 必填 | 说明                       |
1321| -------- | ------------------------ | ---- | -------------------------- |
1322| callback | AsyncCallback\<void\> | 是   | 应用请求通知使能的回调函数。 |
1323
1324**错误码:**
1325
1326以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1327
1328| 错误码ID | 错误信息                            |
1329| -------- | ----------------------------------- |
1330| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1331| 1600001  | Internal error.                     |
1332| 1600002  | Marshalling or unmarshalling error. |
1333| 1600003  | Failed to connect to the service.          |
1334| 1600004  | Notification disabled.          |
1335| 1600013  | A notification dialog box is already displayed.           |
1336
1337**示例:**
1338
1339```ts
1340import { BusinessError } from '@kit.BasicServicesKit';
1341
1342let requestEnableNotificationCallback = (err: BusinessError): void => {
1343  if (err) {
1344    console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
1345  } else {
1346    console.info("requestEnableNotification success");
1347  }
1348};
1349notificationManager.requestEnableNotification(requestEnableNotificationCallback);
1350```
1351
1352## notificationManager.requestEnableNotification<sup>(deprecated)</sup>
1353
1354requestEnableNotification(): Promise\<void\>
1355
1356应用请求通知使能。使用Promise异步回调。
1357
1358> **说明:**
1359>
1360> 从API version 12开始不再维护,建议使用有context入参的[requestEnableNotification](#notificationmanagerrequestenablenotification10-1)代替。
1361
1362**系统能力**:SystemCapability.Notification.Notification
1363
1364**返回值:**
1365
1366| 类型      | 说明        |
1367|---------|-----------|
1368| Promise\<void\> | 无返回结果的Promise对象。 |
1369
1370**错误码:**
1371
1372以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1373
1374| 错误码ID | 错误信息                            |
1375| -------- | ----------------------------------- |
1376| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1377| 1600001  | Internal error.                     |
1378| 1600002  | Marshalling or unmarshalling error. |
1379| 1600003  | Failed to connect to the service.          |
1380| 1600004  | Notification disabled.          |
1381| 1600013  | A notification dialog box is already displayed.           |
1382
1383**示例:**
1384
1385```ts
1386import { BusinessError } from '@kit.BasicServicesKit';
1387
1388notificationManager.requestEnableNotification().then(() => {
1389  console.info("requestEnableNotification success");
1390}).catch((err: BusinessError) => {
1391  console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`);
1392});
1393```
1394
1395## notificationManager.requestEnableNotification<sup>10+</sup>
1396
1397requestEnableNotification(context: UIAbilityContext, callback: AsyncCallback\<void\>): void
1398
1399应用请求通知使能模态弹窗。使用callback异步回调。
1400
1401仅当应用界面加载完成后(即调用[loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent)成功),方可使用该接口。
1402
1403**模型约束**:此接口仅可在Stage模型下使用。
1404
1405**系统能力**:SystemCapability.Notification.Notification
1406
1407**参数:**
1408
1409| 参数名   | 类型                     | 必填 | 说明                 |
1410| -------- | ------------------------ | ---- |--------------------|
1411| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是   | 通知弹窗绑定Ability的上下文。 |
1412| callback | AsyncCallback\<void\> | 是   | 应用请求通知使能的回调函数。     |
1413
1414**错误码:**
1415
1416以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1417
1418| 错误码ID | 错误信息                            |
1419| -------- | ----------------------------------- |
1420| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1421| 1600001  | Internal error.                     |
1422| 1600002  | Marshalling or unmarshalling error. |
1423| 1600003  | Failed to connect to the service.          |
1424| 1600004  | Notification disabled.          |
1425| 1600013  | A notification dialog box is already displayed.           |
1426
1427**示例:**
1428
1429```ts
1430import { BusinessError } from '@kit.BasicServicesKit';
1431import { UIAbility } from '@kit.AbilityKit';
1432import { window } from '@kit.ArkUI';
1433import { hilog } from '@kit.PerformanceAnalysisKit';
1434
1435class MyAbility extends UIAbility {
1436  onWindowStageCreate(windowStage: window.WindowStage) {
1437  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
1438    windowStage.loadContent('pages/Index', (err, data) => {
1439      if (err.code) {
1440        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
1441        return;
1442      }
1443      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
1444      let requestEnableNotificationCallback = (err: BusinessError): void => {
1445        if (err) {
1446          hilog.error(0x0000, 'testTag', `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
1447        } else {
1448          hilog.info(0x0000, 'testTag', `[ANS] requestEnableNotification success`);
1449        }
1450      };
1451      notificationManager.requestEnableNotification(this.context, requestEnableNotificationCallback);
1452    });
1453  }
1454}
1455```
1456
1457## notificationManager.requestEnableNotification<sup>10+</sup>
1458
1459requestEnableNotification(context: UIAbilityContext): Promise\<void\>
1460
1461应用请求通知使能模态弹窗。使用Promise异步回调。
1462
1463仅当应用界面加载完成后(即调用[loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent)成功),方可使用该接口。
1464
1465**模型约束**:此接口仅可在Stage模型下使用。
1466
1467**系统能力**:SystemCapability.Notification.Notification
1468
1469**参数:**
1470
1471| 参数名   | 类型                     | 必填 | 说明                 |
1472| -------- | ------------------------ | ---- |--------------------|
1473| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是   | 通知弹窗绑定Ability的上下文。 |
1474
1475**返回值:**
1476
1477| 类型      | 说明        |
1478|---------|-----------|
1479| Promise\<void\> | 无返回结果的Promise对象。 |
1480
1481**错误码:**
1482
1483以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1484
1485| 错误码ID | 错误信息                            |
1486| -------- | ----------------------------------- |
1487| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1488| 1600001  | Internal error.                     |
1489| 1600002  | Marshalling or unmarshalling error. |
1490| 1600003  | Failed to connect to the service.          |
1491| 1600004  | Notification disabled.          |
1492| 1600013  | A notification dialog box is already displayed.           |
1493
1494**示例:**
1495
1496```ts
1497import { BusinessError } from '@kit.BasicServicesKit';
1498import { UIAbility } from '@kit.AbilityKit';
1499import { window } from '@kit.ArkUI';
1500import { hilog } from '@kit.PerformanceAnalysisKit';
1501
1502class MyAbility extends UIAbility {
1503  onWindowStageCreate(windowStage: window.WindowStage) {
1504    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
1505    windowStage.loadContent('pages/Index', (err, data) => {
1506      if (err.code) {
1507        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
1508        return;
1509      }
1510      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
1511      notificationManager.requestEnableNotification(this.context).then(() => {
1512        hilog.info(0x0000, 'testTag', `[ANS] requestEnableNotification success`);
1513      }).catch((err: BusinessError) => {
1514        hilog.error(0x0000, 'testTag', `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
1515      });
1516    });
1517  }
1518}
1519```
1520
1521## notificationManager.isDistributedEnabled
1522
1523isDistributedEnabled(callback: AsyncCallback\<boolean>): void
1524
1525查询设备是否支持分布式通知。使用callback异步回调。
1526
1527**系统能力**:SystemCapability.Notification.Notification
1528
1529**参数:**
1530
1531| 参数名   | 类型                     | 必填 | 说明                       |
1532| -------- | ------------------------ | ---- | -------------------------- |
1533| callback | AsyncCallback\<boolean\> | 是   | 设备是否支持分布式通知的回调函数(true:支持,false:不支持)。 |
1534
1535**错误码:**
1536
1537以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1538
1539| 错误码ID | 错误信息                            |
1540| -------- | ----------------------------------- |
1541| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1542| 1600001  | Internal error.                     |
1543| 1600002  | Marshalling or unmarshalling error. |
1544| 1600003  | Failed to connect to the service.          |
1545| 1600010  | Distributed operation failed.       |
1546
1547**示例:**
1548
1549```ts
1550import { BusinessError } from '@kit.BasicServicesKit';
1551
1552let isDistributedEnabledCallback = (err: BusinessError, data: boolean): void => {
1553  if (err) {
1554    console.error(`isDistributedEnabled failed, code is ${err.code}, message is ${err.message}`);
1555  } else {
1556    console.info("isDistributedEnabled success " + JSON.stringify(data));
1557  }
1558};
1559notificationManager.isDistributedEnabled(isDistributedEnabledCallback);
1560```
1561
1562## notificationManager.isDistributedEnabled
1563
1564isDistributedEnabled(): Promise\<boolean>
1565
1566查询设备是否支持分布式通知。使用Promise异步回调。
1567
1568**系统能力**:SystemCapability.Notification.Notification
1569
1570**返回值:**
1571
1572| 类型               | 说明                                          |
1573| ------------------ | --------------------------------------------- |
1574| Promise\<boolean\> | Promise方式返回设备是否支持分布式通知的结果(true:支持,false:不支持)。 |
1575
1576**错误码:**
1577
1578以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1579
1580| 错误码ID | 错误信息                            |
1581| -------- | ----------------------------------- |
1582| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1583| 1600001  | Internal error.                     |
1584| 1600002  | Marshalling or unmarshalling error. |
1585| 1600003  | Failed to connect to the service.          |
1586| 1600010  | Distributed operation failed.       |
1587
1588**示例:**
1589
1590```ts
1591import { BusinessError } from '@kit.BasicServicesKit';
1592
1593notificationManager.isDistributedEnabled().then((data: boolean) => {
1594  console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
1595}).catch((err: BusinessError) => {
1596  console.error(`isDistributedEnabled fail: ${JSON.stringify(err)}`);
1597});
1598```
1599
1600## notificationManager.openNotificationSettings<sup>13+</sup>
1601
1602openNotificationSettings(context: UIAbilityContext): Promise\<void\>
1603
1604拉起应用的通知设置界面,该页面以半模态形式呈现,可用于设置通知开关、通知提醒方式等。使用Promise异步回调。
1605
1606**模型约束**:此接口仅可在Stage模型下使用。
1607
1608**系统能力**:SystemCapability.Notification.NotificationSettings
1609
1610**参数:**
1611
1612| 参数名   | 类型                     | 必填 | 说明                 |
1613| -------- | ------------------------ | ---- |--------------------|
1614| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是   | 通知设置页面绑定Ability的上下文。 |
1615
1616**返回值:**
1617
1618| 类型      | 说明        |
1619|---------|-----------|
1620| Promise\<void\> | 无返回结果的Promise对象。 |
1621
1622**错误码:**
1623
1624以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。
1625
1626| 错误码ID | 错误信息                            |
1627| -------- | ----------------------------------- |
1628| 1600001  | Internal error.                     |
1629| 1600003  | Failed to connect to the service.          |
1630| 1600018  | the notification settings window is already displayed.           |
1631
1632**示例:**
1633
1634```ts
1635import { BusinessError } from '@kit.BasicServicesKit';
1636import { UIAbility } from '@kit.AbilityKit';
1637import { window } from '@kit.ArkUI';
1638import { hilog } from '@kit.PerformanceAnalysisKit';
1639
1640class MyAbility extends UIAbility {
1641  onWindowStageCreate(windowStage: window.WindowStage) {
1642    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
1643    windowStage.loadContent('pages/Index', (err, data) => {
1644      if (err.code) {
1645        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
1646        return;
1647      }
1648      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
1649      notificationManager.openNotificationSettings(this.context).then(() => {
1650        hilog.info(0x0000, 'testTag', `[ANS] openNotificationSettings success`);
1651      }).catch((err: BusinessError) => {
1652        hilog.error(0x0000, 'testTag', `[ANS] openNotificationSettings failed, code is ${err.code}, message is ${err.message}`);
1653      });
1654    });
1655  }
1656}
1657```
1658
1659## ContentType
1660
1661通知内容类型。
1662
1663**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1664
1665**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1666
1667| 名称                              | 值          | 说明               |
1668| --------------------------------- | ----------- |------------------|
1669| NOTIFICATION_CONTENT_BASIC_TEXT   | 0          | 普通类型通知。          |
1670| NOTIFICATION_CONTENT_LONG_TEXT    | 1          | 长文本类型通知。         |
1671| NOTIFICATION_CONTENT_PICTURE      | 2          | 图片类型通知。          |
1672| NOTIFICATION_CONTENT_CONVERSATION | 3          | 社交类型通知。预留能力,暂未支持。|
1673| NOTIFICATION_CONTENT_MULTILINE    | 4          | 多行文本类型通知。        |
1674| NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW<sup>11+</sup>    | 5 | 实况窗类型通知。不支持三方应用直接创建该类型通知,可以由系统代理创建系统实况窗类型通知后,三方应用发布同ID的通知来更新指定内容。|
1675| NOTIFICATION_CONTENT_LIVE_VIEW<sup>11+</sup>    | 6 | 普通实况窗类型通知。只支持系统应用。  |
1676
1677## SlotLevel
1678
1679通知级别。
1680
1681**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1682
1683| 名称                              | 值          | 说明               |
1684| --------------------------------- | ----------- | ------------------ |
1685| LEVEL_NONE                        | 0           | 表示关闭通知功能。     |
1686| LEVEL_MIN                         | 1           | 表示通知功能已启用,但状态栏中不显示通知图标,且没有横幅或提示音。 |
1687| LEVEL_LOW                         | 2           | 表示通知功能已启用,且状态栏中显示通知图标,但没有横幅或提示音。 |
1688| LEVEL_DEFAULT                     | 3           | 表示通知功能已启用,状态栏中显示通知图标,没有横幅但有提示音。 |
1689| LEVEL_HIGH                        | 4           | 表示通知功能已启用,状态栏中显示通知图标,有横幅和提示音。 |
1690
1691
1692## SlotType
1693
1694通知渠道类型。
1695
1696**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1697
1698**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1699
1700| 名称                 | 值       | 说明       |
1701| -------------------- | -------- | ---------- |
1702| UNKNOWN_TYPE         | 0 | 未知类型。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 |
1703| SOCIAL_COMMUNICATION | 1 | 社交通信。该类型对应[SlotLevel](#slotlevel)为LEVEL_HIGH。 |
1704| SERVICE_INFORMATION  | 2 | 服务提醒。该类型对应[SlotLevel](#slotlevel)为LEVEL_HIGH。|
1705| CONTENT_INFORMATION  | 3 | 内容资讯。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 |
1706| LIVE_VIEW<sup>11+</sup>            | 4 | 实况窗。不支持三方应用直接创建该渠道类型通知,可以由系统代理创建后,三方应用发布同ID的通知来更新指定内容。该类型对应[SlotLevel](#slotlevel)为LEVEL_DEFAULT。 |
1707| CUSTOMER_SERVICE<sup>11+</sup>     | 5 | 客服消息。该类型用于用户与商家之间的客服消息,需由用户主动发起。该类型对应[SlotLevel](#slotlevel)为LEVEL_DEFAULT。  |
1708| OTHER_TYPES          | 0xFFFF | 其他。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 |
1709