1# @ohos.notification (Notification模块)
2
3本模块提供通知管理的能力,包括发布、取消发布通知,创建、获取、移除通知通道,订阅、取消订阅通知,获取通知的使能状态、角标使能状态,获取通知的相关信息等。
4
5> **说明:**
6>
7> 从API version 9开始,该接口不再维护,推荐使用新接口[@ohos.notificationManager](js-apis-notificationManager.md)。
8> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
9>
10> 通知订阅和取消订阅仅对系统应用开放。
11
12## 导入模块
13
14```ts
15import Notification from '@ohos.notification';
16```
17
18## Notification.publish
19
20publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
21
22发布通知(callback形式)。
23
24**系统能力**:SystemCapability.Notification.Notification
25
26**参数:**
27
28| 参数名     | 类型                                        | 必填 | 说明                                        |
29| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
30| request  | [NotificationRequest](#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
31| callback | AsyncCallback\<void\>                       | 是   | 发布通知的回调方法。                        |
32
33**示例:**
34
35```ts
36import NotificationManager from '@ohos.notificationManager';
37import Base from '@ohos.base';
38
39// publish回调
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// 通知Request对象
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
66发布通知(Promise形式)。
67
68**系统能力**:SystemCapability.Notification.Notification
69
70**参数:**
71
72| 参数名     | 类型                                        | 必填 | 说明                                        |
73| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
74| request  | [NotificationRequest](#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
75
76**返回值:**
77
78| 类型     | 说明         |
79| ------- |------------|
80| Promise\<void\> | 无返回结果的Promise对象。 |
81
82**示例:**
83
84```ts
85import NotificationManager from '@ohos.notificationManager';
86import Base from '@ohos.base';
87
88// 通知Request对象
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
111通过通知ID和通知标签取消已发布的通知(callback形式)。
112
113**系统能力**:SystemCapability.Notification.Notification
114
115**参数:**
116
117| 参数名     | 类型                  | 必填 | 说明                 |
118| -------- | --------------------- | ---- | -------------------- |
119| id       | number                | 是   | 通知ID。               |
120| label    | string                | 是   | 通知标签。             |
121| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
122
123**示例:**
124
125```ts
126import Base from '@ohos.base';
127
128// cancel回调
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
145取消与指定通知ID相匹配的已发布通知,label可以指定也可以不指定(Promise形式)。
146
147**系统能力**:SystemCapability.Notification.Notification
148
149**参数:**
150
151| 参数名  | 类型   | 必填 | 说明     |
152| ----- | ------ | ---- | -------- |
153| id    | number | 是   | 通知ID。   |
154| label | string | 否   | 通知标签,默认为空。 |
155
156**返回值:**
157
158| 类型     | 说明         |
159| ------- |------------|
160| Promise\<void\> | 无返回结果的Promise对象。 |
161
162**示例:**
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
180取消与指定通知ID相匹配的已发布通知(callback形式)。
181
182**系统能力**:SystemCapability.Notification.Notification
183
184**参数:**
185
186| 参数名     | 类型                  | 必填 | 说明                 |
187| -------- | --------------------- | ---- | -------------------- |
188| id       | number                | 是   | 通知ID。               |
189| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
190
191**示例:**
192
193```ts
194import Base from '@ohos.base';
195
196// cancel回调
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
213取消所有已发布的通知(callback形式)。
214
215**系统能力**:SystemCapability.Notification.Notification
216
217**参数:**
218
219| 参数名     | 类型                  | 必填 | 说明                 |
220| -------- | --------------------- | ---- | -------------------- |
221| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
222
223**示例:**
224
225```ts
226import Base from '@ohos.base';
227
228// cancel回调
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
243取消所有已发布的通知(Promise形式)。
244
245**系统能力**:SystemCapability.Notification.Notification
246
247**返回值:**
248
249| 类型     | 说明         |
250| ------- |------------|
251| Promise\<void\> | 无返回结果的Promise对象。 |
252
253**示例:**
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
269创建指定类型的通知通道(callback形式)。
270
271**系统能力**:SystemCapability.Notification.Notification
272
273**参数:**
274
275| 参数名     | 类型                  | 必填 | 说明                   |
276| -------- | --------------------- | ---- | ---------------------- |
277| type     | [SlotType](#slottype)              | 是   | 要创建的通知通道的类型。 |
278| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。   |
279
280**示例:**
281
282```ts
283import Base from '@ohos.base';
284
285// addslot回调
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
300创建指定类型的通知通道(Promise形式)。
301
302**系统能力**:SystemCapability.Notification.Notification
303
304**参数:**
305
306| 参数名 | 类型     | 必填 | 说明                   |
307| ---- | -------- | ---- | ---------------------- |
308| type | [SlotType](#slottype) | 是   | 要创建的通知通道的类型。 |
309
310**返回值:**
311
312| 类型     | 说明         |
313| ------- |------------|
314| Promise\<void\> | 无返回结果的Promise对象。 |
315
316**示例:**
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
332获取一个指定类型的通知通道(callback形式)。
333
334**系统能力**:SystemCapability.Notification.Notification
335
336**参数:**
337
338| 参数名     | 类型                              | 必填 | 说明                                                        |
339| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
340| slotType | [SlotType](#slottype)                          | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
341| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | 是   | 表示被指定的回调方法。                                        |
342
343**示例:**
344
345```ts
346import Base from '@ohos.base';
347
348// getSlot回调
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
364获取一个指定类型的通知通道(Promise形式)。
365
366**系统能力**:SystemCapability.Notification.Notification
367
368**参数:**
369
370| 参数名     | 类型     | 必填 | 说明                                                        |
371| -------- | -------- | ---- | ----------------------------------------------------------- |
372| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
373
374**返回值:**
375
376| 类型                                                        | 说明                                                         |
377| ----------------------------------------------------------- | ------------------------------------------------------------ |
378| Promise\<NotificationSlot\> | 以Promise形式返回获取一个通知通道。 |
379
380**示例:**
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
397获取此应用程序的所有通知通道(callback形式)。
398
399**系统能力**:SystemCapability.Notification.Notification
400
401**参数:**
402
403| 参数名     | 类型                              | 必填 | 说明                 |
404| -------- | --------------------------------- | ---- | -------------------- |
405| callback | AsyncCallback\<Array\<[NotificationSlot](#notificationslot)>> | 是   | 以callback形式返回获取此应用程序的所有通知通道的结果。 |
406
407**示例:**
408
409```ts
410import Base from '@ohos.base';
411
412// getSlots回调
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
427获取此应用程序的所有通知通道(Promise形式)。
428
429**系统能力**:SystemCapability.Notification.Notification
430
431**返回值:**
432
433| 类型                                                        | 说明                                                         |
434| ----------------------------------------------------------- | ------------------------------------------------------------ |
435| Promise\<Array\<[NotificationSlot](#notificationslot)\>\> | 以Promise形式返回获取此应用程序的所有通知通道的结果。 |
436
437**示例:**
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
453删除指定类型的通知通道(callback形式)。
454
455**系统能力**:SystemCapability.Notification.Notification
456
457**参数:**
458
459| 参数名     | 类型                  | 必填 | 说明                                                        |
460| -------- | --------------------- | ---- | ----------------------------------------------------------- |
461| slotType | [SlotType](#slottype)              | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
462| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。                                        |
463
464**示例:**
465
466```ts
467import Base from '@ohos.base';
468
469// removeSlot回调
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
485删除指定类型的通知通道(Promise形式)。
486
487**系统能力**:SystemCapability.Notification.Notification
488
489**参数:**
490
491| 参数名     | 类型     | 必填 | 说明                                                        |
492| -------- | -------- | ---- | ----------------------------------------------------------- |
493| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
494
495**返回值:**
496
497| 类型     | 说明         |
498| ------- |------------|
499| Promise\<void\> | 无返回结果的Promise对象。 |
500
501**示例:**
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
518删除所有通知通道(callback形式)。
519
520**系统能力**:SystemCapability.Notification.Notification
521
522**参数:**
523
524| 参数名     | 类型                  | 必填 | 说明                 |
525| -------- | --------------------- | ---- | -------------------- |
526| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
527
528**示例:**
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
547删除所有通知通道(Promise形式)。
548
549**系统能力**:SystemCapability.Notification.Notification
550
551**返回值:**
552
553| 类型     | 说明         |
554| ------- |------------|
555| Promise\<void\> | 无返回结果的Promise对象。 |
556
557**示例:**
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
573获取当前应用未删除的通知数(Callback形式)。
574
575**系统能力**:SystemCapability.Notification.Notification
576
577**参数:**
578
579| 参数名     | 类型                   | 必填 | 说明                   |
580| -------- | ---------------------- | ---- | ---------------------- |
581| callback | AsyncCallback\<number\> | 是   | 获取未删除通知数回调函数。 |
582
583**示例:**
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
603获取当前应用未删除的通知数(Promise形式)。
604
605**系统能力**:SystemCapability.Notification.Notification
606
607**返回值:**
608
609| 类型              | 说明                                        |
610| ----------------- | ------------------------------------------- |
611| Promise\<number\> | 以Promise形式返回获取当前应用未删除通知数。 |
612
613**示例:**
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
629获取当前应用未删除的通知列表(Callback形式)。
630
631**系统能力**:SystemCapability.Notification.Notification
632
633**参数:**
634
635| 参数名     | 类型                                                         | 必填 | 说明                           |
636| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
637| callback | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | 是   | 获取当前应用通知列表回调函数。 |
638
639**示例:**
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
660获取当前应用未删除的通知列表(Promise形式)。
661
662**系统能力**:SystemCapability.Notification.Notification
663
664**返回值:**
665
666| 类型                                                         | 说明                                    |
667| ------------------------------------------------------------ | --------------------------------------- |
668| Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | 以Promise形式返回获取当前应用通知列表。 |
669
670**示例:**
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
687取消本应用指定组下的通知(Callback形式)。
688
689**系统能力**:SystemCapability.Notification.Notification
690
691**参数:**
692
693| 参数名      | 类型                  | 必填 | 说明                         |
694| --------- | --------------------- | ---- | ---------------------------- |
695| groupName | string                | 是   | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](#notificationrequest)对象指定。 |
696| callback  | AsyncCallback\<void\> | 是   | 取消本应用指定组下通知的回调函数。 |
697
698**示例:**
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
720取消本应用指定组下的通知(Promise形式)。
721
722**系统能力**:SystemCapability.Notification.Notification
723
724**参数:**
725
726| 参数名      | 类型   | 必填 | 说明           |
727| --------- | ------ | ---- | -------------- |
728| groupName | string | 是   | 通知组名称。 |
729
730**返回值:**
731
732| 类型     | 说明         |
733| ------- |------------|
734| Promise\<void\> | 无返回结果的Promise对象。 |
735
736**示例:**
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
753查询模板是否存在(Callback形式)。
754
755**系统能力**:SystemCapability.Notification.Notification
756
757**参数:**
758
759| 参数名       | 类型                     | 必填 | 说明                       |
760| ------------ | ------------------------ | ---- | -------------------------- |
761| templateName | string                   | 是   | 模板名称。                   |
762| callback     | AsyncCallback\<boolean\> | 是   | 查询模板是否存在的回调函数。 |
763
764**示例:**
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
785查询模板是否存在(Promise形式)。
786
787**系统能力**:SystemCapability.Notification.Notification
788
789**参数:**
790
791| 参数名       | 类型   | 必填 | 说明     |
792| ------------ | ------ | ---- | -------- |
793| templateName | string | 是   | 模板名称。 |
794
795**返回值:**
796
797| 类型               | 说明            |
798| ------------------ | --------------- |
799| Promise\<boolean\> | Promise方式返回模板是否存在的结果。 |
800
801**示例:**
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
818应用请求通知使能(Callback形式)。
819
820**系统能力**:SystemCapability.Notification.Notification
821
822**参数:**
823
824| 参数名   | 类型                     | 必填 | 说明                       |
825| -------- | ------------------------ | ---- | -------------------------- |
826| callback | AsyncCallback\<void\> | 是   | 应用请求通知使能的回调函数。 |
827
828**示例:**
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
848应用请求通知使能(Promise形式)。
849
850**系统能力**:SystemCapability.Notification.Notification
851
852**返回值:**
853
854| 类型     | 说明         |
855| ------- |------------|
856| Promise\<void\> | 无返回结果的Promise对象。 |
857
858**示例:**
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
874查询设备是否支持分布式通知(Callback形式)。
875
876**系统能力**:SystemCapability.Notification.Notification
877
878**参数:**
879
880| 参数名   | 类型                     | 必填 | 说明                       |
881| -------- | ------------------------ | ---- | -------------------------- |
882| callback | AsyncCallback\<boolean\> | 是   | 设备是否支持分布式通知的回调函数。 |
883
884**示例:**
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
904查询设备是否支持分布式通知(Promise形式)。
905
906**系统能力**:SystemCapability.Notification.Notification
907
908**返回值:**
909
910| 类型               | 说明                                          |
911| ------------------ | --------------------------------------------- |
912| Promise\<boolean\> | Promise方式返回设备是否支持分布式通知的结果。 |
913
914**示例:**
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**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
929
930| 名称                              | 值          | 说明               |
931| --------------------------------- | ----------- | ------------------ |
932| NOTIFICATION_CONTENT_BASIC_TEXT   | NOTIFICATION_CONTENT_BASIC_TEXT | 普通类型通知。     |
933| NOTIFICATION_CONTENT_LONG_TEXT    | NOTIFICATION_CONTENT_LONG_TEXT | 长文本类型通知。   |
934| NOTIFICATION_CONTENT_PICTURE      | NOTIFICATION_CONTENT_PICTURE | 图片类型通知。     |
935| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | 社交类型通知。     |
936| NOTIFICATION_CONTENT_MULTILINE    | NOTIFICATION_CONTENT_MULTILINE | 多行文本类型通知。 |
937
938## SlotLevel
939
940**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
941
942| 名称                              | 值          | 说明               |
943| --------------------------------- | ----------- | ------------------ |
944| LEVEL_NONE                        | 0           | 表示关闭通知功能。     |
945| LEVEL_MIN                         | 1           | 表示通知功能已启用,但状态栏中不显示通知图标,且没有横幅或提示音。 |
946| LEVEL_LOW                         | 2           | 表示通知功能已启用,且状态栏中显示通知图标,但没有横幅或提示音。 |
947| LEVEL_DEFAULT                     | 3           | 表示通知功能已启用,状态栏中显示通知图标,没有横幅但有提示音。 |
948| LEVEL_HIGH                        | 4           | 表示通知功能已启用,状态栏中显示通知图标,有横幅和提示音。 |
949
950
951## BundleOption<sup>deprecated</sup>
952
953**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
954
955> **说明:**
956> 从 API version 7开始支持,从API version 9开始废弃。建议使用[notificationManager.BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)替代
957
958| 名称   | 类型   | 必填 | 说明   |
959| ------ | ------ | --- |  ------ |
960| bundle | string | 是  | 应用的包信息。 |
961| uid    | number | 否  | 用户ID,默认为0。 |
962
963## NotificationKey<sup>deprecated</sup>
964
965**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
966
967> **说明:**
968> 从 API version 7开始支持,从API version 9开始废弃。<!--Del-->建议使用[notificationManager.NotificationKey](js-apis-notificationSubscribe-sys.md#notificationkey)替代。<!--DelEnd-->
969
970| 名称  | 类型   | 可读 | 可写 | 说明     |
971| ----- | ------ | ---- | --- | -------- |
972| id    | number | 是  | 是  | 通知ID。   |
973| label | string | 是  | 是  | 通知标签。 |
974
975
976## SlotType
977
978**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
979
980| 名称                 | 值       | 说明       |
981| -------------------- | -------- | ---------- |
982| UNKNOWN_TYPE         | 0 | 未知类型。 |
983| SOCIAL_COMMUNICATION | 1 | 社交类型。 |
984| SERVICE_INFORMATION  | 2 | 服务类型。 |
985| CONTENT_INFORMATION  | 3 | 内容类型。 |
986| OTHER_TYPES          | 0xFFFF | 其他类型。 |
987
988
989## NotificationActionButton
990
991描述通知中显示的操作按钮。
992
993**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
994
995| 名称      | 类型                                            | 可读 | 可写 | 说明                      |
996| --------- | ----------------------------------------------- | --- | ---- | ------------------------- |
997| title     | string                                          | 是  | 是  | 按钮标题。                  |
998| wantAgent | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md)   | 是  | 是  | 点击按钮时触发的WantAgent。 |
999| extras    | { [key: string]: any }                          | 是  | 是  | 按钮扩展信息。              |
1000| userInput<sup>8+</sup> | [NotificationUserInput](#notificationuserinput8) | 是  | 是  | 用户输入对象实例。          |
1001
1002
1003## NotificationBasicContent
1004
1005描述普通文本通知。
1006
1007**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1008
1009| 名称           | 类型   | 可读 | 可写 | 说明                               |
1010| -------------- | ------ | ---- | ---- | ---------------------------------- |
1011| title          | string | 是   | 是   | 通知标题。                         |
1012| text           | string | 是   | 是   | 通知内容。                         |
1013| additionalText | string | 是   | 是   | 通知附加内容,是对通知内容的补充。 |
1014
1015
1016## NotificationLongTextContent
1017
1018描述长文本通知。
1019
1020**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1021
1022| 名称           | 类型   | 可读 | 可写 | 说明                             |
1023| -------------- | ------ | ---- | --- | -------------------------------- |
1024| title          | string | 是  | 是  | 通知标题。                         |
1025| text           | string | 是  | 是  | 通知内容。                         |
1026| additionalText | string | 是  | 是  | 通知附加内容,是对通知内容的补充。 |
1027| longText       | string | 是  | 是  | 通知的长文本。                     |
1028| briefText      | string | 是  | 是  | 通知概要内容,是对通知内容的总结。 |
1029| expandedTitle  | string | 是  | 是  | 通知展开时的标题。                 |
1030
1031
1032## NotificationMultiLineContent
1033
1034描述多行文本通知。
1035
1036**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1037
1038| 名称           | 类型            | 可读 | 可写 | 说明                             |
1039| -------------- | --------------- | --- | --- | -------------------------------- |
1040| title          | string          | 是  | 是  | 通知标题。                         |
1041| text           | string          | 是  | 是  | 通知内容。                         |
1042| additionalText | string          | 是  | 是  | 通知附加内容,是对通知内容的补充。 |
1043| briefText      | string          | 是  | 是  | 通知概要内容,是对通知内容的总结。 |
1044| longTitle      | string          | 是  | 是  | 通知展开时的标题。                 |
1045| lines          | Array\<string\> | 是  | 是  | 通知的多行文本。                   |
1046
1047
1048## NotificationPictureContent
1049
1050描述附有图片的通知。
1051
1052**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1053
1054| 名称           | 类型           | 可读 | 可写 | 说明                             |
1055| -------------- | -------------- | ---- | --- | -------------------------------- |
1056| title          | string         | 是  | 是  | 通知标题。                         |
1057| text           | string         | 是  | 是  | 通知内容。                         |
1058| additionalText | string         | 是  | 是  | 通知附加内容,是对通知内容的补充。 |
1059| briefText      | string         | 是  | 是  | 通知概要内容,是对通知内容的总结。 |
1060| expandedTitle  | string         | 是  | 是  | 通知展开时的标题。                 |
1061| picture        | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是  | 是  | 通知的图片内容。                   |
1062
1063
1064## NotificationContent
1065
1066描述通知类型。
1067
1068**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1069
1070| 名称        | 类型                                                         | 可读 | 可写 | 说明               |
1071| ----------- | ------------------------------------------------------------ | ---- | --- | ------------------ |
1072| contentType | [notification.ContentType](#contenttype)                                  | 是  | 是  | 通知内容类型。       |
1073| normal      | [NotificationBasicContent](#notificationbasiccontent)        | 是  | 是  | 基本类型通知内容。   |
1074| longText    | [NotificationLongTextContent](#notificationlongtextcontent)  | 是  | 是  | 长文本类型通知内容。 |
1075| multiLine   | [NotificationMultiLineContent](#notificationmultilinecontent) | 是  | 是  | 多行类型通知内容。   |
1076| picture     | [NotificationPictureContent](#notificationpicturecontent)    | 是  | 是  | 图片类型通知内容。   |
1077
1078## NotificationRequest
1079
1080描述通知的请求。
1081
1082**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1083
1084| 名称                  | 类型                                          | 可读 | 可写 | 说明                       |
1085| --------------------- | --------------------------------------------- | ---- | --- | -------------------------- |
1086| content               | [NotificationContent](#notificationcontent)   | 是  | 是  | 通知内容。                   |
1087| id                    | number                                        | 是  | 是  | 通知ID。                     |
1088| slotType              | [notification.SlotType](#slottype)                         | 是  | 是  | 通道类型。                   |
1089| isOngoing             | boolean                                       | 是  | 是  | 是否进行时通知。             |
1090| isUnremovable         | boolean                                       | 是  | 是  | 是否可移除。                 |
1091| deliveryTime          | number                                        | 是  | 是  | 通知发送时间。               |
1092| tapDismissed          | boolean                                       | 是  | 是  | 通知是否自动清除。           |
1093| autoDeletedTime       | number                                        | 是  | 是  | 自动清除的时间。             |
1094| wantAgent             | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md) | 是  | 是  | WantAgent封装了应用的行为意图,点击通知时触发该行为。 |
1095| extraInfo             | {[key: string]: any}                          | 是  | 是  | 扩展参数。                   |
1096| color                 | number                                        | 是  | 是  | 通知背景颜色。预留能力,暂未支持。 |
1097| colorEnabled          | boolean                                       | 是  | 是  | 通知背景颜色是否使能。预留能力,暂未支持。 |
1098| isAlertOnce           | boolean                                       | 是  | 是  | 设置是否仅有一次此通知提醒。 |
1099| isStopwatch           | boolean                                       | 是  | 是  | 是否显示已用时间。           |
1100| isCountDown           | boolean                                       | 是  | 是  | 是否显示倒计时时间。         |
1101| isFloatingIcon        | boolean                                       | 是  | 是  | 是否显示状态栏图标。         |
1102| label                 | string                                        | 是  | 是  | 通知标签。                   |
1103| badgeIconStyle        | number                                        | 是  | 是  | 通知角标类型。               |
1104| showDeliveryTime      | boolean                                       | 是  | 是  | 是否显示分发时间。           |
1105| actionButtons         | Array\<[NotificationActionButton](#notificationactionbutton)\>             | 是  | 是  | 通知按钮,最多两个按钮。     |
1106| smallIcon             | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是  | 是  | 通知小图标。可选字段,大小不超过30KB。 |
1107| largeIcon             | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是  | 是  | 通知大图标。可选字段,大小不超过30KB。 |
1108| creatorBundleName     | string                                        | 是  | 否  | 创建通知的包名。             |
1109| creatorUid            | number                                        | 是  | 否  | 创建通知的UID。              |
1110| creatorPid            | number                                        | 是  | 否  | 创建通知的PID。              |
1111| creatorUserId<sup>8+</sup>| number                                    | 是  | 否  | 创建通知的UserId。           |
1112| hashCode              | string                                        | 是  | 否  | 通知唯一标识。               |
1113| groupName<sup>8+</sup>| string                                        | 是  | 是  | 组通知名称。                 |
1114| template<sup>8+</sup> | [NotificationTemplate](#notificationtemplate8) | 是  | 是  | 通知模板。                   |
1115| distributedOption<sup>8+</sup>   | [DistributedOptions](#distributedoptions8)                 | 是  | 是  | 分布式通知的选项。          |
1116| notificationFlags<sup>8+</sup> | [NotificationFlags](./js-apis-inner-notification-notificationFlags.md)                    | 是  | 否  | 获取NotificationFlags。          |
1117| removalWantAgent<sup>9+</sup> | [WantAgent](../apis-ability-kit/js-apis-wantAgent.md) | 是  | 是  | 当移除通知时,通知将被重定向到的WantAgent实例。          |
1118| badgeNumber<sup>9+</sup> | number                    | 是  | 是  | 应用程序图标上显示的通知数。          |
1119
1120## DistributedOptions<sup>8+</sup>
1121
1122描述分布式选项。
1123
1124**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1125
1126| 名称                   | 类型            | 可读 | 可写 | 说明                               |
1127| ---------------------- | -------------- | ---- | ---- | ---------------------------------- |
1128| isDistributed          | boolean        | 是   | 是   | 是否为分布式通知。                  |
1129| supportDisplayDevices  | Array\<string> | 是   | 是   | 可以同步通知到的设备列表。         |
1130| supportOperateDevices  | Array\<string> | 是   | 是   | 可以打开通知的设备列表。              |
1131
1132
1133## NotificationSlot
1134
1135描述通知槽
1136
1137**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1138
1139| 名称                 | 类型                  | 可读 | 可写 | 说明                     |
1140| -------------------- | --------------------- | ---- | --- |------------------------|
1141| type                 | [notification.SlotType](#slottype) | 是  | 是  | 通道类型。                  |
1142| level                | [notification.SlotLevel](#slotlevel)                | 是  | 是  | 通知级别,不设置则根据通知渠道类型有默认值。 |
1143| desc                 | string                | 是  | 是  | 通知渠道描述信息。              |
1144| badgeFlag            | boolean               | 是  | 是  | 是否显示角标。                |
1145| bypassDnd            | boolean               | 是  | 是  | 设置是否在系统中绕过免打扰模式。       |
1146| lockscreenVisibility | number                | 是  | 是  | 在锁定屏幕上显示通知的模式。         |
1147| vibrationEnabled     | boolean               | 是  | 是  | 是否可振动。                 |
1148| sound                | string                | 是  | 是  | 通知提示音。                 |
1149| lightEnabled         | boolean               | 是  | 是  | 是否闪灯。                  |
1150| lightColor           | number                | 是  | 是  | 通知灯颜色。                 |
1151| vibrationValues      | Array\<number\>       | 是  | 是  | 通知振动样式。                |
1152| enabled<sup>9+</sup> | boolean               | 是  | 否  | 此通知插槽中的启停状态。           |
1153
1154## NotificationTemplate<sup>8+</sup>
1155
1156通知模板。
1157
1158**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
1159
1160| 名称 | 类型                    | 可读 | 可写 | 说明       |
1161| ---- | ---------------------- | ---- | ---- | ---------- |
1162| name | string                 | 是   | 是   | 模板名称。 |
1163| data | Record<string, Object> | 是   | 是   | 模板数据。 |
1164
1165
1166## NotificationUserInput<sup>8+</sup>
1167
1168保存用户输入的通知消息。
1169
1170**系统能力**:SystemCapability.Notification.Notification
1171
1172| 名称     | 类型   | 可读 | 可写 | 说明                          |
1173| -------- | ------ | --- | ---- | ----------------------------- |
1174| inputKey | string | 是  | 是  | 用户输入时用于标识此输入的key。 |
1175