1# @ohos.notificationManager (NotificationManager)
2
3The **NotificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { notificationManager } from '@kit.NotificationKit';
13```
14
15## notificationManager.publish
16
17publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
18
19Publish a notification. This API uses an asynchronous callback to return the result.
20
21If the ID and label of the new notification are the same as that of the previous notification, the new one replaces the previous one.
22
23**System capability**: SystemCapability.Notification.Notification
24
25**Parameters**
26
27| Name    | Type                                       | Mandatory| Description                                       |
28| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
29| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
30| callback | AsyncCallback\<void\>                       | Yes  | Callback used to return the result.                       |
31
32**Error codes**
33
34For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
35
36| ID| Error Message                                             |
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**Example**
53
54```ts
55import { BusinessError } from '@kit.BasicServicesKit';
56
57// publish callback
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// NotificationRequest object
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
84Publish a notification. This API uses a promise to return the URI of the file in the destination directory.
85
86If the ID and label of the new notification are the same as that of the previous notification, the new one replaces the previous one.
87
88**System capability**: SystemCapability.Notification.Notification
89
90**Parameters**
91
92| Name    | Type                                       | Mandatory| Description                                       |
93| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
94| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | Yes  | Content and related configuration of the notification to publish.|
95
96**Return value**
97
98| Type    | Description|
99| ------- |--|
100| Promise\<void\> | Promise that returns no value.|
101
102**Error codes**
103
104For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
105
106| ID| Error Message                                             |
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**Example**
123
124```ts
125import { BusinessError } from '@kit.BasicServicesKit';
126
127// NotificationRequest object
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
151Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result.
152
153**System capability**: SystemCapability.Notification.Notification
154
155**Parameters**
156
157| Name    | Type                 | Mandatory| Description                |
158| -------- | --------------------- | ---- | -------------------- |
159| id       | number                | Yes  | Notification ID.              |
160| label    | string                | Yes  | Notification label.            |
161| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
162
163**Error codes**
164
165For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
166
167| ID| Error Message                           |
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**Example**
176
177```ts
178import { BusinessError } from '@kit.BasicServicesKit';
179
180// cancel callback
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
195Cancels a notification with the specified ID and optional label. This API uses a promise to return the URI of the file in the destination directory.
196
197**System capability**: SystemCapability.Notification.Notification
198
199**Parameters**
200
201| Name | Type  | Mandatory| Description    |
202| ----- | ------ | ---- | -------- |
203| id    | number | Yes  | Notification ID.  |
204| label | string | No  | Notification label. This parameter is left empty by default.|
205
206**Return value**
207
208| Type    | Description       |
209| ------- |-----------|
210| Promise\<void\> | Promise that returns no value.|
211
212**Error codes**
213
214For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
215
216| ID| Error Message                           |
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**Example**
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
240Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result.
241
242**System capability**: SystemCapability.Notification.Notification
243
244**Parameters**
245
246| Name    | Type                 | Mandatory| Description                |
247| -------- | --------------------- | ---- | -------------------- |
248| id       | number                | Yes  | Notification ID.              |
249| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
250
251**Error codes**
252
253For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
254
255| ID| Error Message                           |
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**Example**
264
265```ts
266import { BusinessError } from '@kit.BasicServicesKit';
267
268// cancel callback
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
283Cancels all notifications of this application. This API uses an asynchronous callback to return the result.
284
285**System capability**: SystemCapability.Notification.Notification
286
287**Parameters**
288
289| Name    | Type                 | Mandatory| Description                |
290| -------- | --------------------- | ---- | -------------------- |
291| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
292
293**Error codes**
294
295For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
296
297| ID| Error Message                           |
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**Example**
305
306```ts
307import { BusinessError } from '@kit.BasicServicesKit';
308
309// cancel callback
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
324Cancels all notifications of this application. This API uses a promise to return the URI of the file in the destination directory.
325
326**System capability**: SystemCapability.Notification.Notification
327
328**Return value**
329
330| Type    | Description       |
331| ------- |-----------|
332| Promise\<void\> | Promise that returns no value.|
333
334**Error codes**
335
336For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
337
338| ID| Error Message                           |
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**Example**
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
361Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.
362
363**System capability**: SystemCapability.Notification.Notification
364
365**Parameters**
366
367| Name    | Type                 | Mandatory| Description                  |
368| -------- | --------------------- | ---- | ---------------------- |
369| type     | [SlotType](#slottype)              | Yes  | Type of the notification slot to add.|
370| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.  |
371
372**Error codes**
373
374For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
375
376| ID| Error Message                           |
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**Example**
385
386```ts
387import { BusinessError } from '@kit.BasicServicesKit';
388
389// addSlot callback
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
404Adds a notification slot of a specified type. This API uses a promise to return the URI of the file in the destination directory.
405
406**System capability**: SystemCapability.Notification.Notification
407
408**Parameters**
409
410| Name| Type    | Mandatory| Description                  |
411| ---- | -------- | ---- | ---------------------- |
412| type | [SlotType](#slottype) | Yes  | Type of the notification slot to add.|
413
414**Return value**
415
416| Type    | Description       |
417| ------- |-----------|
418| Promise\<void\> | Promise that returns no value.|
419
420**Error codes**
421
422For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
423
424| ID| Error Message                           |
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**Example**
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
448Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result.
449
450**System capability**: SystemCapability.Notification.Notification
451
452**Parameters**
453
454| Name    | Type                             | Mandatory| Description                                                       |
455| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
456| slotType | [SlotType](#slottype)                          | Yes  | Type of a notification slot, including social communication, service notification, and content consultation.|
457| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Yes  | Callback used to return the result.                                       |
458
459**Error codes**
460
461For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
462
463| ID| Error Message                           |
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**Example**
471
472```ts
473import { BusinessError } from '@kit.BasicServicesKit';
474
475// getSlot callback
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
491Obtains a notification slot of a specified type. This API uses a promise to return the URI of the file in the destination directory.
492
493**System capability**: SystemCapability.Notification.Notification
494
495**Parameters**
496
497| Name    | Type    | Mandatory| Description                                                       |
498| -------- | -------- | ---- | ----------------------------------------------------------- |
499| slotType | [SlotType](#slottype) | Yes  | Type of a notification slot, including social communication, service notification, and content consultation.|
500
501**Return value**
502
503| Type                                                       | Description                                                        |
504| ----------------------------------------------------------- | ------------------------------------------------------------ |
505| Promise\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | Promise used to return the result.|
506
507**Error codes**
508
509For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
510
511| ID| Error Message                           |
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**Example**
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
535Obtains all notification slots of this application. This API uses an asynchronous callback to return the result.
536
537**System capability**: SystemCapability.Notification.Notification
538
539**Parameters**
540
541| Name    | Type                             | Mandatory| Description                |
542| -------- | --------------------------------- | ---- | -------------------- |
543| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Yes  | Callback used to return all notification slots of the current application.|
544
545**Error codes**
546
547For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
548
549
550| ID| Error Message                           |
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**Example**
558
559```ts
560import { BusinessError } from '@kit.BasicServicesKit';
561
562// getSlots callback
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
577Obtains all notification slots of this application. This API uses a promise to return the URI of the file in the destination directory.
578
579**System capability**: SystemCapability.Notification.Notification
580
581**Return value**
582
583| Type                                                       | Description                                                        |
584| ----------------------------------------------------------- | ------------------------------------------------------------ |
585| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | Promise used to return all notification slots of the current application.|
586
587**Error codes**
588
589For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
590
591| ID| Error Message                           |
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**Example**
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
614Removes a notification slot of a specified type for this application. This API uses an asynchronous callback to return the result.
615
616**System capability**: SystemCapability.Notification.Notification
617
618**Parameters**
619
620| Name    | Type                 | Mandatory| Description                                                       |
621| -------- | --------------------- | ---- | ----------------------------------------------------------- |
622| slotType | [SlotType](#slottype)              | Yes  | Type of a notification slot, including social communication, service notification, and content consultation.|
623| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                                       |
624
625**Error codes**
626
627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
628
629| ID| Error Message                           |
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**Example**
637
638```ts
639import { BusinessError } from '@kit.BasicServicesKit';
640
641// removeSlot callback
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
657Removes a notification slot of a specified type for this application. This API uses a promise to return the URI of the file in the destination directory.
658
659**System capability**: SystemCapability.Notification.Notification
660
661**Parameters**
662
663| Name    | Type    | Mandatory| Description                                                       |
664| -------- | -------- | ---- | ----------------------------------------------------------- |
665| slotType | [SlotType](#slottype) | Yes  | Type of a notification slot, including social communication, service notification, and content consultation.|
666
667**Return value**
668
669| Type     | Description       |
670|---------|-----------|
671| Promise\<void\> | Promise that returns no value.|
672
673**Error codes**
674
675For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
676
677| ID| Error Message                           |
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**Example**
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
701Removes all notification slots for this application. This API uses an asynchronous callback to return the result.
702
703**System capability**: SystemCapability.Notification.Notification
704
705**Parameters**
706
707| Name    | Type                 | Mandatory| Description                |
708| -------- | --------------------- | ---- | -------------------- |
709| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
710
711**Error codes**
712
713For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
714
715| ID| Error Message                           |
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**Example**
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
741Removes all notification slots for this application. This API uses a promise to return the URI of the file in the destination directory.
742
743**System capability**: SystemCapability.Notification.Notification
744
745**Return value**
746
747| Type     | Description       |
748|---------|-----------|
749| Promise\<void\> | Promise that returns no value.|
750
751**Error codes**
752
753For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
754
755| ID| Error Message                           |
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**Example**
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
778Checks whether notification is enabled for the specified application. This API uses an asynchronous callback to return the result.
779
780**System capability**: SystemCapability.Notification.Notification
781
782**Parameters**
783
784| Name    | Type                 | Mandatory| Description                    |
785| -------- | --------------------- | ---- | ------------------------ |
786| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.|
787
788**Error codes**
789
790For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
791
792| ID| Error Message                                 |
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**Example**
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
821Checks whether notification is enabled for the specified application. This API uses a promise to return the URI of the file in the destination directory.
822
823**System capability**: SystemCapability.Notification.Notification
824
825**Return value**
826
827| Type                                                       | Description                                                        |
828| ----------------------------------------------------------- | ------------------------------------------------------------ |
829| Promise\<boolean\> | Promise used to return the result. The value **true** means that the notification is enabled, and **false** means the opposite.|
830
831**Error codes**
832
833For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
834
835| ID| Error Message                                |
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**Example**
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
860Synchronously checks whether notification is enabled for the specified application.
861
862**System capability**: SystemCapability.Notification.Notification
863
864**Return value**
865
866| Type                                                       | Description                                                    |
867| ----------------------------------------------------------- |--------------------------------------------------------- |
868| boolean | Returned result. **true**: enabled; **false**: returned.|
869
870**Error codes**
871
872For details about the error codes, see [Notification Error Codes](./errorcode-notification.md).
873
874| ID| Error Message                                |
875| -------- | ---------------------------------------- |
876| 1600001  | Internal error.                          |
877| 1600002  | Marshalling or unmarshalling error.      |
878| 1600003  | Failed to connect to the service.               |
879
880**Example**
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
891Sets the notification badge number. This API uses a promise to return the URI of the file in the destination directory.
892
893If the **badgeNumber** is set to **0**, badges are cleared; if the value is greater than **99**, **99+** is displayed on the badge.
894
895**System capability**: SystemCapability.Notification.Notification
896
897**Parameters**
898
899| Name     | Type  | Mandatory| Description      |
900| ----------- | ------ | ---- | ---------- |
901| badgeNumber | number | Yes  | Notification badge number to set.|
902
903**Return value**
904
905| Type     | Description       |
906|---------|-----------|
907| Promise\<void\> | Promise that returns no value.|
908
909**Error codes**
910
911For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
912
913| ID| Error Message                           |
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**Example**
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
938Sets the notification badge number. This API uses an asynchronous callback to return the result.
939
940If the **badgeNumber** is set to **0**, badges are cleared; if the value is greater than **99**, **99+** is displayed on the badge.
941
942**System capability**: SystemCapability.Notification.Notification
943
944**Parameters**
945
946| Name     | Type                 | Mandatory| Description              |
947| ----------- | --------------------- | ---- | ------------------ |
948| badgeNumber | number                | Yes  | Notification badge number to set.        |
949| callback    | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
950
951**Error codes**
952
953For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
954
955| ID| Error Message                           |
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**Example**
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
983Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.
984
985**System capability**: SystemCapability.Notification.Notification
986
987**Parameters**
988
989| Name    | Type                  | Mandatory| Description                  |
990| -------- | ---------------------- | ---- | ---------------------- |
991| callback | AsyncCallback\<number\> | Yes  | Callback used to return the result.|
992
993**Error codes**
994
995For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
996
997| ID| Error Message                           |
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**Example**
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
1024Obtains the number of active notifications of this application. This API uses a promise to return the URI of the file in the destination directory.
1025
1026**System capability**: SystemCapability.Notification.Notification
1027
1028**Return value**
1029
1030| Type             | Description                                       |
1031| ----------------- | ------------------------------------------- |
1032| Promise\<number\> | Promise used to return the result.|
1033
1034**Error codes**
1035
1036For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1037
1038| ID| Error Message                           |
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**Example**
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
1061Obtains the active notifications of this application. This API uses an asynchronous callback to return the result.
1062
1063**System capability**: SystemCapability.Notification.Notification
1064
1065**Parameters**
1066
1067| Name    | Type                                                        | Mandatory| Description                          |
1068| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
1069| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | Yes  | Callback used to return the result.|
1070
1071**Error codes**
1072
1073For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1074
1075| ID| Error Message                           |
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**Example**
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
1101Obtains the active notifications of this application. This API uses a promise to return the URI of the file in the destination directory.
1102
1103**System capability**: SystemCapability.Notification.Notification
1104
1105**Return value**
1106
1107| Type                                                        | Description                                   |
1108| ------------------------------------------------------------ | --------------------------------------- |
1109| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | Promise used to return the result.|
1110
1111**Error codes**
1112
1113For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1114
1115| ID| Error Message                           |
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**Example**
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
1138Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.
1139
1140**System capability**: SystemCapability.Notification.Notification
1141
1142**Parameters**
1143
1144| Name     | Type                 | Mandatory| Description                        |
1145| --------- | --------------------- | ---- | ---------------------------- |
1146| groupName | string                | Yes  | Name of the notification group, which is specified through [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) when the notification is published.|
1147| callback  | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
1148
1149**Error codes**
1150
1151For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1152
1153| ID| Error Message                           |
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**Example**
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
1180Cancels notifications under a notification group of this application. This API uses a promise to return the URI of the file in the destination directory.
1181
1182**System capability**: SystemCapability.Notification.Notification
1183
1184**Parameters**
1185
1186| Name     | Type  | Mandatory| Description          |
1187| --------- | ------ | ---- | -------------- |
1188| groupName | string | Yes  | Name of the notification group, which is specified through [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) when the notification is published.|
1189
1190**Return value**
1191
1192| Type     | Description       |
1193|---------|-----------|
1194| Promise\<void\> | Promise that returns no value.|
1195
1196**Error codes**
1197
1198For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1199
1200| ID| Error Message                           |
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**Example**
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
1224Checks whether a specified template is supported. This API uses an asynchronous callback to return the result.
1225
1226**System capability**: SystemCapability.Notification.Notification
1227
1228**Parameters**
1229
1230| Name      | Type                    | Mandatory| Description                      |
1231| ------------ | ------------------------ | ---- | -------------------------- |
1232| templateName | string                   | Yes  | Template name. Currently, only **downloadTemplate** is supported.                  |
1233| callback     | AsyncCallback\<boolean\> | Yes  | Callback used to return the result. The value **true** means that the specified template is supported, and **false** means the opposite.|
1234
1235**Error codes**
1236
1237For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1238
1239| ID| Error Message                           |
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**Example**
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
1266Checks whether a specified template is supported. This API uses a promise to return the URI of the file in the destination directory.
1267
1268**System capability**: SystemCapability.Notification.Notification
1269
1270**Parameters**
1271
1272| Name      | Type  | Mandatory| Description    |
1273| ------------ | ------ | ---- | -------- |
1274| templateName | string | Yes  | Template name. Currently, only **downloadTemplate** is supported.|
1275
1276**Return value**
1277
1278| Type              | Description           |
1279| ------------------ | --------------- |
1280| Promise\<boolean\> | Promise used to return the result. The value **true** means that the specified template is supported, and **false** means the opposite.|
1281
1282**Error codes**
1283
1284For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1285
1286| ID| Error Message                           |
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**Example**
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
1310Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
1311
1312> **NOTE**
1313>
1314> This API is deprecated since API version 12. You are advised to use [requestEnableNotification](#notificationmanagerrequestenablenotification10) with **context** input parameters instead.
1315
1316**System capability**: SystemCapability.Notification.Notification
1317
1318**Parameters**
1319
1320| Name  | Type                    | Mandatory| Description                      |
1321| -------- | ------------------------ | ---- | -------------------------- |
1322| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
1323
1324**Error codes**
1325
1326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1327
1328| ID| Error Message                           |
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**Example**
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
1356Requests notification to be enabled for this application. This API uses a promise to return the URI of the file in the destination directory.
1357
1358> **NOTE**
1359>
1360> This API is deprecated since API version 12. You are advised to use [requestEnableNotification](#notificationmanagerrequestenablenotification10-1) with **context** input parameters instead.
1361
1362**System capability**: SystemCapability.Notification.Notification
1363
1364**Return value**
1365
1366| Type     | Description       |
1367|---------|-----------|
1368| Promise\<void\> | Promise that returns no value.|
1369
1370**Error codes**
1371
1372For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1373
1374| ID| Error Message                           |
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**Example**
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
1399Requests notification to be enabled for this application in a modal. This API uses an asynchronous callback to return the result.
1400
1401This API can be called only after the application UI is loaded (that is, [loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent) is successfully called).
1402
1403**Model restriction**: This API can be used only in the stage model.
1404
1405**System capability**: SystemCapability.Notification.Notification
1406
1407**Parameters**
1408
1409| Name  | Type                    | Mandatory| Description                |
1410| -------- | ------------------------ | ---- |--------------------|
1411| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes  | Ability context bound to the notification dialog box.|
1412| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.    |
1413
1414**Error codes**
1415
1416For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1417
1418| ID| Error Message                           |
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**Example**
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
1461Requests notification to be enabled for this application in a modal. This API uses a promise to return the URI of the file in the destination directory.
1462
1463This API can be called only after the application UI is loaded (that is, [loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent) is successfully called).
1464
1465**Model restriction**: This API can be used only in the stage model.
1466
1467**System capability**: SystemCapability.Notification.Notification
1468
1469**Parameters**
1470
1471| Name  | Type                    | Mandatory| Description                |
1472| -------- | ------------------------ | ---- |--------------------|
1473| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes  | Ability context bound to the notification dialog box.|
1474
1475**Return value**
1476
1477| Type     | Description       |
1478|---------|-----------|
1479| Promise\<void\> | Promise that returns no value.|
1480
1481**Error codes**
1482
1483For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1484
1485| ID| Error Message                           |
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**Example**
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
1525Checks whether distributed notification is enabled on this device. This API uses an asynchronous callback to return the result.
1526
1527**System capability**: SystemCapability.Notification.Notification
1528
1529**Parameters**
1530
1531| Name  | Type                    | Mandatory| Description                      |
1532| -------- | ------------------------ | ---- | -------------------------- |
1533| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result. The value **true** means that distributed notification is enabled, and **false** means the opposite.|
1534
1535**Error codes**
1536
1537For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1538
1539| ID| Error Message                           |
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**Example**
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
1566Checks whether distributed notification is enabled on this device. This API uses a promise to return the URI of the file in the destination directory.
1567
1568**System capability**: SystemCapability.Notification.Notification
1569
1570**Return value**
1571
1572| Type              | Description                                         |
1573| ------------------ | --------------------------------------------- |
1574| Promise\<boolean\> | Promise used to return the result. The value **true** means that distributed notification is enabled, and **false** means the opposite.|
1575
1576**Error codes**
1577
1578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1579
1580| ID| Error Message                           |
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**Example**
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
1604Opens the notification settings page of the application, which is displayed in semi-modal mode and can be used to set the notification enabling and notification mode. This API uses a promise to return the URI of the file in the destination directory.
1605
1606**Model restriction**: This API can be used only in the stage model.
1607
1608**System capability**: SystemCapability.Notification.NotificationSettings
1609
1610**Parameters**
1611
1612| Name  | Type                    | Mandatory| Description                |
1613| -------- | ------------------------ | ---- |--------------------|
1614| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes  | Ability context bound to the notification settings page.|
1615
1616**Return value**
1617
1618| Type     | Description       |
1619|---------|-----------|
1620| Promise\<void\> | Promise that returns no value.|
1621
1622**Error codes**
1623
1624For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md).
1625
1626| ID| Error Message                           |
1627| -------- | ----------------------------------- |
1628| 1600001  | Internal error.                     |
1629| 1600003  | Failed to connect to the service.          |
1630| 1600018  | the notification settings window is already displayed.           |
1631
1632**Example**
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
1661Enumerates the notification content types.
1662
1663**Atomic service API**: This API can be used in atomic services since API version 12.
1664
1665**System capability**: SystemCapability.Notification.Notification
1666
1667| Name                             | Value         | Description              |
1668| --------------------------------- | ----------- |------------------|
1669| NOTIFICATION_CONTENT_BASIC_TEXT   | 0          | Normal text notification.         |
1670| NOTIFICATION_CONTENT_LONG_TEXT    | 1          | Long text notification.        |
1671| NOTIFICATION_CONTENT_PICTURE      | 2          | Picture-attached notification.         |
1672| NOTIFICATION_CONTENT_CONVERSATION | 3          | Conversation notification. Not supported currently.|
1673| NOTIFICATION_CONTENT_MULTILINE    | 4          | Multi-line text notification.       |
1674| NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW<sup>11+</sup>    | 5 | Live view notification. A third-party application cannot directly create a notification of this type. After the system proxy creates a system live view, the third-party application releases a notification with the same ID to update the specified content.|
1675| NOTIFICATION_CONTENT_LIVE_VIEW<sup>11+</sup>    | 6 | Common live view notification. Only system applications are supported. |
1676
1677## SlotLevel
1678
1679Enumerates the notification level.
1680
1681**System capability**: SystemCapability.Notification.Notification
1682
1683| Name                             | Value         | Description              |
1684| --------------------------------- | ----------- | ------------------ |
1685| LEVEL_NONE                        | 0           | Notification is disabled.    |
1686| LEVEL_MIN                         | 1           | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.|
1687| LEVEL_LOW                         | 2           | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.|
1688| LEVEL_DEFAULT                     | 3           | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.|
1689| LEVEL_HIGH                        | 4           | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.|
1690
1691
1692## SlotType
1693
1694Enumerates the notification slot types.
1695
1696**Atomic service API**: This API can be used in atomic services since API version 12.
1697
1698**System capability**: SystemCapability.Notification.Notification
1699
1700| Name                | Value      | Description      |
1701| -------------------- | -------- | ---------- |
1702| UNKNOWN_TYPE         | 0 | Unknown type. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_MIN**.|
1703| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_HIGH**.|
1704| SERVICE_INFORMATION  | 2 | Notification slot for service information. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_HIGH**.|
1705| CONTENT_INFORMATION  | 3 | Notification slot for content consultation. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_MIN**.|
1706| LIVE_VIEW<sup>11+</sup>            | 4 | Live view. A third-party application cannot directly create a notification of this slot type. After the system proxy creates a system live view, the third-party application releases a notification with the same ID to update the specified content. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_DEFAULT**.|
1707| CUSTOMER_SERVICE<sup>11+</sup>     | 5 | Customer service message. This type is used for messages between users and customer service providers. The messages must be initiated by users. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_DEFAULT**. |
1708| OTHER_TYPES          | 0xFFFF | Notification slot for other purposes. This type corresponds to [SlotLevel](#slotlevel) being **LEVEL_MIN**.|
1709