1# @ohos.notification (Notification)
2
3The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status.
4
5> **NOTE**
6>
7> The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.notificationManager](js-apis-notificationManager.md).
8> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9>
10> Notification subscription and unsubscription APIs are available only to system applications.
11
12## Modules to Import
13
14```ts
15import Notification from '@ohos.notification';
16```
17
18## Notification.publish
19
20publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
21
22Publishes a notification. This API uses an asynchronous callback to return the result.
23
24**System capability**: SystemCapability.Notification.Notification
25
26**Parameters**
27
28| Name    | Type                                       | Mandatory | Description                                       |
29| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
30| request  | [NotificationRequest](#notificationrequest) | Yes  | Content and related configuration of the notification to publish. |
31| callback | AsyncCallback\<void\>                       | Yes  | Callback used to return the result.                       |
32
33**Example**
34
35```ts
36import NotificationManager from '@ohos.notificationManager';
37import Base from '@ohos.base';
38
39// publish callback
40let publishCallback = (err: Base.BusinessError) => {
41  if (err) {
42    console.error(`publish failed, code is ${err}`);
43  } else {
44    console.info("publish success");
45  }
46}
47// NotificationRequest object
48let notificationRequest: NotificationManager.NotificationRequest = {
49  id: 1,
50  content: {
51    contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
52    normal: {
53      title: "test_title",
54      text: "test_text",
55      additionalText: "test_additionalText"
56    }
57  }
58};
59Notification.publish(notificationRequest, publishCallback);
60```
61
62## Notification.publish
63
64publish(request: NotificationRequest): Promise\<void\>
65
66Publishes a notification. This API uses a promise to return the result.
67
68**System capability**: SystemCapability.Notification.Notification
69
70**Parameters**
71
72| Name    | Type                                       | Mandatory | Description                                       |
73| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
74| request  | [NotificationRequest](#notificationrequest) | Yes  | Content and related configuration of the notification to publish. |
75
76**Return value**
77
78| Type    | Description        |
79| ------- |------------|
80| Promise\<void\> | Promise that returns no value. |
81
82**Example**
83
84```ts
85import NotificationManager from '@ohos.notificationManager';
86import Base from '@ohos.base';
87
88// NotificationRequest object
89let notificationRequest: NotificationManager.NotificationRequest = {
90  id: 1,
91  content: {
92    contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
93    normal: {
94      title: "test_title",
95      text: "test_text",
96      additionalText: "test_additionalText"
97    }
98  }
99};
100Notification.publish(notificationRequest).then(() => {
101  console.info("publish success");
102}).catch((err: Base.BusinessError) => {
103  console.error(`publish failed, code is ${err}`);
104});
105```
106
107## Notification.cancel
108
109cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
110
111Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result.
112
113**System capability**: SystemCapability.Notification.Notification
114
115**Parameters**
116
117| Name    | Type                 | Mandatory | Description                |
118| -------- | --------------------- | ---- | -------------------- |
119| id       | number                | Yes  | Notification ID.              |
120| label    | string                | Yes  | Notification label.            |
121| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
122
123**Example**
124
125```ts
126import Base from '@ohos.base';
127
128// cancel callback
129let cancelCallback = (err: Base.BusinessError) => {
130  if (err) {
131    console.info("cancel failed " + JSON.stringify(err));
132  } else {
133    console.info("cancel success");
134  }
135}
136Notification.cancel(0, "label", cancelCallback);
137```
138
139
140
141## Notification.cancel
142
143cancel(id: number, label?: string): Promise\<void\>
144
145Cancels a notification with the specified ID and optional label. This API uses a promise to return the result.
146
147**System capability**: SystemCapability.Notification.Notification
148
149**Parameters**
150
151| Name | Type  | Mandatory | Description    |
152| ----- | ------ | ---- | -------- |
153| id    | number | Yes  | Notification ID.  |
154| label | string | No  | Notification label. This parameter is left empty by default. |
155
156**Return value**
157
158| Type    | Description        |
159| ------- |------------|
160| Promise\<void\> | Promise that returns no value. |
161
162**Example**
163
164```ts
165import Base from '@ohos.base';
166
167Notification.cancel(0).then(() => {
168	console.info("cancel success");
169}).catch((err: Base.BusinessError) => {
170  console.error(`cancel failed, code is ${err}`);
171});
172```
173
174
175
176## Notification.cancel
177
178cancel(id: number, callback: AsyncCallback\<void\>): void
179
180Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result.
181
182**System capability**: SystemCapability.Notification.Notification
183
184**Parameters**
185
186| Name    | Type                 | Mandatory | Description                |
187| -------- | --------------------- | ---- | -------------------- |
188| id       | number                | Yes  | Notification ID.              |
189| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
190
191**Example**
192
193```ts
194import Base from '@ohos.base';
195
196// cancel callback
197let cancelCallback = (err: Base.BusinessError) => {
198  if (err) {
199    console.info("cancel failed " + JSON.stringify(err));
200  } else {
201    console.info("cancel success");
202  }
203}
204Notification.cancel(0, cancelCallback);
205```
206
207
208
209## Notification.cancelAll
210
211cancelAll(callback: AsyncCallback\<void\>): void
212
213Cancels all notifications. This API uses an asynchronous callback to return the result.
214
215**System capability**: SystemCapability.Notification.Notification
216
217**Parameters**
218
219| Name    | Type                 | Mandatory | Description                |
220| -------- | --------------------- | ---- | -------------------- |
221| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
222
223**Example**
224
225```ts
226import Base from '@ohos.base';
227
228// cancel callback
229let cancelAllCallback = (err: Base.BusinessError) => {
230  if (err) {
231    console.info("cancelAll failed " + JSON.stringify(err));
232  } else {
233    console.info("cancelAll success");
234  }
235}
236Notification.cancelAll(cancelAllCallback);
237```
238
239## Notification.cancelAll
240
241cancelAll(): Promise\<void\>
242
243Cancels all notifications. This API uses a promise to return the result.
244
245**System capability**: SystemCapability.Notification.Notification
246
247**Return value**
248
249| Type    | Description        |
250| ------- |------------|
251| Promise\<void\> | Promise that returns no value. |
252
253**Example**
254
255```ts
256import Base from '@ohos.base';
257
258Notification.cancelAll().then(() => {
259	console.info("cancelAll success");
260}).catch((err: Base.BusinessError) => {
261  console.error(`cancelAll failed, code is ${err}`);
262});
263```
264
265## Notification.addSlot
266
267addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
268
269Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.
270
271**System capability**: SystemCapability.Notification.Notification
272
273**Parameters**
274
275| Name    | Type                 | Mandatory | Description                  |
276| -------- | --------------------- | ---- | ---------------------- |
277| type     | [SlotType](#slottype)              | Yes  | Type of the notification slot to add. |
278| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.  |
279
280**Example**
281
282```ts
283import Base from '@ohos.base';
284
285// addSlot callback
286let addSlotCallBack = (err: Base.BusinessError) => {
287  if (err) {
288    console.info("addSlot failed " + JSON.stringify(err));
289  } else {
290    console.info("addSlot success");
291  }
292}
293Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
294```
295
296## Notification.addSlot
297
298addSlot(type: SlotType): Promise\<void\>
299
300Adds a notification slot of a specified type. This API uses a promise to return the result.
301
302**System capability**: SystemCapability.Notification.Notification
303
304**Parameters**
305
306| Name | Type    | Mandatory | Description                  |
307| ---- | -------- | ---- | ---------------------- |
308| type | [SlotType](#slottype) | Yes  | Type of the notification slot to add. |
309
310**Return value**
311
312| Type    | Description        |
313| ------- |------------|
314| Promise\<void\> | Promise that returns no value. |
315
316**Example**
317
318```ts
319import Base from '@ohos.base';
320
321Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
322  console.info("addSlot success");
323}).catch((err: Base.BusinessError) => {
324  console.error(`addSlot failed, code is ${err}`);
325});
326```
327
328## Notification.getSlot
329
330getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
331
332Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result.
333
334**System capability**: SystemCapability.Notification.Notification
335
336**Parameters**
337
338| Name    | Type                             | Mandatory | Description                                                       |
339| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
340| slotType | [SlotType](#slottype)                          | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes. |
341| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes  | Callback used to return the result.                                       |
342
343**Example**
344
345```ts
346import Base from '@ohos.base';
347
348// getSlot callback
349let getSlotCallback = (err: Base.BusinessError) => {
350  if (err) {
351    console.info("getSlot failed " + JSON.stringify(err));
352  } else {
353    console.info("getSlot success");
354  }
355}
356let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
357Notification.getSlot(slotType, getSlotCallback);
358```
359
360## Notification.getSlot
361
362getSlot(slotType: SlotType): Promise\<NotificationSlot\>
363
364Obtains a notification slot of a specified type. This API uses a promise to return the result.
365
366**System capability**: SystemCapability.Notification.Notification
367
368**Parameters**
369
370| Name    | Type    | Mandatory | Description                                                       |
371| -------- | -------- | ---- | ----------------------------------------------------------- |
372| slotType | [SlotType](#slottype) | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes. |
373
374**Return value**
375
376| Type                                                       | Description                                                        |
377| ----------------------------------------------------------- | ------------------------------------------------------------ |
378| Promise\<NotificationSlot\> | Promise used to return the result. |
379
380**Example**
381
382```ts
383import Base from '@ohos.base';
384
385let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
386Notification.getSlot(slotType).then((data) => {
387  console.info("getSlot success, data: " + JSON.stringify(data));
388}).catch((err: Base.BusinessError) => {
389  console.error(`getSlot failed, code is ${err}`);
390});
391```
392
393## Notification.getSlots
394
395getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void
396
397Obtains all notification slots. This API uses an asynchronous callback to return the result.
398
399**System capability**: SystemCapability.Notification.Notification
400
401**Parameters**
402
403| Name    | Type                             | Mandatory | Description                |
404| -------- | --------------------------------- | ---- | -------------------- |
405| callback | AsyncCallback\<Array\<[NotificationSlot](#notificationslot)>> | Yes  | Callback used to return the result. |
406
407**Example**
408
409```ts
410import Base from '@ohos.base';
411
412// getSlots callback
413function getSlotsCallback(err: Base.BusinessError) {
414  if (err) {
415    console.info("getSlots failed " + JSON.stringify(err));
416  } else {
417    console.info("getSlots success");
418  }
419}
420Notification.getSlots(getSlotsCallback);
421```
422
423## Notification.getSlots
424
425getSlots(): Promise\<Array\<NotificationSlot\>>
426
427Obtains all notification slots of this application. This API uses a promise to return the result.
428
429**System capability**: SystemCapability.Notification.Notification
430
431**Return value**
432
433| Type                                                       | Description                                                        |
434| ----------------------------------------------------------- | ------------------------------------------------------------ |
435| Promise\<Array\<[NotificationSlot](#notificationslot)\>\> | Promise used to return the result. |
436
437**Example**
438
439```ts
440import Base from '@ohos.base';
441
442Notification.getSlots().then((data) => {
443  console.info("getSlots success, data: " + JSON.stringify(data));
444}).catch((err: Base.BusinessError) => {
445  console.error(`getSlots failed, code is ${err}`);
446});
447```
448
449## Notification.removeSlot
450
451removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
452
453Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.
454
455**System capability**: SystemCapability.Notification.Notification
456
457**Parameters**
458
459| Name    | Type                 | Mandatory | Description                                                       |
460| -------- | --------------------- | ---- | ----------------------------------------------------------- |
461| slotType | [SlotType](#slottype)              | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes. |
462| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                                       |
463
464**Example**
465
466```ts
467import Base from '@ohos.base';
468
469// removeSlot callback
470let removeSlotCallback = (err: Base.BusinessError) => {
471  if (err) {
472    console.info("removeSlot failed " + JSON.stringify(err));
473  } else {
474    console.info("removeSlot success");
475  }
476}
477let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
478Notification.removeSlot(slotType, removeSlotCallback);
479```
480
481## Notification.removeSlot
482
483removeSlot(slotType: SlotType): Promise\<void\>
484
485Removes a notification slot of a specified type. This API uses a promise to return the result.
486
487**System capability**: SystemCapability.Notification.Notification
488
489**Parameters**
490
491| Name    | Type    | Mandatory | Description                                                       |
492| -------- | -------- | ---- | ----------------------------------------------------------- |
493| slotType | [SlotType](#slottype) | Yes  | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes. |
494
495**Return value**
496
497| Type    | Description        |
498| ------- |------------|
499| Promise\<void\> | Promise that returns no value. |
500
501**Example**
502
503```ts
504import Base from '@ohos.base';
505
506let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
507Notification.removeSlot(slotType).then(() => {
508  console.info("removeSlot success");
509}).catch((err: Base.BusinessError) => {
510  console.error(`removeSlot failed, code is ${err}`);
511});
512```
513
514## Notification.removeAllSlots
515
516removeAllSlots(callback: AsyncCallback\<void\>): void
517
518Removes all notification slots. This API uses an asynchronous callback to return the result.
519
520**System capability**: SystemCapability.Notification.Notification
521
522**Parameters**
523
524| Name    | Type                 | Mandatory | Description                |
525| -------- | --------------------- | ---- | -------------------- |
526| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
527
528**Example**
529
530```ts
531import Base from '@ohos.base';
532
533let removeAllCallBack = (err: Base.BusinessError) => {
534  if (err) {
535    console.info("removeAllSlots failed " + JSON.stringify(err));
536  } else {
537    console.info("removeAllSlots success");
538  }
539}
540Notification.removeAllSlots(removeAllCallBack);
541```
542
543## Notification.removeAllSlots
544
545removeAllSlots(): Promise\<void\>
546
547Removes all notification slots. This API uses a promise to return the result.
548
549**System capability**: SystemCapability.Notification.Notification
550
551**Return value**
552
553| Type    | Description        |
554| ------- |------------|
555| Promise\<void\> | Promise that returns no value. |
556
557**Example**
558
559```ts
560import Base from '@ohos.base';
561
562Notification.removeAllSlots().then(() => {
563  console.info("removeAllSlots success");
564}).catch((err: Base.BusinessError) => {
565  console.error(`removeAllSlots failed, code is ${err}`);
566});
567```
568
569## Notification.getActiveNotificationCount
570
571getActiveNotificationCount(callback: AsyncCallback\<number\>): void
572
573Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.
574
575**System capability**: SystemCapability.Notification.Notification
576
577**Parameters**
578
579| Name    | Type                  | Mandatory | Description                  |
580| -------- | ---------------------- | ---- | ---------------------- |
581| callback | AsyncCallback\<number\> | Yes  | Callback used to return the result. |
582
583**Example**
584
585```ts
586import Base from '@ohos.base';
587
588let getActiveNotificationCountCallback = (err: Base.BusinessError, data: number) => {
589  if (err) {
590    console.info("getActiveNotificationCount failed " + JSON.stringify(err));
591  } else {
592    console.info("getActiveNotificationCount success");
593  }
594}
595
596Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
597```
598
599## Notification.getActiveNotificationCount
600
601getActiveNotificationCount(): Promise\<number\>
602
603Obtains the number of active notifications of this application. This API uses a promise to return the result.
604
605**System capability**: SystemCapability.Notification.Notification
606
607**Return value**
608
609| Type             | Description                                       |
610| ----------------- | ------------------------------------------- |
611| Promise\<number\> | Promise used to return the result. |
612
613**Example**
614
615```ts
616import Base from '@ohos.base';
617
618Notification.getActiveNotificationCount().then((data: number) => {
619  console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
620}).catch((err: Base.BusinessError) => {
621  console.error(`getAllActiveNotifications failed, code is ${err}`);
622});
623```
624
625## Notification.getActiveNotifications
626
627getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
628
629Obtains active notifications of this application. This API uses an asynchronous callback to return the result.
630
631**System capability**: SystemCapability.Notification.Notification
632
633**Parameters**
634
635| Name    | Type                                                        | Mandatory | Description                          |
636| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
637| callback | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | Yes  | Callback used to return the result. |
638
639**Example**
640
641```ts
642import Base from '@ohos.base';
643import NotificationManager from '@ohos.notificationManager';
644
645let getActiveNotificationsCallback = (err: Base.BusinessError, data: NotificationManager.NotificationRequest[]) => {
646  if (err) {
647    console.info("getActiveNotifications failed " + JSON.stringify(err));
648  } else {
649    console.info("getActiveNotifications success");
650  }
651}
652
653Notification.getActiveNotifications(getActiveNotificationsCallback);
654```
655
656## Notification.getActiveNotifications
657
658getActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationrequest)\>\>
659
660Obtains active notifications of this application. This API uses a promise to return the result.
661
662**System capability**: SystemCapability.Notification.Notification
663
664**Return value**
665
666| Type                                                        | Description                                   |
667| ------------------------------------------------------------ | --------------------------------------- |
668| Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result. |
669
670**Example**
671
672```ts
673import Base from '@ohos.base';
674import NotificationManager from '@ohos.notificationManager';
675
676Notification.getActiveNotifications().then((data: NotificationManager.NotificationRequest[]) => {
677  console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
678}).catch((err: Base.BusinessError) => {
679  console.error(`removeGroupByBundle failed, code is ${err}`);
680});
681```
682
683## Notification.cancelGroup<sup>8+</sup>
684
685cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
686
687Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.
688
689**System capability**: SystemCapability.Notification.Notification
690
691**Parameters**
692
693| Name     | Type                 | Mandatory | Description                        |
694| --------- | --------------------- | ---- | ---------------------------- |
695| groupName | string                | Yes  | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published. |
696| callback  | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
697
698**Example**
699
700```ts
701import Base from '@ohos.base';
702
703let cancelGroupCallback = (err: Base.BusinessError) => {
704  if (err) {
705    console.info("cancelGroup failed " + JSON.stringify(err));
706  } else {
707    console.info("cancelGroup success");
708  }
709}
710
711let groupName: string = "GroupName";
712
713Notification.cancelGroup(groupName, cancelGroupCallback);
714```
715
716## Notification.cancelGroup<sup>8+</sup>
717
718cancelGroup(groupName: string): Promise\<void\>
719
720Cancels notifications under a notification group of this application. This API uses a promise to return the result.
721
722**System capability**: SystemCapability.Notification.Notification
723
724**Parameters**
725
726| Name     | Type  | Mandatory | Description          |
727| --------- | ------ | ---- | -------------- |
728| groupName | string | Yes  | Name of the notification group. |
729
730**Return value**
731
732| Type    | Description        |
733| ------- |------------|
734| Promise\<void\> | Promise that returns no value. |
735
736**Example**
737
738```ts
739import Base from '@ohos.base';
740
741let groupName: string = "GroupName";
742Notification.cancelGroup(groupName).then(() => {
743	console.info("cancelGroup success");
744}).catch((err: Base.BusinessError) => {
745  console.error(`cancelGroup failed, code is ${err}`);
746});
747```
748
749## Notification.isSupportTemplate<sup>8+</sup>
750
751isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void
752
753Checks whether a specified template exists. This API uses an asynchronous callback to return the result.
754
755**System capability**: SystemCapability.Notification.Notification
756
757**Parameters**
758
759| Name      | Type                    | Mandatory | Description                      |
760| ------------ | ------------------------ | ---- | -------------------------- |
761| templateName | string                   | Yes  | Template name.                  |
762| callback     | AsyncCallback\<boolean\> | Yes  | Callback used to return the result. |
763
764**Example**
765
766```ts
767import Base from '@ohos.base';
768
769let templateName: string = 'process';
770function isSupportTemplateCallback(err: Base.BusinessError, data: boolean) {
771  if (err) {
772    console.info("isSupportTemplate failed " + JSON.stringify(err));
773  } else {
774    console.info("isSupportTemplate success");
775  }
776}
777
778Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
779```
780
781## Notification.isSupportTemplate<sup>8+</sup>
782
783isSupportTemplate(templateName: string): Promise\<boolean\>
784
785Checks whether a specified template exists. This API uses a promise to return the result.
786
787**System capability**: SystemCapability.Notification.Notification
788
789**Parameters**
790
791| Name      | Type  | Mandatory | Description    |
792| ------------ | ------ | ---- | -------- |
793| templateName | string | Yes  | Template name. |
794
795**Return value**
796
797| Type              | Description           |
798| ------------------ | --------------- |
799| Promise\<boolean\> | Promise used to return the result. |
800
801**Example**
802
803```ts
804import Base from '@ohos.base';
805
806let templateName: string = 'process';
807Notification.isSupportTemplate(templateName).then((data: boolean) => {
808  console.info("isSupportTemplate success, data: " + JSON.stringify(data));
809}).catch((err: Base.BusinessError) => {
810  console.error(`isSupportTemplate failed, code is ${err}`);
811});
812```
813
814## Notification.requestEnableNotification<sup>8+</sup>
815
816requestEnableNotification(callback: AsyncCallback\<void\>): void
817
818Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
819
820**System capability**: SystemCapability.Notification.Notification
821
822**Parameters**
823
824| Name  | Type                    | Mandatory | Description                      |
825| -------- | ------------------------ | ---- | -------------------------- |
826| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. |
827
828**Example**
829
830```ts
831import Base from '@ohos.base';
832
833let requestEnableNotificationCallback = (err: Base.BusinessError) => {
834  if (err) {
835    console.info("requestEnableNotification failed " + JSON.stringify(err));
836  } else {
837    console.info("requestEnableNotification success");
838  }
839};
840
841Notification.requestEnableNotification(requestEnableNotificationCallback);
842```
843
844## Notification.requestEnableNotification<sup>8+</sup>
845
846requestEnableNotification(): Promise\<void\>
847
848Requests notification to be enabled for this application. This API uses a promise to return the result.
849
850**System capability**: SystemCapability.Notification.Notification
851
852**Return value**
853
854| Type    | Description        |
855| ------- |------------|
856| Promise\<void\> | Promise that returns no value. |
857
858**Example**
859
860```ts
861import Base from '@ohos.base';
862
863Notification.requestEnableNotification().then(() => {
864  console.info("requestEnableNotification success");
865}).catch((err: Base.BusinessError) => {
866  console.error(`requestEnableNotification failed, code is ${err}`);
867});
868```
869
870## Notification.isDistributedEnabled<sup>8+</sup>
871
872isDistributedEnabled(callback: AsyncCallback\<boolean>): void
873
874Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
875
876**System capability**: SystemCapability.Notification.Notification
877
878**Parameters**
879
880| Name  | Type                    | Mandatory | Description                      |
881| -------- | ------------------------ | ---- | -------------------------- |
882| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result. |
883
884**Example**
885
886```ts
887import Base from '@ohos.base';
888
889let isDistributedEnabledCallback = (err: Base.BusinessError, data: boolean) => {
890  if (err) {
891    console.info("isDistributedEnabled failed " + JSON.stringify(err));
892  } else {
893    console.info("isDistributedEnabled success " + JSON.stringify(data));
894  }
895};
896
897Notification.isDistributedEnabled(isDistributedEnabledCallback);
898```
899
900## Notification.isDistributedEnabled<sup>8+</sup>
901
902isDistributedEnabled(): Promise\<boolean>
903
904Checks whether this device supports distributed notifications. This API uses a promise to return the result.
905
906**System capability**: SystemCapability.Notification.Notification
907
908**Return value**
909
910| Type              | Description                                         |
911| ------------------ | --------------------------------------------- |
912| Promise\<boolean\> | Promise used to return the result. |
913
914**Example**
915
916```ts
917import Base from '@ohos.base';
918
919Notification.isDistributedEnabled().then((data: boolean) => {
920    console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
921}).catch((err: Base.BusinessError) => {
922  console.error(`isDistributedEnabled failed, code is ${err}`);
923});
924```
925
926## ContentType
927
928**System capability**: SystemCapability.Notification.Notification
929
930| Name                             | Value         | Description              |
931| --------------------------------- | ----------- | ------------------ |
932| NOTIFICATION_CONTENT_BASIC_TEXT   | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification.    |
933| NOTIFICATION_CONTENT_LONG_TEXT    | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification.  |
934| NOTIFICATION_CONTENT_PICTURE      | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification.    |
935| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification.    |
936| NOTIFICATION_CONTENT_MULTILINE    | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification. |
937
938## SlotLevel
939
940**System capability**: SystemCapability.Notification.Notification
941
942| Name                             | Value         | Description              |
943| --------------------------------- | ----------- | ------------------ |
944| LEVEL_NONE                        | 0           | The notification function is disabled.    |
945| LEVEL_MIN                         | 1           | The notification function is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone. |
946| LEVEL_LOW                         | 2           | The notification function is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone. |
947| LEVEL_DEFAULT                     | 3           | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner. |
948| LEVEL_HIGH                        | 4           | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner. |
949
950
951## BundleOption<sup>deprecated</sup>
952
953**System capability**: SystemCapability.Notification.Notification
954
955> **NOTE**
956> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [notificationManager.BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption).
957
958| Name  | Type  | Mandatory | Description  |
959| ------ | ------ | --- |  ------ |
960| bundle | string | Yes | Bundle information of the application. |
961| uid    | number | No | User ID. The default value is 0. |
962
963## NotificationKey<sup>deprecated</sup>
964
965**System capability**: SystemCapability.Notification.Notification
966
967> **NOTE**
968> This API is supported since API version 7 and deprecated since API version 9. <!--Del-->You are advised to use [notificationManager.NotificationKey](js-apis-notificationSubscribe-sys.md#notificationkey).<!--DelEnd-->
969
970| Name | Type  | Readable | Writable | Description    |
971| ----- | ------ | ---- | --- | -------- |
972| id    | number | Yes | Yes | Notification ID.  |
973| label | string | Yes | Yes | Notification label. |
974
975
976## SlotType
977
978**System capability**: SystemCapability.Notification.Notification
979
980| Name                | Value      | Description      |
981| -------------------- | -------- | ---------- |
982| UNKNOWN_TYPE         | 0 | Unknown type. |
983| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication. |
984| SERVICE_INFORMATION  | 2 | Notification slot for service information. |
985| CONTENT_INFORMATION  | 3 | Notification slot for content consultation. |
986| OTHER_TYPES          | 0xFFFF | Notification slot for other purposes. |
987
988
989## NotificationActionButton
990
991Describes the button displayed in the notification.
992
993**System capability**: SystemCapability.Notification.Notification
994
995| Name     | Type                                           | Readable | Writable | Description                     |
996| --------- | ----------------------------------------------- | --- | ---- | ------------------------- |
997| title     | string                                          | Yes | Yes | Button title.                 |
998| wantAgent | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md)   | Yes | Yes | **WantAgent** of the button. |
999| extras    | { [key: string]: any }                          | Yes | Yes | Extra information of the button.             |
1000| userInput<sup>8+</sup> | [NotificationUserInput](#notificationuserinput8) | Yes | Yes | User input object.         |
1001
1002
1003## NotificationBasicContent
1004
1005Describes the normal text notification.
1006
1007**System capability**: SystemCapability.Notification.Notification
1008
1009| Name          | Type  | Readable | Writable | Description                              |
1010| -------------- | ------ | ---- | ---- | ---------------------------------- |
1011| title          | string | Yes  | Yes  | Notification title.                        |
1012| text           | string | Yes  | Yes  | Notification content.                        |
1013| additionalText | string | Yes  | Yes  | Additional information of the notification. |
1014
1015
1016## NotificationLongTextContent
1017
1018Describes the long text notification.
1019
1020**System capability**: SystemCapability.Notification.Notification
1021
1022| Name          | Type  | Readable | Writable | Description                            |
1023| -------------- | ------ | ---- | --- | -------------------------------- |
1024| title          | string | Yes | Yes | Notification title.                        |
1025| text           | string | Yes | Yes | Notification content.                        |
1026| additionalText | string | Yes | Yes | Additional information of the notification. |
1027| longText       | string | Yes | Yes | Long text of the notification.                    |
1028| briefText      | string | Yes | Yes | Brief text of the notification. |
1029| expandedTitle  | string | Yes | Yes | Title of the notification in the expanded state.                |
1030
1031
1032## NotificationMultiLineContent
1033
1034Describes the multi-line text notification.
1035
1036**System capability**: SystemCapability.Notification.Notification
1037
1038| Name          | Type           | Readable | Writable | Description                            |
1039| -------------- | --------------- | --- | --- | -------------------------------- |
1040| title          | string          | Yes | Yes | Notification title.                        |
1041| text           | string          | Yes | Yes | Notification content.                        |
1042| additionalText | string          | Yes | Yes | Additional information of the notification. |
1043| briefText      | string          | Yes | Yes | Brief text of the notification. |
1044| longTitle      | string          | Yes | Yes | Title of the notification in the expanded state.                |
1045| lines          | Array\<string\> | Yes | Yes | Multi-line text of the notification.                  |
1046
1047
1048## NotificationPictureContent
1049
1050Describes the picture-attached notification.
1051
1052**System capability**: SystemCapability.Notification.Notification
1053
1054| Name          | Type          | Readable | Writable | Description                            |
1055| -------------- | -------------- | ---- | --- | -------------------------------- |
1056| title          | string         | Yes | Yes | Notification title.                        |
1057| text           | string         | Yes | Yes | Notification content.                        |
1058| additionalText | string         | Yes | Yes | Additional information of the notification. |
1059| briefText      | string         | Yes | Yes | Brief text of the notification. |
1060| expandedTitle  | string         | Yes | Yes | Title of the notification in the expanded state.                |
1061| picture        | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification.                  |
1062
1063
1064## NotificationContent
1065
1066Describes the notification content.
1067
1068**System capability**: SystemCapability.Notification.Notification
1069
1070| Name       | Type                                                        | Readable | Writable | Description              |
1071| ----------- | ------------------------------------------------------------ | ---- | --- | ------------------ |
1072| contentType | [notification.ContentType](#contenttype)                                  | Yes | Yes | Notification content type.      |
1073| normal      | [NotificationBasicContent](#notificationbasiccontent)        | Yes | Yes | Normal text.  |
1074| longText    | [NotificationLongTextContent](#notificationlongtextcontent)  | Yes | Yes | Long text. |
1075| multiLine   | [NotificationMultiLineContent](#notificationmultilinecontent) | Yes | Yes | Multi-line text.  |
1076| picture     | [NotificationPictureContent](#notificationpicturecontent)    | Yes | Yes | Picture-attached.  |
1077
1078## NotificationRequest
1079
1080Describes the notification request.
1081
1082**System capability**: SystemCapability.Notification.Notification
1083
1084| Name                 | Type                                         | Readable | Writable | Description                      |
1085| --------------------- | --------------------------------------------- | ---- | --- | -------------------------- |
1086| content               | [NotificationContent](#notificationcontent)   | Yes | Yes | Notification content.                  |
1087| id                    | number                                        | Yes | Yes | Notification ID.                    |
1088| slotType              | [notification.SlotType](#slottype)                         | Yes | Yes | Slot type.                  |
1089| isOngoing             | boolean                                       | Yes | Yes | Whether the notification is an ongoing notification.            |
1090| isUnremovable         | boolean                                       | Yes | Yes | Whether the notification can be removed.                |
1091| deliveryTime          | number                                        | Yes | Yes | Time when the notification is sent.              |
1092| tapDismissed          | boolean                                       | Yes | Yes | Whether the notification is automatically cleared.          |
1093| autoDeletedTime       | number                                        | Yes | Yes | Time when the notification is automatically cleared.            |
1094| wantAgent             | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked.  |
1095| extraInfo             | {[key: string]: any}                          | Yes | Yes | Extended parameters.                  |
1096| color                 | number                                        | Yes | Yes | Background color of the notification. Not supported currently. |
1097| colorEnabled          | boolean                                       | Yes | Yes | Whether the notification background color is enabled. Not supported currently. |
1098| isAlertOnce           | boolean                                       | Yes | Yes | Whether the notification triggers an alert only once. |
1099| isStopwatch           | boolean                                       | Yes | Yes | Whether to display the stopwatch.          |
1100| isCountDown           | boolean                                       | Yes | Yes | Whether to display the countdown time.        |
1101| isFloatingIcon        | boolean                                       | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar.        |
1102| label                 | string                                        | Yes | Yes | Notification label.                  |
1103| badgeIconStyle        | number                                        | Yes | Yes | Notification badge type.              |
1104| showDeliveryTime      | boolean                                       | Yes | Yes | Whether to display the time when the notification is delivered.          |
1105| actionButtons         | Array\<[NotificationActionButton](#notificationactionbutton)\>             | Yes | Yes | Buttons in the notification. Up to two buttons are allowed.    |
1106| smallIcon             | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB. |
1107| largeIcon             | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB. |
1108| creatorBundleName     | string                                        | Yes | No | Name of the bundle that creates the notification.            |
1109| creatorUid            | number                                        | Yes | No | UID used for creating the notification.             |
1110| creatorPid            | number                                        | Yes | No | PID used for creating the notification.             |
1111| creatorUserId<sup>8+</sup>| number                                    | Yes | No | ID of the user who creates the notification.          |
1112| hashCode              | string                                        | Yes | No | Unique ID of the notification.              |
1113| groupName<sup>8+</sup>| string                                        | Yes | Yes | Notification group name.                |
1114| template<sup>8+</sup> | [NotificationTemplate](#notificationtemplate8) | Yes | Yes | Notification template.                  |
1115| distributedOption<sup>8+</sup>   | [DistributedOptions](#distributedoptions8)                 | Yes | Yes | Distributed notification options.         |
1116| notificationFlags<sup>8+</sup> | [NotificationFlags](./js-apis-inner-notification-notificationFlags.md)                    | Yes | No | Notification flags.         |
1117| removalWantAgent<sup>9+</sup> | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed.         |
1118| badgeNumber<sup>9+</sup> | number                    | Yes | Yes | Number of notifications displayed on the application icon.         |
1119
1120## DistributedOptions<sup>8+</sup>
1121
1122Describes distributed notifications options.
1123
1124**System capability**: SystemCapability.Notification.Notification
1125
1126| Name                  | Type           | Readable | Writable | Description                              |
1127| ---------------------- | -------------- | ---- | ---- | ---------------------------------- |
1128| isDistributed          | boolean        | Yes  | Yes  | Whether the notification is a distributed notification.                 |
1129| supportDisplayDevices  | Array\<string> | Yes  | Yes  | List of the devices to which the notification can be synchronized.        |
1130| supportOperateDevices  | Array\<string> | Yes  | Yes  | List of the devices on which the notification can be opened.             |
1131
1132
1133## NotificationSlot
1134
1135Describes the notification slot.
1136
1137**System capability**: SystemCapability.Notification.Notification
1138
1139| Name                | Type                 | Readable | Writable | Description                    |
1140| -------------------- | --------------------- | ---- | --- |------------------------|
1141| type                 | [notification.SlotType](#slottype) | Yes | Yes | Slot type.                 |
1142| level                | [notification.SlotLevel](#slotlevel)                | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type. |
1143| desc                 | string                | Yes | Yes | Notification slot description.             |
1144| badgeFlag            | boolean               | Yes | Yes | Whether to display the badge.               |
1145| bypassDnd            | boolean               | Yes | Yes | Whether to bypass DND mode in the system.      |
1146| lockscreenVisibility | number                | Yes | Yes | Mode for displaying the notification on the lock screen.        |
1147| vibrationEnabled     | boolean               | Yes | Yes | Whether vibration is enabled for the notification.                |
1148| sound                | string                | Yes | Yes | Notification alert tone.                |
1149| lightEnabled         | boolean               | Yes | Yes | Whether the indicator blinks for the notification.                 |
1150| lightColor           | number                | Yes | Yes | Indicator color of the notification.                |
1151| vibrationValues      | Array\<number\>       | Yes | Yes | Vibration mode of the notification.               |
1152| enabled<sup>9+</sup> | boolean               | Yes | No | Whether the notification slot is enabled.          |
1153
1154## NotificationTemplate<sup>8+</sup>
1155
1156Describes the notification template.
1157
1158**System capability**: SystemCapability.Notification.Notification
1159
1160| Name | Type                   | Readable | Writable | Description      |
1161| ---- | ---------------------- | ---- | ---- | ---------- |
1162| name | string                 | Yes  | Yes  | Template name. |
1163| data | Record<string, Object> | Yes  | Yes  | Template data. |
1164
1165
1166## NotificationUserInput<sup>8+</sup>
1167
1168Provides the notification user input.
1169
1170**System capability**: SystemCapability.Notification.Notification
1171
1172| Name    | Type  | Readable | Writable | Description                         |
1173| -------- | ------ | --- | ---- | ----------------------------- |
1174| inputKey | string | Yes | Yes | Key to identify the user input. |
1175