• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.notificationManager (NotificationManager模块)
2
3本模块提供通知管理的能力,包括发布、取消发布通知,创建、获取、移除通知通道,获取通知的使能状态、角标使能状态,获取通知的相关信息等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import Notification from '@ohos.notificationManager';
13```
14
15## Notification.publish
16
17publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
18
19发布通知(callback形式)。
20
21**系统能力**:SystemCapability.Notification.Notification
22
23**参数:**
24
25| 参数名     | 类型                                        | 必填 | 说明                                        |
26| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
27| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
28| callback | AsyncCallback\<void\>                       | 是   | 发布通知的回调方法。                        |
29
30**错误码:**
31
32错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
33
34| 错误码ID | 错误信息                                  |
35| -------- | ----------------------------------------- |
36| 1600001  | Internal error.                           |
37| 1600002  | Marshalling or unmarshalling error.       |
38| 1600003  | Failed to connect service.                |
39| 1600004  | Notification is not enabled.              |
40| 1600005  | Notification slot is not enabled.         |
41| 1600009  | Over max number notifications per second. |
42
43**示例:**
44
45```js
46//publish回调
47function publishCallback(err) {
48    if (err) {
49        console.info("publish failed " + JSON.stringify(err));
50    } else {
51        console.info("publish success");
52    }
53}
54//通知Request对象
55let notificationRequest = {
56    id: 1,
57    content: {
58        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
59        normal: {
60            title: "test_title",
61            text: "test_text",
62            additionalText: "test_additionalText"
63        }
64    }
65};
66Notification.publish(notificationRequest, publishCallback);
67```
68
69
70
71## Notification.publish
72
73publish(request: NotificationRequest): Promise\<void\>
74
75发布通知(Promise形式)。
76
77**系统能力**:SystemCapability.Notification.Notification
78
79**参数:**
80
81| 参数名     | 类型                                        | 必填 | 说明                                        |
82| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
83| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
84
85**错误码:**
86
87错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
88
89| 错误码ID | 错误信息                                  |
90| -------- | ----------------------------------------- |
91| 1600001  | Internal error.                           |
92| 1600002  | Marshalling or unmarshalling error.       |
93| 1600003  | Failed to connect service.                |
94| 1600004  | Notification is not enabled.              |
95| 1600005  | Notification slot is not enabled.         |
96| 1600009  | Over max number notifications per second. |
97
98**示例:**
99
100```js
101// 通知Request对象
102let notificationRequest = {
103    notificationId: 1,
104    content: {
105        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
106        normal: {
107            title: "test_title",
108            text: "test_text",
109            additionalText: "test_additionalText"
110        }
111    }
112};
113Notification.publish(notificationRequest).then(() => {
114	console.info("publish success");
115});
116
117```
118
119## Notification.publish
120
121publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void
122
123发布通知给指定的用户(callback形式)。
124
125**系统能力**:SystemCapability.Notification.Notification
126
127**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
128
129**系统API**: 此接口为系统接口,三方应用不支持调用。
130
131**参数:**
132
133| 参数名     | 类型                                        | 必填 | 说明                                        |
134| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
135| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
136| userId   | number                                      | 是   | 用户ID。                           |
137| callback | AsyncCallback\<void\>                       | 是   | 被指定的回调方法。                           |
138
139**错误码:**
140
141错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
142
143| 错误码ID | 错误信息                                  |
144| -------- | ----------------------------------------- |
145| 1600001  | Internal error.                           |
146| 1600002  | Marshalling or unmarshalling error.       |
147| 1600003  | Failed to connect service.                |
148| 1600004  | Notification is not enabled.              |
149| 1600005  | Notification slot is not enabled.         |
150| 1600008  | The user is not exist.                    |
151| 1600009  | Over max number notifications per second. |
152
153**示例:**
154
155```js
156// publish回调
157function publishCallback(err) {
158    if (err) {
159        console.info("publish failed " + JSON.stringify(err));
160    } else {
161        console.info("publish success");
162    }
163}
164// 用户ID
165let userId = 1;
166// 通知Request对象
167let notificationRequest = {
168    id: 1,
169    content: {
170        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
171        normal: {
172            title: "test_title",
173            text: "test_text",
174            additionalText: "test_additionalText"
175        }
176    }
177};
178Notification.publish(notificationRequest, userId, publishCallback);
179```
180
181## Notification.publish
182
183publish(request: NotificationRequest, userId: number): Promise\<void\>
184
185发布通知给指定的用户(Promise形式)。
186
187**系统能力**:SystemCapability.Notification.Notification
188
189**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
190
191**系统API**: 此接口为系统接口,三方应用不支持调用。
192
193**参数:**
194
195| 参数名     |  类型                                        | 必填 | 说明                                        |
196| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
197| request  | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
198| userId   | number                                      | 是   | 用户ID。                           |
199
200**错误码:**
201
202错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
203
204| 错误码ID | 错误信息                                  |
205| -------- | ----------------------------------------- |
206| 1600001  | Internal error.                           |
207| 1600002  | Marshalling or unmarshalling error.       |
208| 1600003  | Failed to connect service.                |
209| 1600004  | Notification is not enabled.              |
210| 1600005  | Notification slot is not enabled.         |
211| 1600008  | The user is not exist.                    |
212| 1600009  | Over max number notifications per second. |
213
214**示例:**
215
216```js
217let notificationRequest = {
218    notificationId: 1,
219    content: {
220        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
221        normal: {
222            title: "test_title",
223            text: "test_text",
224            additionalText: "test_additionalText"
225        }
226    }
227};
228
229let userId = 1;
230
231Notification.publish(notificationRequest, userId).then(() => {
232	console.info("publish success");
233});
234```
235
236
237## Notification.cancel
238
239cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
240
241通过通知ID和通知标签取消已发布的通知(callback形式)。
242
243**系统能力**:SystemCapability.Notification.Notification
244
245**参数:**
246
247| 参数名     | 类型                  | 必填 | 说明                 |
248| -------- | --------------------- | ---- | -------------------- |
249| id       | number                | 是   | 通知ID。               |
250| label    | string                | 是   | 通知标签。             |
251| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
252
253**错误码:**
254
255错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
256
257| 错误码ID | 错误信息                            |
258| -------- | ----------------------------------- |
259| 1600001  | Internal error.                     |
260| 1600002  | Marshalling or unmarshalling error. |
261| 1600003  | Failed to connect service.          |
262| 1600007  | The notification is not exist.      |
263
264**示例:**
265
266```js
267// cancel回调
268function cancelCallback(err) {
269    if (err) {
270        console.info("cancel failed " + JSON.stringify(err));
271    } else {
272        console.info("cancel success");
273    }
274}
275Notification.cancel(0, "label", cancelCallback);
276```
277
278
279
280## Notification.cancel
281
282cancel(id: number, label?: string): Promise\<void\>
283
284取消与指定通知ID相匹配的已发布通知,label可以指定也可以不指定(Promise形式)。
285
286**系统能力**:SystemCapability.Notification.Notification
287
288**参数:**
289
290| 参数名  | 类型   | 必填 | 说明     |
291| ----- | ------ | ---- | -------- |
292| id    | number | 是   | 通知ID。   |
293| label | string | 否   | 通知标签。 |
294
295**错误码:**
296
297错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
298
299| 错误码ID | 错误信息                            |
300| -------- | ----------------------------------- |
301| 1600001  | Internal error.                     |
302| 1600002  | Marshalling or unmarshalling error. |
303| 1600003  | Failed to connect service.          |
304| 1600007  | The notification is not exist.      |
305
306**示例:**
307
308```js
309Notification.cancel(0).then(() => {
310	console.info("cancel success");
311});
312```
313
314
315
316## Notification.cancel
317
318cancel(id: number, callback: AsyncCallback\<void\>): void
319
320取消与指定通知ID相匹配的已发布通知(callback形式)。
321
322**系统能力**:SystemCapability.Notification.Notification
323
324**参数:**
325
326| 参数名     | 类型                  | 必填 | 说明                 |
327| -------- | --------------------- | ---- | -------------------- |
328| id       | number                | 是   | 通知ID。               |
329| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
330
331**错误码:**
332
333错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
334
335| 错误码ID | 错误信息                            |
336| -------- | ----------------------------------- |
337| 1600001  | Internal error.                     |
338| 1600002  | Marshalling or unmarshalling error. |
339| 1600003  | Failed to connect service.          |
340| 1600007  | The notification is not exist.      |
341
342**示例:**
343
344```js
345// cancel回调
346function cancelCallback(err) {
347    if (err) {
348        console.info("cancel failed " + JSON.stringify(err));
349    } else {
350        console.info("cancel success");
351    }
352}
353Notification.cancel(0, cancelCallback);
354```
355
356
357
358## Notification.cancelAll
359
360cancelAll(callback: AsyncCallback\<void\>): void
361
362取消所有已发布的通知(callback形式)。
363
364**系统能力**:SystemCapability.Notification.Notification
365
366**错误码:**
367
368错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
369
370| 错误码ID | 错误信息                            |
371| -------- | ----------------------------------- |
372| 1600001  | Internal error.                     |
373| 1600002  | Marshalling or unmarshalling error. |
374| 1600003  | Failed to connect service.          |
375
376**参数:**
377
378| 参数名     | 类型                  | 必填 | 说明                 |
379| -------- | --------------------- | ---- | -------------------- |
380| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
381
382**示例:**
383
384```js
385// cancel回调
386function cancelAllCallback(err) {
387    if (err) {
388        console.info("cancelAll failed " + JSON.stringify(err));
389    } else {
390        console.info("cancelAll success");
391    }
392}
393Notification.cancelAll(cancelAllCallback);
394```
395
396
397
398## Notification.cancelAll
399
400cancelAll(): Promise\<void\>
401
402取消所有已发布的通知(Promise形式)。
403
404**系统能力**:SystemCapability.Notification.Notification
405
406**错误码:**
407
408错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
409
410| 错误码ID | 错误信息                            |
411| -------- | ----------------------------------- |
412| 1600001  | Internal error.                     |
413| 1600002  | Marshalling or unmarshalling error. |
414| 1600003  | Failed to connect service.          |
415
416**示例:**
417
418```js
419Notification.cancelAll().then(() => {
420	console.info("cancelAll success");
421});
422```
423
424
425
426## Notification.addSlot
427
428addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
429
430创建通知通道(callback形式)。
431
432**系统能力**:SystemCapability.Notification.Notification
433
434**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
435
436**系统API**: 此接口为系统接口,三方应用不支持调用。
437
438**参数:**
439
440| 参数名     | 类型                  | 必填 | 说明                 |
441| -------- | --------------------- | ---- | -------------------- |
442| slot     | [NotificationSlot](js-apis-inner-notification-notificationSlot.md)       | 是   | 要创建的通知通道对象。 |
443| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
444
445**错误码:**
446
447错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
448
449| 错误码ID | 错误信息                            |
450| -------- | ----------------------------------- |
451| 1600001  | Internal error.                     |
452| 1600002  | Marshalling or unmarshalling error. |
453| 1600003  | Failed to connect service.          |
454
455**示例:**
456
457```js
458// addslot回调
459function addSlotCallBack(err) {
460    if (err) {
461        console.info("addSlot failed " + JSON.stringify(err));
462    } else {
463        console.info("addSlot success");
464    }
465}
466// 通知slot对象
467let notificationSlot = {
468    type: Notification.SlotType.SOCIAL_COMMUNICATION
469};
470Notification.addSlot(notificationSlot, addSlotCallBack);
471```
472
473
474
475## Notification.addSlot
476
477addSlot(slot: NotificationSlot): Promise\<void\>
478
479创建通知通道(Promise形式)。
480
481**系统能力**:SystemCapability.Notification.Notification
482
483**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
484
485**系统API**: 此接口为系统接口,三方应用不支持调用。
486
487**参数:**
488
489| 参数名 | 类型             | 必填 | 说明                 |
490| ---- | ---------------- | ---- | -------------------- |
491| slot | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | 是   | 要创建的通知通道对象。 |
492
493**错误码:**
494
495错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
496
497| 错误码ID | 错误信息                            |
498| -------- | ----------------------------------- |
499| 1600001  | Internal error.                     |
500| 1600002  | Marshalling or unmarshalling error. |
501| 1600003  | Failed to connect service.          |
502
503**示例:**
504
505```js
506// 通知slot对象
507let notificationSlot = {
508    type: Notification.SlotType.SOCIAL_COMMUNICATION
509};
510Notification.addSlot(notificationSlot).then(() => {
511	console.info("addSlot success");
512});
513```
514
515
516
517## Notification.addSlot
518
519addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
520
521创建指定类型的通知通道(callback形式)。
522
523**系统能力**:SystemCapability.Notification.Notification
524
525**参数:**
526
527| 参数名     | 类型                  | 必填 | 说明                   |
528| -------- | --------------------- | ---- | ---------------------- |
529| type     | [SlotType](#slottype)              | 是   | 要创建的通知通道的类型。 |
530| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。   |
531
532**错误码:**
533
534错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
535
536| 错误码ID | 错误信息                            |
537| -------- | ----------------------------------- |
538| 1600001  | Internal error.                     |
539| 1600002  | Marshalling or unmarshalling error. |
540| 1600003  | Failed to connect service.          |
541
542**示例:**
543
544```js
545// addslot回调
546function addSlotCallBack(err) {
547    if (err) {
548        console.info("addSlot failed " + JSON.stringify(err));
549    } else {
550        console.info("addSlot success");
551    }
552}
553Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
554```
555
556
557
558## Notification.addSlot
559
560addSlot(type: SlotType): Promise\<void\>
561
562创建指定类型的通知通道(Promise形式)。
563
564**系统能力**:SystemCapability.Notification.Notification
565
566**参数:**
567
568| 参数名 | 类型     | 必填 | 说明                   |
569| ---- | -------- | ---- | ---------------------- |
570| type | [SlotType](#slottype) | 是   | 要创建的通知通道的类型。 |
571
572**错误码:**
573
574错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
575
576| 错误码ID | 错误信息                            |
577| -------- | ----------------------------------- |
578| 1600001  | Internal error.                     |
579| 1600002  | Marshalling or unmarshalling error. |
580| 1600003  | Failed to connect service.          |
581
582**示例:**
583
584```js
585Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
586	console.info("addSlot success");
587});
588```
589
590
591
592## Notification.addSlots
593
594addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void
595
596创建多个通知通道(callback形式)。
597
598**系统能力**:SystemCapability.Notification.Notification
599
600**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
601
602**系统API**: 此接口为系统接口,三方应用不支持调用。
603
604**参数:**
605
606| 参数名     | 类型                      | 必填 | 说明                     |
607| -------- | ------------------------- | ---- | ------------------------ |
608| slots    | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 是   | 要创建的通知通道对象数组。 |
609| callback | AsyncCallback\<void\>     | 是   | 表示被指定的回调方法。     |
610
611**错误码:**
612
613错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
614
615| 错误码ID | 错误信息                            |
616| -------- | ----------------------------------- |
617| 1600001  | Internal error.                     |
618| 1600002  | Marshalling or unmarshalling error. |
619| 1600003  | Failed to connect service.          |
620
621**示例:**
622
623```js
624// addSlots回调
625function addSlotsCallBack(err) {
626    if (err) {
627        console.info("addSlots failed " + JSON.stringify(err));
628    } else {
629        console.info("addSlots success");
630    }
631}
632// 通知slot对象
633let notificationSlot = {
634    type: Notification.SlotType.SOCIAL_COMMUNICATION
635};
636// 通知slot array 对象
637let notificationSlotArray = new Array();
638notificationSlotArray[0] = notificationSlot;
639
640Notification.addSlots(notificationSlotArray, addSlotsCallBack);
641```
642
643
644
645## Notification.addSlots
646
647addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
648
649创建多个通知通道(Promise形式)。
650
651**系统能力**:SystemCapability.Notification.Notification
652
653**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
654
655**系统API**: 此接口为系统接口,三方应用不支持调用。
656
657**参数:**
658
659| 参数名  | 类型                      | 必填 | 说明                     |
660| ----- | ------------------------- | ---- | ------------------------ |
661| slots | Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 是   | 要创建的通知通道对象数组。 |
662
663**错误码:**
664
665错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
666
667| 错误码ID | 错误信息                            |
668| -------- | ----------------------------------- |
669| 1600001  | Internal error.                     |
670| 1600002  | Marshalling or unmarshalling error. |
671| 1600003  | Failed to connect service.          |
672
673**示例:**
674
675```js
676// 通知slot对象
677let notificationSlot = {
678    type: Notification.SlotType.SOCIAL_COMMUNICATION
679};
680// 通知slot array 对象
681let notificationSlotArray = new Array();
682notificationSlotArray[0] = notificationSlot;
683
684Notification.addSlots(notificationSlotArray).then(() => {
685	console.info("addSlots success");
686});
687```
688
689
690
691## Notification.getSlot
692
693getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
694
695获取一个指定类型的通知通道(callback形式)。
696
697**系统能力**:SystemCapability.Notification.Notification
698
699**参数:**
700
701| 参数名     | 类型                              | 必填 | 说明                                                        |
702| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
703| slotType | [SlotType](#slottype)                          | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
704| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 是   | 表示被指定的回调方法。                                        |
705
706**错误码:**
707
708错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
709
710| 错误码ID | 错误信息                            |
711| -------- | ----------------------------------- |
712| 1600001  | Internal error.                     |
713| 1600002  | Marshalling or unmarshalling error. |
714| 1600003  | Failed to connect service.          |
715
716**示例:**
717
718```js
719// getSlot回调
720function getSlotCallback(err,data) {
721    if (err) {
722        console.info("getSlot failed " + JSON.stringify(err));
723    } else {
724        console.info("getSlot success");
725    }
726}
727let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
728Notification.getSlot(slotType, getSlotCallback);
729```
730
731
732
733## Notification.getSlot
734
735getSlot(slotType: SlotType): Promise\<NotificationSlot\>
736
737获取一个指定类型的通知通道(Promise形式)。
738
739**系统能力**:SystemCapability.Notification.Notification
740
741**参数:**
742
743| 参数名     | 类型     | 必填 | 说明                                                        |
744| -------- | -------- | ---- | ----------------------------------------------------------- |
745| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
746
747**返回值:**
748
749| 类型                                                        | 说明                                                         |
750| ----------------------------------------------------------- | ------------------------------------------------------------ |
751| Promise\<NotificationSlot\> | 以Promise形式返回获取一个通知通道。 |
752
753**错误码:**
754
755错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
756
757| 错误码ID | 错误信息                            |
758| -------- | ----------------------------------- |
759| 1600001  | Internal error.                     |
760| 1600002  | Marshalling or unmarshalling error. |
761| 1600003  | Failed to connect service.          |
762
763**示例:**
764
765```js
766let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
767Notification.getSlot(slotType).then((data) => {
768	console.info("getSlot success, data: " + JSON.stringify(data));
769});
770```
771
772
773
774## Notification.getSlots
775
776getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>): void
777
778获取此应用程序的所有通知通道(callback形式)。
779
780**系统能力**:SystemCapability.Notification.Notification
781
782**参数:**
783
784| 参数名     | 类型                              | 必填 | 说明                 |
785| -------- | --------------------------------- | ---- | -------------------- |
786| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 是   | 以callback形式返回获取此应用程序的所有通知通道的结果。 |
787
788**错误码:**
789
790错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
791
792| 错误码ID | 错误信息                            |
793| -------- | ----------------------------------- |
794| 1600001  | Internal error.                     |
795| 1600002  | Marshalling or unmarshalling error. |
796| 1600003  | Failed to connect service.          |
797
798**示例:**
799
800```js
801// getSlots回调
802function getSlotsCallback(err,data) {
803    if (err) {
804        console.info("getSlots failed " + JSON.stringify(err));
805    } else {
806        console.info("getSlots success");
807    }
808}
809Notification.getSlots(getSlotsCallback);
810```
811
812
813
814## Notification.getSlots
815
816getSlots(): Promise\<Array\<NotificationSlot\>>
817
818获取此应用程序的所有通知通道(Promise形式)。
819
820**系统能力**:SystemCapability.Notification.Notification
821
822**返回值:**
823
824| 类型                                                        | 说明                                                         |
825| ----------------------------------------------------------- | ------------------------------------------------------------ |
826| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 以Promise形式返回获取此应用程序的所有通知通道的结果。 |
827
828**错误码:**
829
830错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
831
832| 错误码ID | 错误信息                            |
833| -------- | ----------------------------------- |
834| 1600001  | Internal error.                     |
835| 1600002  | Marshalling or unmarshalling error. |
836| 1600003  | Failed to connect service.          |
837
838**示例:**
839
840```js
841Notification.getSlots().then((data) => {
842	console.info("getSlots success, data: " + JSON.stringify(data));
843});
844```
845
846
847
848## Notification.removeSlot
849
850removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
851
852删除指定类型的通知通道(callback形式)。
853
854**系统能力**:SystemCapability.Notification.Notification
855
856**参数:**
857
858| 参数名     | 类型                  | 必填 | 说明                                                        |
859| -------- | --------------------- | ---- | ----------------------------------------------------------- |
860| slotType | [SlotType](#slottype)              | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
861| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。                                        |
862
863**错误码:**
864
865错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
866
867| 错误码ID | 错误信息                            |
868| -------- | ----------------------------------- |
869| 1600001  | Internal error.                     |
870| 1600002  | Marshalling or unmarshalling error. |
871| 1600003  | Failed to connect service.          |
872
873**示例:**
874
875```js
876// removeSlot回调
877function removeSlotCallback(err) {
878    if (err) {
879        console.info("removeSlot failed " + JSON.stringify(err));
880    } else {
881        console.info("removeSlot success");
882    }
883}
884let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
885Notification.removeSlot(slotType,removeSlotCallback);
886```
887
888
889
890## Notification.removeSlot
891
892removeSlot(slotType: SlotType): Promise\<void\>
893
894删除指定类型的通知通道(Promise形式)。
895
896**系统能力**:SystemCapability.Notification.Notification
897
898**参数:**
899
900| 参数名     | 类型     | 必填 | 说明                                                        |
901| -------- | -------- | ---- | ----------------------------------------------------------- |
902| slotType | [SlotType](#slottype) | 是   | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
903
904**错误码:**
905
906错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
907
908| 错误码ID | 错误信息                            |
909| -------- | ----------------------------------- |
910| 1600001  | Internal error.                     |
911| 1600002  | Marshalling or unmarshalling error. |
912| 1600003  | Failed to connect service.          |
913
914**示例:**
915
916```js
917let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
918Notification.removeSlot(slotType).then(() => {
919	console.info("removeSlot success");
920});
921```
922
923
924
925## Notification.removeAllSlots
926
927removeAllSlots(callback: AsyncCallback\<void\>): void
928
929删除所有通知通道(callback形式)。
930
931**系统能力**:SystemCapability.Notification.Notification
932
933**参数:**
934
935| 参数名     | 类型                  | 必填 | 说明                 |
936| -------- | --------------------- | ---- | -------------------- |
937| callback | AsyncCallback\<void\> | 是   | 表示被指定的回调方法。 |
938
939**错误码:**
940
941错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
942
943| 错误码ID | 错误信息                            |
944| -------- | ----------------------------------- |
945| 1600001  | Internal error.                     |
946| 1600002  | Marshalling or unmarshalling error. |
947| 1600003  | Failed to connect service.          |
948
949**示例:**
950
951```js
952function removeAllCallBack(err) {
953    if (err) {
954        console.info("removeAllSlots failed " + JSON.stringify(err));
955    } else {
956        console.info("removeAllSlots success");
957    }
958}
959Notification.removeAllSlots(removeAllCallBack);
960```
961
962
963
964## Notification.removeAllSlots
965
966removeAllSlots(): Promise\<void\>
967
968删除所有通知通道(Promise形式)。
969
970**系统能力**:SystemCapability.Notification.Notification
971
972**错误码:**
973
974错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
975
976| 错误码ID | 错误信息                            |
977| -------- | ----------------------------------- |
978| 1600001  | Internal error.                     |
979| 1600002  | Marshalling or unmarshalling error. |
980| 1600003  | Failed to connect service.          |
981
982**示例:**
983
984```js
985Notification.removeAllSlots().then(() => {
986	console.info("removeAllSlots success");
987});
988```
989
990
991
992## Notification.setNotificationEnable
993
994setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
995
996设定指定应用的通知使能状态(Callback形式)。
997
998**系统能力**:SystemCapability.Notification.Notification
999
1000**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1001
1002**系统API**: 此接口为系统接口,三方应用不支持调用。
1003
1004**参数:**
1005
1006| 参数名     | 类型                  | 必填 | 说明                 |
1007| -------- | --------------------- | ---- | -------------------- |
1008| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)   | 是   | 指定应用的包信息。        |
1009| enable   | boolean               | 是   | 使能状态。             |
1010| callback | AsyncCallback\<void\> | 是   | 设定通知使能回调函数。 |
1011
1012**错误码:**
1013
1014错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1015
1016| 错误码ID | 错误信息                                 |
1017| -------- | ---------------------------------------- |
1018| 1600001  | Internal error.                          |
1019| 1600002  | Marshalling or unmarshalling error.      |
1020| 1600003  | Failed to connect service.               |
1021| 17700001 | The specified bundle name was not found. |
1022
1023**示例:**
1024
1025```js
1026function setNotificationEnablenCallback(err) {
1027    if (err) {
1028        console.info("setNotificationEnablenCallback failed " + JSON.stringify(err));
1029    } else {
1030        console.info("setNotificationEnablenCallback success");
1031    }
1032}
1033let bundle = {
1034    bundle: "bundleName1",
1035};
1036Notification.setNotificationEnable(bundle, false, setNotificationEnablenCallback);
1037```
1038
1039
1040
1041## Notification.setNotificationEnable
1042
1043setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\>
1044
1045设定指定应用的通知使能状态(Promise形式)。
1046
1047**系统能力**:SystemCapability.Notification.Notification
1048
1049**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1050
1051**系统API**: 此接口为系统接口,三方应用不支持调用。
1052
1053**参数:**
1054
1055| 参数名   | 类型         | 必填 | 说明       |
1056| ------ | ------------ | ---- | ---------- |
1057| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1058| enable | boolean      | 是   | 使能状态。   |
1059
1060**错误码:**
1061
1062错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1063
1064| 错误码ID | 错误信息                                 |
1065| -------- | ---------------------------------------- |
1066| 1600001  | Internal error.                          |
1067| 1600002  | Marshalling or unmarshalling error.      |
1068| 1600003  | Failed to connect service.               |
1069| 17700001 | The specified bundle name was not found. |
1070
1071**示例:**
1072
1073```js
1074let bundle = {
1075    bundle: "bundleName1",
1076};
1077Notification.setNotificationEnable(bundle, false).then(() => {
1078	console.info("setNotificationEnable success");
1079});
1080```
1081
1082
1083
1084## Notification.isNotificationEnabled
1085
1086isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
1087
1088获取指定应用的通知使能状态(Callback形式)。
1089
1090**系统能力**:SystemCapability.Notification.Notification
1091
1092**系统API**:此接口为系统接口,三方应用不支持调用。
1093
1094**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1095
1096**参数:**
1097
1098| 参数名     | 类型                  | 必填 | 说明                     |
1099| -------- | --------------------- | ---- | ------------------------ |
1100| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | 是   | 指定应用的包信息。            |
1101| callback | AsyncCallback\<void\> | 是   | 获取通知使能状态回调函数。 |
1102
1103**错误码:**
1104
1105错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1106
1107| 错误码ID | 错误信息                                 |
1108| -------- | ---------------------------------------- |
1109| 1600001  | Internal error.                          |
1110| 1600002  | Marshalling or unmarshalling error.      |
1111| 1600003  | Failed to connect service.               |
1112| 17700001 | The specified bundle name was not found. |
1113
1114**示例:**
1115
1116```js
1117function isNotificationEnabledCallback(err, data) {
1118    if (err) {
1119        console.info("isNotificationEnabled failed " + JSON.stringify(err));
1120    } else {
1121        console.info("isNotificationEnabled success");
1122    }
1123}
1124let bundle = {
1125    bundle: "bundleName1",
1126};
1127Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
1128```
1129
1130
1131
1132## Notification.isNotificationEnabled
1133
1134isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
1135
1136获取指定应用的通知使能状态(Promise形式)。
1137
1138**系统能力**:SystemCapability.Notification.Notification
1139
1140**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1141
1142**系统API**: 此接口为系统接口,三方应用不支持调用。
1143
1144**参数:**
1145
1146| 参数名   | 类型         | 必填 | 说明       |
1147| ------ | ------------ | ---- | ---------- |
1148| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1149
1150**返回值:**
1151
1152| 类型               | 说明                                                |
1153| ------------------ | --------------------------------------------------- |
1154| Promise\<boolean\> | 以Promise形式返回获取指定应用的通知使能状态的结果。 |
1155
1156**错误码:**
1157
1158错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1159
1160| 错误码ID | 错误信息                                 |
1161| -------- | ---------------------------------------- |
1162| 1600001  | Internal error.                          |
1163| 1600002  | Marshalling or unmarshalling error.      |
1164| 1600003  | Failed to connect service.               |
1165| 17700001 | The specified bundle name was not found. |
1166
1167**示例:**
1168
1169```js
1170let bundle = {
1171    bundle: "bundleName1",
1172};
1173Notification.isNotificationEnabled(bundle).then((data) => {
1174	console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
1175});
1176```
1177
1178
1179
1180## Notification.isNotificationEnabled
1181
1182isNotificationEnabled(callback: AsyncCallback\<boolean\>): void
1183
1184获取通知使能状态(Callback形式)。
1185
1186**系统能力**:SystemCapability.Notification.Notification
1187
1188**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1189
1190**系统API**: 此接口为系统接口,三方应用不支持调用。
1191
1192**参数:**
1193
1194| 参数名     | 类型                  | 必填 | 说明                     |
1195| -------- | --------------------- | ---- | ------------------------ |
1196| callback | AsyncCallback\<void\> | 是   | 获取通知使能状态回调函数。 |
1197
1198**错误码:**
1199
1200错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1201
1202| 错误码ID | 错误信息                            |
1203| -------- | ----------------------------------- |
1204| 1600001  | Internal error.                     |
1205| 1600002  | Marshalling or unmarshalling error. |
1206| 1600003  | Failed to connect service.          |
1207
1208**示例:**
1209
1210```js
1211function isNotificationEnabledCallback(err, data) {
1212    if (err) {
1213        console.info("isNotificationEnabled failed " + JSON.stringify(err));
1214    } else {
1215        console.info("isNotificationEnabled success");
1216    }
1217}
1218
1219Notification.isNotificationEnabled(isNotificationEnabledCallback);
1220```
1221
1222
1223
1224## Notification.isNotificationEnabled
1225
1226isNotificationEnabled(): Promise\<boolean\>
1227
1228获取通知使能状态(Promise形式)。
1229
1230**系统能力**:SystemCapability.Notification.Notification
1231
1232**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1233
1234**系统API**: 此接口为系统接口,三方应用不支持调用。
1235
1236**参数:**
1237
1238| 参数名   | 类型         | 必填 | 说明       |
1239| ------ | ------------ | ---- | ---------- |
1240| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1241
1242**返回值:**
1243
1244| 类型                                                        | 说明                                                         |
1245| ----------------------------------------------------------- | ------------------------------------------------------------ |
1246| Promise\<boolean\> | 以Promise形式返回获取通知使能状态的结果。 |
1247
1248**错误码:**
1249
1250错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1251
1252| 错误码ID | 错误信息                                 |
1253| -------- | ---------------------------------------- |
1254| 1600001  | Internal error.                          |
1255| 1600002  | Marshalling or unmarshalling error.      |
1256| 1600003  | Failed to connect service.               |
1257| 17700001 | The specified bundle name was not found. |
1258
1259**示例:**
1260
1261```js
1262Notification.isNotificationEnabled().then((data) => {
1263	console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
1264});
1265```
1266
1267
1268
1269## Notification.displayBadge
1270
1271displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
1272
1273设定指定应用的角标使能状态(Callback形式)。
1274
1275**系统能力**:SystemCapability.Notification.Notification
1276
1277**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1278
1279**系统API**: 此接口为系统接口,三方应用不支持调用。
1280
1281**参数:**
1282
1283| 参数名     | 类型                  | 必填 | 说明                 |
1284| -------- | --------------------- | ---- | -------------------- |
1285| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | 是   | 指定应用的包信息。           |
1286| enable   | boolean               | 是   | 使能状态。             |
1287| callback | AsyncCallback\<void\> | 是   | 设定角标使能回调函数。 |
1288
1289**错误码:**
1290
1291错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1292
1293| 错误码ID | 错误信息                                 |
1294| -------- | ---------------------------------------- |
1295| 1600001  | Internal error.                          |
1296| 1600002  | Marshalling or unmarshalling error.      |
1297| 1600003  | Failed to connect service.               |
1298| 17700001 | The specified bundle name was not found. |
1299
1300**示例:**
1301
1302```js
1303function displayBadgeCallback(err) {
1304    if (err) {
1305        console.info("displayBadge failed " + JSON.stringify(err));
1306    } else {
1307        console.info("displayBadge success");
1308    }
1309}
1310let bundle = {
1311    bundle: "bundleName1",
1312};
1313Notification.displayBadge(bundle, false, displayBadgeCallback);
1314```
1315
1316
1317
1318## Notification.displayBadge
1319
1320displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>
1321
1322设定指定应用的角标使能状态(Promise形式)。
1323
1324**系统能力**:SystemCapability.Notification.Notification
1325
1326**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1327
1328**系统API**: 此接口为系统接口,三方应用不支持调用。
1329
1330**参数:**
1331
1332| 参数名   | 类型         | 必填 | 说明       |
1333| ------ | ------------ | ---- | ---------- |
1334| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1335| enable | boolean      | 是   | 使能状态。   |
1336
1337**错误码:**
1338
1339错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1340
1341| 错误码ID | 错误信息                                 |
1342| -------- | ---------------------------------------- |
1343| 1600001  | Internal error.                          |
1344| 1600002  | Marshalling or unmarshalling error.      |
1345| 1600003  | Failed to connect service.               |
1346| 17700001 | The specified bundle name was not found. |
1347
1348**示例:**
1349
1350```js
1351let bundle = {
1352    bundle: "bundleName1",
1353};
1354Notification.displayBadge(bundle, false).then(() => {
1355	console.info("displayBadge success");
1356});
1357```
1358
1359
1360
1361## Notification.isBadgeDisplayed
1362
1363isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
1364
1365获取指定应用的角标使能状态(Callback形式)。
1366
1367**系统能力**:SystemCapability.Notification.Notification
1368
1369**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1370
1371**系统API**: 此接口为系统接口,三方应用不支持调用。
1372
1373**参数:**
1374
1375| 参数名     | 类型                  | 必填 | 说明                     |
1376| -------- | --------------------- | ---- | ------------------------ |
1377| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | 是   | 指定应用的包信息。               |
1378| callback | AsyncCallback\<void\> | 是   | 获取角标使能状态回调函数。 |
1379
1380**错误码:**
1381
1382错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1383
1384| 错误码ID | 错误信息                                 |
1385| -------- | ---------------------------------------- |
1386| 1600001  | Internal error.                          |
1387| 1600002  | Marshalling or unmarshalling error.      |
1388| 1600003  | Failed to connect service.               |
1389| 17700001 | The specified bundle name was not found. |
1390
1391**示例:**
1392
1393```js
1394function isBadgeDisplayedCallback(err, data) {
1395    if (err) {
1396        console.info("isBadgeDisplayed failed " + JSON.stringify(err));
1397    } else {
1398        console.info("isBadgeDisplayed success");
1399    }
1400}
1401let bundle = {
1402    bundle: "bundleName1",
1403};
1404Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
1405```
1406
1407
1408
1409## Notification.isBadgeDisplayed
1410
1411isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
1412
1413获取指定应用的角标使能状态(Promise形式)。
1414
1415**系统能力**:SystemCapability.Notification.Notification
1416
1417**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1418
1419**系统API**: 此接口为系统接口,三方应用不支持调用。
1420
1421**参数:**
1422
1423| 参数名   | 类型         | 必填 | 说明       |
1424| ------ | ------------ | ---- | ---------- |
1425| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1426
1427**返回值:**
1428
1429| 类型                                                        | 说明                                                         |
1430| ----------------------------------------------------------- | ------------------------------------------------------------ |
1431| Promise\<boolean\> | 以Promise形式返回获取指定应用的角标使能状态。 |
1432
1433**错误码:**
1434
1435错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1436
1437| 错误码ID | 错误信息                                 |
1438| -------- | ---------------------------------------- |
1439| 1600001  | Internal error.                          |
1440| 1600002  | Marshalling or unmarshalling error.      |
1441| 1600003  | Failed to connect service.               |
1442| 17700001 | The specified bundle name was not found. |
1443
1444**示例:**
1445
1446```js
1447let bundle = {
1448    bundle: "bundleName1",
1449};
1450Notification.isBadgeDisplayed(bundle).then((data) => {
1451	console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
1452});
1453```
1454
1455
1456
1457## Notification.setSlotByBundle
1458
1459setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void
1460
1461设定指定应用的通知通道(Callback形式)。
1462
1463**系统能力**:SystemCapability.Notification.Notification
1464
1465**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1466
1467**系统API**: 此接口为系统接口,三方应用不支持调用。
1468
1469**参数:**
1470
1471| 参数名     | 类型                  | 必填 | 说明                 |
1472| -------- | --------------------- | ---- | -------------------- |
1473| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | 是   | 指定应用的包信息。           |
1474| slot     | [NotificationSlot](js-apis-inner-notification-notificationSlot.md)      | 是   | 通知通道。             |
1475| callback | AsyncCallback\<void\> | 是   | 设定通知通道回调函数。 |
1476
1477**错误码:**
1478
1479错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1480
1481| 错误码ID | 错误信息                                 |
1482| -------- | ---------------------------------------- |
1483| 1600001  | Internal error.                          |
1484| 1600002  | Marshalling or unmarshalling error.      |
1485| 1600003  | Failed to connect service.               |
1486| 17700001 | The specified bundle name was not found. |
1487
1488
1489
1490**示例:**
1491
1492```js
1493function setSlotByBundleCallback(err) {
1494    if (err) {
1495        console.info("setSlotByBundle failed " + JSON.stringify(err));
1496    } else {
1497        console.info("setSlotByBundle success");
1498    }
1499}
1500let bundle = {
1501    bundle: "bundleName1",
1502};
1503let notificationSlot = {
1504    type: Notification.SlotType.SOCIAL_COMMUNICATION
1505};
1506Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
1507```
1508
1509
1510
1511## Notification.setSlotByBundle
1512
1513setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
1514
1515设定指定应用的通知通道(Promise形式)。
1516
1517**系统能力**:SystemCapability.Notification.Notification
1518
1519**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1520
1521**系统API**: 此接口为系统接口,三方应用不支持调用。
1522
1523**参数:**
1524
1525| 参数名   | 类型         | 必填 | 说明       |
1526| ------ | ------------ | ---- | ---------- |
1527| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1528| slot   | [NotificationSlot](js-apis-inner-notification-notificationSlot.md) | 是   | 通知通道。 |
1529
1530**错误码:**
1531
1532错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1533
1534| 错误码ID | 错误信息                                 |
1535| -------- | ---------------------------------------- |
1536| 1600001  | Internal error.                          |
1537| 1600002  | Marshalling or unmarshalling error.      |
1538| 1600003  | Failed to connect service.               |
1539| 17700001 | The specified bundle name was not found. |
1540
1541**示例:**
1542
1543```js
1544let bundle = {
1545    bundle: "bundleName1",
1546};
1547let notificationSlot = {
1548    type: Notification.SlotType.SOCIAL_COMMUNICATION
1549};
1550Notification.setSlotByBundle(bundle, notificationSlot).then(() => {
1551	console.info("setSlotByBundle success");
1552});
1553```
1554
1555
1556
1557## Notification.getSlotsByBundle
1558
1559getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>): void
1560
1561获取指定应用的所有通知通道(Callback形式)。
1562
1563**系统能力**:SystemCapability.Notification.Notification
1564
1565**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1566
1567**系统API**: 此接口为系统接口,三方应用不支持调用。
1568
1569**参数:**
1570
1571| 参数名     | 类型                                     | 必填 | 说明                 |
1572| -------- | ---------------------------------------- | ---- | -------------------- |
1573| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)                             | 是   | 指定应用的包信息。           |
1574| callback | AsyncCallback<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>> | 是   | 获取通知通道回调函数。 |
1575
1576**错误码:**
1577
1578错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1579
1580| 错误码ID | 错误信息                                 |
1581| -------- | ---------------------------------------- |
1582| 1600001  | Internal error.                          |
1583| 1600002  | Marshalling or unmarshalling error.      |
1584| 1600003  | Failed to connect service.               |
1585| 17700001 | The specified bundle name was not found. |
1586
1587**示例:**
1588
1589```js
1590function getSlotsByBundleCallback(err, data) {
1591    if (err) {
1592        console.info("getSlotsByBundle failed " + JSON.stringify(err));
1593    } else {
1594        console.info("getSlotsByBundle success");
1595    }
1596}
1597let bundle = {
1598    bundle: "bundleName1",
1599};
1600Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
1601```
1602
1603
1604
1605## Notification.getSlotsByBundle
1606
1607getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>>
1608
1609获取指定应用的所有通知通道(Promise形式)。
1610
1611**系统能力**:SystemCapability.Notification.Notification
1612
1613**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1614
1615**系统API**: 此接口为系统接口,三方应用不支持调用。
1616
1617**参数:**
1618
1619| 参数名   | 类型         | 必填 | 说明       |
1620| ------ | ------------ | ---- | ---------- |
1621| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1622
1623**返回值:**
1624
1625| 类型                                                        | 说明                                                         |
1626| ----------------------------------------------------------- | ------------------------------------------------------------ |
1627| Promise<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>> | 以Promise形式返回获取指定应用的通知通道。 |
1628
1629**错误码:**
1630
1631错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1632
1633| 错误码ID | 错误信息                                 |
1634| -------- | ---------------------------------------- |
1635| 1600001  | Internal error.                          |
1636| 1600002  | Marshalling or unmarshalling error.      |
1637| 1600003  | Failed to connect service.               |
1638| 17700001 | The specified bundle name was not found. |
1639
1640**示例:**
1641
1642```js
1643let bundle = {
1644    bundle: "bundleName1",
1645};
1646Notification.getSlotsByBundle(bundle).then((data) => {
1647	console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
1648});
1649```
1650
1651
1652
1653## Notification.getSlotNumByBundle
1654
1655getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void
1656
1657获取指定应用的通知通道数量(Callback形式)。
1658
1659**系统能力**:SystemCapability.Notification.Notification
1660
1661**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1662
1663**系统API**: 此接口为系统接口,三方应用不支持调用。
1664
1665**参数:**
1666
1667| 参数名     | 类型                      | 必填 | 说明                   |
1668| -------- | ------------------------- | ---- | ---------------------- |
1669| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)              | 是   | 指定应用的包信息。             |
1670| callback | AsyncCallback\<number\> | 是   | 获取通知通道数量回调函数。 |
1671
1672**错误码:**
1673
1674错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1675
1676| 错误码ID | 错误信息                                 |
1677| -------- | ---------------------------------------- |
1678| 1600001  | Internal error.                          |
1679| 1600002  | Marshalling or unmarshalling error.      |
1680| 1600003  | Failed to connect service.               |
1681| 17700001 | The specified bundle name was not found. |
1682
1683**示例:**
1684
1685```js
1686function getSlotNumByBundleCallback(err, data) {
1687    if (err) {
1688        console.info("getSlotNumByBundle failed " + JSON.stringify(err));
1689    } else {
1690        console.info("getSlotNumByBundle success");
1691    }
1692}
1693let bundle = {
1694    bundle: "bundleName1",
1695};
1696Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
1697```
1698
1699
1700
1701## Notification.getSlotNumByBundle
1702
1703getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
1704
1705获取指定应用的通知通道数量(Promise形式)。
1706
1707**系统能力**:SystemCapability.Notification.Notification
1708
1709**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1710
1711**系统API**: 此接口为系统接口,三方应用不支持调用。
1712
1713**参数:**
1714
1715| 参数名   | 类型         | 必填 | 说明       |
1716| ------ | ------------ | ---- | ---------- |
1717| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 指定应用的包信息。 |
1718
1719**返回值:**
1720
1721| 类型                                                        | 说明                                                         |
1722| ----------------------------------------------------------- | ------------------------------------------------------------ |
1723| Promise\<number\> | 以Promise形式返回获取指定应用的通知通道数量。 |
1724
1725**错误码:**
1726
1727错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1728
1729| 错误码ID | 错误信息                                 |
1730| -------- | ---------------------------------------- |
1731| 1600001  | Internal error.                          |
1732| 1600002  | Marshalling or unmarshalling error.      |
1733| 1600003  | Failed to connect service.               |
1734| 17700001 | The specified bundle name was not found. |
1735
1736**示例:**
1737
1738```js
1739let bundle = {
1740    bundle: "bundleName1",
1741};
1742Notification.getSlotNumByBundle(bundle).then((data) => {
1743	console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
1744});
1745```
1746
1747
1748
1749
1750## Notification.getAllActiveNotifications
1751
1752getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
1753
1754获取当前未删除的所有通知(Callback形式)。
1755
1756**系统能力**:SystemCapability.Notification.Notification
1757
1758**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1759
1760**系统API**: 此接口为系统接口,三方应用不支持调用。
1761
1762**参数:**
1763
1764| 参数名     | 类型                                                         | 必填 | 说明                 |
1765| -------- | ------------------------------------------------------------ | ---- | -------------------- |
1766| callback | AsyncCallback<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>> | 是   | 获取活动通知回调函数。 |
1767
1768**错误码:**
1769
1770错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1771
1772| 错误码ID | 错误信息                            |
1773| -------- | ----------------------------------- |
1774| 1600001  | Internal error.                     |
1775| 1600002  | Marshalling or unmarshalling error. |
1776| 1600003  | Failed to connect service.          |
1777
1778**示例:**
1779
1780```js
1781function getAllActiveNotificationsCallback(err, data) {
1782    if (err) {
1783        console.info("getAllActiveNotifications failed " + JSON.stringify(err));
1784    } else {
1785        console.info("getAllActiveNotifications success");
1786    }
1787}
1788
1789Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
1790```
1791
1792
1793
1794## Notification.getAllActiveNotifications
1795
1796getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\>
1797
1798获取当前未删除的所有通知(Promise形式)。
1799
1800**系统能力**:SystemCapability.Notification.Notification
1801
1802**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
1803
1804**系统API**: 此接口为系统接口,三方应用不支持调用。
1805
1806**返回值:**
1807
1808| 类型                                                        | 说明                                                         |
1809| ----------------------------------------------------------- | ------------------------------------------------------------ |
1810| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | 以Promise形式返回获取活动通知。 |
1811
1812**错误码:**
1813
1814错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1815
1816| 错误码ID | 错误信息                            |
1817| -------- | ----------------------------------- |
1818| 1600001  | Internal error.                     |
1819| 1600002  | Marshalling or unmarshalling error. |
1820| 1600003  | Failed to connect service.          |
1821
1822**示例:**
1823
1824```js
1825Notification.getAllActiveNotifications().then((data) => {
1826	console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
1827});
1828```
1829
1830
1831
1832## Notification.getActiveNotificationCount
1833
1834getActiveNotificationCount(callback: AsyncCallback\<number\>): void
1835
1836获取当前应用未删除的通知数(Callback形式)。
1837
1838**系统能力**:SystemCapability.Notification.Notification
1839
1840**参数:**
1841
1842| 参数名     | 类型                   | 必填 | 说明                   |
1843| -------- | ---------------------- | ---- | ---------------------- |
1844| callback | AsyncCallback\<number\> | 是   | 获取未删除通知数回调函数。 |
1845
1846**错误码:**
1847
1848错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1849
1850| 错误码ID | 错误信息                            |
1851| -------- | ----------------------------------- |
1852| 1600001  | Internal error.                     |
1853| 1600002  | Marshalling or unmarshalling error. |
1854| 1600003  | Failed to connect service.          |
1855
1856**示例:**
1857
1858```js
1859function getActiveNotificationCountCallback(err, data) {
1860    if (err) {
1861        console.info("getActiveNotificationCount failed " + JSON.stringify(err));
1862    } else {
1863        console.info("getActiveNotificationCount success");
1864    }
1865}
1866
1867Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
1868```
1869
1870
1871
1872## Notification.getActiveNotificationCount
1873
1874getActiveNotificationCount(): Promise\<number\>
1875
1876获取当前应用未删除的通知数(Promise形式)。
1877
1878**系统能力**:SystemCapability.Notification.Notification
1879
1880**返回值:**
1881
1882| 类型              | 说明                                        |
1883| ----------------- | ------------------------------------------- |
1884| Promise\<number\> | 以Promise形式返回获取当前应用未删除通知数。 |
1885
1886**错误码:**
1887
1888错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1889
1890| 错误码ID | 错误信息                            |
1891| -------- | ----------------------------------- |
1892| 1600001  | Internal error.                     |
1893| 1600002  | Marshalling or unmarshalling error. |
1894| 1600003  | Failed to connect service.          |
1895
1896**示例:**
1897
1898```js
1899Notification.getActiveNotificationCount().then((data) => {
1900	console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
1901});
1902```
1903
1904
1905
1906## Notification.getActiveNotifications
1907
1908getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
1909
1910获取当前应用未删除的通知列表(Callback形式)。
1911
1912**系统能力**:SystemCapability.Notification.Notification
1913
1914**参数:**
1915
1916| 参数名     | 类型                                                         | 必填 | 说明                           |
1917| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
1918| callback | AsyncCallback<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>> | 是   | 获取当前应用通知列表回调函数。 |
1919
1920**错误码:**
1921
1922错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1923
1924| 错误码ID | 错误信息                            |
1925| -------- | ----------------------------------- |
1926| 1600001  | Internal error.                     |
1927| 1600002  | Marshalling or unmarshalling error. |
1928| 1600003  | Failed to connect service.          |
1929
1930**示例:**
1931
1932```js
1933function getActiveNotificationsCallback(err, data) {
1934    if (err) {
1935        console.info("getActiveNotifications failed " + JSON.stringify(err));
1936    } else {
1937        console.info("getActiveNotifications success");
1938    }
1939}
1940
1941Notification.getActiveNotifications(getActiveNotificationsCallback);
1942```
1943
1944
1945
1946## Notification.getActiveNotifications
1947
1948getActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\>
1949
1950获取当前应用未删除的通知列表(Promise形式)。
1951
1952**系统能力**:SystemCapability.Notification.Notification
1953
1954**返回值:**
1955
1956| 类型                                                         | 说明                                    |
1957| ------------------------------------------------------------ | --------------------------------------- |
1958| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | 以Promise形式返回获取当前应用通知列表。 |
1959
1960**错误码:**
1961
1962错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1963
1964| 错误码ID | 错误信息                            |
1965| -------- | ----------------------------------- |
1966| 1600001  | Internal error.                     |
1967| 1600002  | Marshalling or unmarshalling error. |
1968| 1600003  | Failed to connect service.          |
1969
1970**示例:**
1971
1972```js
1973Notification.getActiveNotifications().then((data) => {
1974	console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
1975});
1976```
1977
1978
1979
1980## Notification.cancelGroup
1981
1982cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
1983
1984取消本应用指定组下的通知(Callback形式)。
1985
1986**系统能力**:SystemCapability.Notification.Notification
1987
1988**参数:**
1989
1990| 参数名      | 类型                  | 必填 | 说明                         |
1991| --------- | --------------------- | ---- | ---------------------------- |
1992| groupName | string                | 是   | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象指定。 |
1993| callback  | AsyncCallback\<void\> | 是   | 取消本应用指定组下通知的回调函数。 |
1994
1995**错误码:**
1996
1997错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
1998
1999| 错误码ID | 错误信息                            |
2000| -------- | ----------------------------------- |
2001| 1600001  | Internal error.                     |
2002| 1600002  | Marshalling or unmarshalling error. |
2003| 1600003  | Failed to connect service.          |
2004
2005**示例:**
2006
2007```js
2008function cancelGroupCallback(err) {
2009    if (err) {
2010        console.info("cancelGroup failed " + JSON.stringify(err));
2011    } else {
2012        console.info("cancelGroup success");
2013    }
2014}
2015
2016let groupName = "GroupName";
2017
2018Notification.cancelGroup(groupName, cancelGroupCallback);
2019```
2020
2021
2022
2023## Notification.cancelGroup
2024
2025cancelGroup(groupName: string): Promise\<void\>
2026
2027取消本应用指定组下的通知(Promise形式)。
2028
2029**系统能力**:SystemCapability.Notification.Notification
2030
2031**参数:**
2032
2033| 参数名      | 类型   | 必填 | 说明           |
2034| --------- | ------ | ---- | -------------- |
2035| groupName | string | 是   | 通知组名称。 |
2036
2037**错误码:**
2038
2039错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2040
2041| 错误码ID | 错误信息                            |
2042| -------- | ----------------------------------- |
2043| 1600001  | Internal error.                     |
2044| 1600002  | Marshalling or unmarshalling error. |
2045| 1600003  | Failed to connect service.          |
2046
2047**示例:**
2048
2049```js
2050let groupName = "GroupName";
2051Notification.cancelGroup(groupName).then(() => {
2052	console.info("cancelGroup success");
2053});
2054```
2055
2056
2057
2058## Notification.removeGroupByBundle
2059
2060removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void
2061
2062删除指定应用的指定组下的通知(Callback形式)。
2063
2064**系统能力**:SystemCapability.Notification.Notification
2065
2066**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2067
2068**系统API**: 此接口为系统接口,三方应用不支持调用。
2069
2070**参数:**
2071
2072| 参数名      | 类型                  | 必填 | 说明                         |
2073| --------- | --------------------- | ---- | ---------------------------- |
2074| bundle    | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)          | 是   | 应用的包信息。                   |
2075| groupName | string                | 是   | 通知组名称。               |
2076| callback  | AsyncCallback\<void\> | 是   | 删除指定应用指定组下通知的回调函数。 |
2077
2078**错误码:**
2079
2080错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2081
2082| 错误码ID | 错误信息                                 |
2083| -------- | ---------------------------------------- |
2084| 1600001  | Internal error.                          |
2085| 1600002  | Marshalling or unmarshalling error.      |
2086| 1600003  | Failed to connect service.               |
2087| 17700001 | The specified bundle name was not found. |
2088
2089**示例:**
2090
2091```js
2092function removeGroupByBundleCallback(err) {
2093    if (err) {
2094        console.info("removeGroupByBundle failed " + JSON.stringify(err));
2095    } else {
2096        console.info("removeGroupByBundle success");
2097    }
2098}
2099
2100let bundleOption = {bundle: "Bundle"};
2101let groupName = "GroupName";
2102
2103Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);
2104```
2105
2106
2107
2108## Notification.removeGroupByBundle
2109
2110removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
2111
2112删除指定应用的指定组下的通知(Promise形式)。
2113
2114**系统能力**:SystemCapability.Notification.Notification
2115
2116**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2117
2118**系统API**: 此接口为系统接口,三方应用不支持调用。
2119
2120**参数:**
2121
2122| 参数名      | 类型         | 必填 | 说明           |
2123| --------- | ------------ | ---- | -------------- |
2124| bundle    | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 应用的包信息。     |
2125| groupName | string       | 是   | 通知组名称。 |
2126
2127**错误码:**
2128
2129错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2130
2131| 错误码ID | 错误信息                                 |
2132| -------- | ---------------------------------------- |
2133| 1600001  | Internal error.                          |
2134| 1600002  | Marshalling or unmarshalling error.      |
2135| 1600003  | Failed to connect service.               |
2136| 17700001 | The specified bundle name was not found. |
2137
2138**示例:**
2139
2140```js
2141let bundleOption = {bundle: "Bundle"};
2142let groupName = "GroupName";
2143Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
2144	console.info("removeGroupByBundle success");
2145});
2146```
2147
2148
2149
2150## Notification.setDoNotDisturbDate
2151
2152setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void
2153
2154设置免打扰时间(Callback形式)。
2155
2156**系统能力**:SystemCapability.Notification.Notification
2157
2158**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2159
2160**系统API**: 此接口为系统接口,三方应用不支持调用。
2161
2162**参数:**
2163
2164| 参数名     | 类型                  | 必填 | 说明                   |
2165| -------- | --------------------- | ---- | ---------------------- |
2166| date     | [DoNotDisturbDate](#donotdisturbdate)      | 是   | 免打扰时间选项。         |
2167| callback | AsyncCallback\<void\> | 是   | 设置免打扰时间回调函数。 |
2168
2169**错误码:**
2170
2171错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2172
2173| 错误码ID | 错误信息                            |
2174| -------- | ----------------------------------- |
2175| 1600001  | Internal error.                     |
2176| 1600002  | Marshalling or unmarshalling error. |
2177| 1600003  | Failed to connect service.          |
2178
2179**示例:**
2180
2181```js
2182function setDoNotDisturbDateCallback(err) {
2183    if (err) {
2184        console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
2185    } else {
2186        console.info("setDoNotDisturbDate success");
2187    }
2188}
2189
2190let doNotDisturbDate = {
2191    type: Notification.DoNotDisturbType.TYPE_ONCE,
2192    begin: new Date(),
2193    end: new Date(2021, 11, 15, 18, 0)
2194};
2195
2196Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
2197```
2198
2199
2200
2201## Notification.setDoNotDisturbDate
2202
2203setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
2204
2205设置免打扰时间(Promise形式)。
2206
2207**系统能力**:SystemCapability.Notification.Notification
2208
2209**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2210
2211**系统API**: 此接口为系统接口,三方应用不支持调用。
2212
2213**参数:**
2214
2215| 参数名 | 类型             | 必填 | 说明           |
2216| ---- | ---------------- | ---- | -------------- |
2217| date | [DoNotDisturbDate](#donotdisturbdate) | 是   | 免打扰时间选项。 |
2218
2219**错误码:**
2220
2221错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2222
2223| 错误码ID | 错误信息                            |
2224| -------- | ----------------------------------- |
2225| 1600001  | Internal error.                     |
2226| 1600002  | Marshalling or unmarshalling error. |
2227| 1600003  | Failed to connect service.          |
2228
2229**示例:**
2230
2231```js
2232let doNotDisturbDate = {
2233    type: Notification.DoNotDisturbType.TYPE_ONCE,
2234    begin: new Date(),
2235    end: new Date(2021, 11, 15, 18, 0)
2236};
2237Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
2238	console.info("setDoNotDisturbDate success");
2239});
2240```
2241
2242
2243## Notification.setDoNotDisturbDate
2244
2245setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): void
2246
2247指定用户设置免打扰时间(Callback形式)。
2248
2249**系统能力**:SystemCapability.Notification.Notification
2250
2251**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2252
2253**系统API**: 此接口为系统接口,三方应用不支持调用。
2254
2255**参数:**
2256
2257| 参数名     | 类型                  | 必填 | 说明                   |
2258| -------- | --------------------- | ---- | ---------------------- |
2259| date     | [DoNotDisturbDate](#donotdisturbdate)      | 是   | 免打扰时间选项。         |
2260| userId   | number                | 是   | 设置免打扰时间的用户ID。 |
2261| callback | AsyncCallback\<void\> | 是   | 设置免打扰时间回调函数。 |
2262
2263**错误码:**
2264
2265错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2266
2267| 错误码ID | 错误信息                            |
2268| -------- | ----------------------------------- |
2269| 1600001  | Internal error.                     |
2270| 1600002  | Marshalling or unmarshalling error. |
2271| 1600003  | Failed to connect service.          |
2272| 1600008  | The user is not exist.              |
2273
2274**示例:**
2275
2276```js
2277function setDoNotDisturbDateCallback(err) {
2278    if (err) {
2279        console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
2280    } else {
2281        console.info("setDoNotDisturbDate success");
2282    }
2283}
2284
2285let doNotDisturbDate = {
2286    type: Notification.DoNotDisturbType.TYPE_ONCE,
2287    begin: new Date(),
2288    end: new Date(2021, 11, 15, 18, 0)
2289};
2290
2291let userId = 1;
2292
2293Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);
2294```
2295
2296
2297
2298## Notification.setDoNotDisturbDate
2299
2300setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
2301
2302指定用户设置免打扰时间(Promise形式)。
2303
2304**系统能力**:SystemCapability.Notification.Notification
2305
2306**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2307
2308**系统API**: 此接口为系统接口,三方应用不支持调用。
2309
2310**参数:**
2311
2312| 参数名   | 类型             | 必填 | 说明           |
2313| ------ | ---------------- | ---- | -------------- |
2314| date   | [DoNotDisturbDate](#donotdisturbdate) | 是   | 免打扰时间选项。 |
2315| userId | number           | 是   | 设置免打扰时间的用户ID。 |
2316
2317**错误码:**
2318
2319错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2320
2321| 错误码ID | 错误信息                            |
2322| -------- | ----------------------------------- |
2323| 1600001  | Internal error.                     |
2324| 1600002  | Marshalling or unmarshalling error. |
2325| 1600003  | Failed to connect service.          |
2326| 1600008  | The user is not exist.              |
2327
2328**示例:**
2329
2330```js
2331let doNotDisturbDate = {
2332    type: Notification.DoNotDisturbType.TYPE_ONCE,
2333    begin: new Date(),
2334    end: new Date(2021, 11, 15, 18, 0)
2335};
2336
2337let userId = 1;
2338
2339Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
2340	console.info("setDoNotDisturbDate success");
2341});
2342```
2343
2344
2345## Notification.getDoNotDisturbDate
2346
2347getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
2348
2349查询免打扰时间(Callback形式)。
2350
2351**系统能力**:SystemCapability.Notification.Notification
2352
2353**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2354
2355**系统API**: 此接口为系统接口,三方应用不支持调用。
2356
2357**参数:**
2358
2359| 参数名     | 类型                              | 必填 | 说明                   |
2360| -------- | --------------------------------- | ---- | ---------------------- |
2361| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | 是   | 查询免打扰时间回调函数。 |
2362
2363**错误码:**
2364
2365错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2366
2367| 错误码ID | 错误信息                            |
2368| -------- | ----------------------------------- |
2369| 1600001  | Internal error.                     |
2370| 1600002  | Marshalling or unmarshalling error. |
2371| 1600003  | Failed to connect service.          |
2372
2373**示例:**
2374
2375```js
2376function getDoNotDisturbDateCallback(err,data) {
2377    if (err) {
2378        console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
2379    } else {
2380        console.info("getDoNotDisturbDate success");
2381    }
2382}
2383
2384Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
2385```
2386
2387
2388
2389## Notification.getDoNotDisturbDate
2390
2391getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
2392
2393查询免打扰时间(Promise形式)。
2394
2395**系统能力**:SystemCapability.Notification.Notification
2396
2397**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2398
2399**系统API**: 此接口为系统接口,三方应用不支持调用。
2400
2401**返回值:**
2402
2403| 类型                                             | 说明                                      |
2404| ------------------------------------------------ | ----------------------------------------- |
2405| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | 以Promise形式返回获取查询到的免打扰时间。 |
2406
2407**错误码:**
2408
2409错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2410
2411| 错误码ID | 错误信息                            |
2412| -------- | ----------------------------------- |
2413| 1600001  | Internal error.                     |
2414| 1600002  | Marshalling or unmarshalling error. |
2415| 1600003  | Failed to connect service.          |
2416
2417**示例:**
2418
2419```js
2420Notification.getDoNotDisturbDate().then((data) => {
2421	console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
2422});
2423```
2424
2425
2426## Notification.getDoNotDisturbDate
2427
2428getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): void
2429
2430查询指定用户的免打扰时间(Callback形式)。
2431
2432**系统能力**:SystemCapability.Notification.Notification
2433
2434**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2435
2436**系统API**: 此接口为系统接口,三方应用不支持调用。
2437
2438**参数:**
2439
2440| 参数名     | 类型                              | 必填 | 说明                   |
2441| -------- | --------------------------------- | ---- | ---------------------- |
2442| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | 是   | 查询免打扰时间回调函数。 |
2443| userId   | number                            | 是   | 用户ID。 |
2444
2445**错误码:**
2446
2447错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2448
2449| 错误码ID | 错误信息                            |
2450| -------- | ----------------------------------- |
2451| 1600001  | Internal error.                     |
2452| 1600002  | Marshalling or unmarshalling error. |
2453| 1600003  | Failed to connect service.          |
2454| 1600008  | The user is not exist.              |
2455
2456**示例:**
2457
2458```js
2459function getDoNotDisturbDateCallback(err,data) {
2460    if (err) {
2461        console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
2462    } else {
2463        console.info("getDoNotDisturbDate success");
2464    }
2465}
2466
2467let userId = 1;
2468
2469Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback);
2470```
2471
2472
2473
2474## Notification.getDoNotDisturbDate
2475
2476getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
2477
2478查询指定用户的免打扰时间(Promise形式)。
2479
2480**系统能力**:SystemCapability.Notification.Notification
2481
2482**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2483
2484**系统API**: 此接口为系统接口,三方应用不支持调用。
2485
2486**参数:**
2487
2488| 参数名     | 类型                              | 必填 | 说明                   |
2489| -------- | --------------------------------- | ---- | ---------------------- |
2490| userId   | number                            | 是   | 用户ID。 |
2491
2492**返回值:**
2493
2494| 类型                                             | 说明                                      |
2495| ------------------------------------------------ | ----------------------------------------- |
2496| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | 以Promise形式返回获取查询到的免打扰时间。 |
2497
2498**错误码:**
2499
2500错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2501
2502| 错误码ID | 错误信息                            |
2503| -------- | ----------------------------------- |
2504| 1600001  | Internal error.                     |
2505| 1600002  | Marshalling or unmarshalling error. |
2506| 1600003  | Failed to connect service.          |
2507| 1600008  | The user is not exist.              |
2508
2509**示例:**
2510
2511```js
2512let userId = 1;
2513
2514Notification.getDoNotDisturbDate(userId).then((data) => {
2515	console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
2516});
2517```
2518
2519
2520## Notification.isSupportDoNotDisturbMode
2521
2522isSupportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void
2523
2524查询是否支持免打扰功能(Callback形式)。
2525
2526**系统能力**:SystemCapability.Notification.Notification
2527
2528**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2529
2530**系统API**: 此接口为系统接口,三方应用不支持调用。
2531
2532**参数:**
2533
2534| 参数名     | 类型                     | 必填 | 说明                             |
2535| -------- | ------------------------ | ---- | -------------------------------- |
2536| callback | AsyncCallback\<boolean\> | 是   | 查询是否支持免打扰功能回调函数。 |
2537
2538**错误码:**
2539
2540错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2541
2542| 错误码ID | 错误信息                            |
2543| -------- | ----------------------------------- |
2544| 1600001  | Internal error.                     |
2545| 1600002  | Marshalling or unmarshalling error. |
2546| 1600003  | Failed to connect service.          |
2547
2548**示例:**
2549
2550```js
2551function isSupportDoNotDisturbModeCallback(err,data) {
2552    if (err) {
2553        console.info("isSupportDoNotDisturbMode failed " + JSON.stringify(err));
2554    } else {
2555        console.info("isSupportDoNotDisturbMode success");
2556    }
2557}
2558
2559Notification.isSupportDoNotDisturbMode(supportDoNotDisturbModeCallback);
2560```
2561
2562
2563
2564## Notification.isSupportDoNotDisturbMode
2565
2566isSupportDoNotDisturbMode(): Promise\<boolean\>
2567
2568查询是否支持勿扰模式功能(Promise形式)。
2569
2570**系统能力**:SystemCapability.Notification.Notification
2571
2572**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2573
2574**系统API**: 此接口为系统接口,三方应用不支持调用。
2575
2576**返回值:**
2577
2578| 类型                                                        | 说明                                                         |
2579| ----------------------------------------------------------- | ------------------------------------------------------------ |
2580| Promise\<boolean\> | 以Promise形式返回获取是否支持免打扰功能的结果。 |
2581
2582**错误码:**
2583
2584错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2585
2586| 错误码ID | 错误信息                            |
2587| -------- | ----------------------------------- |
2588| 1600001  | Internal error.                     |
2589| 1600002  | Marshalling or unmarshalling error. |
2590| 1600003  | Failed to connect service.          |
2591
2592**示例:**
2593
2594```js
2595Notification.isSupportDoNotDisturbMode().then((data) => {
2596	console.info("isSupportDoNotDisturbMode success, data: " + JSON.stringify(data));
2597});
2598```
2599
2600
2601
2602## Notification.isSupportTemplate
2603
2604isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void
2605
2606查询模板是否存在(Callback形式)。
2607
2608**系统能力**:SystemCapability.Notification.Notification
2609
2610**参数:**
2611
2612| 参数名       | 类型                     | 必填 | 说明                       |
2613| ------------ | ------------------------ | ---- | -------------------------- |
2614| templateName | string                   | 是   | 模板名称。                   |
2615| callback     | AsyncCallback\<boolean\> | 是   | 查询模板是否存在的回调函数。 |
2616
2617**错误码:**
2618
2619错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2620
2621| 错误码ID | 错误信息                            |
2622| -------- | ----------------------------------- |
2623| 1600001  | Internal error.                     |
2624| 1600002  | Marshalling or unmarshalling error. |
2625| 1600003  | Failed to connect service.          |
2626| 1600011  | Read template config failed.        |
2627
2628**示例:**
2629
2630```javascript
2631let templateName = 'process';
2632function isSupportTemplateCallback(err, data) {
2633    if (err) {
2634        console.info("isSupportTemplate failed " + JSON.stringify(err));
2635    } else {
2636        console.info("isSupportTemplate success");
2637    }
2638}
2639
2640Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
2641```
2642
2643
2644
2645## Notification.isSupportTemplate
2646
2647isSupportTemplate(templateName: string): Promise\<boolean\>
2648
2649查询模板是否存在(Promise形式)。
2650
2651**系统能力**:SystemCapability.Notification.Notification
2652
2653**参数:**
2654
2655| 参数名       | 类型   | 必填 | 说明     |
2656| ------------ | ------ | ---- | -------- |
2657| templateName | string | 是   | 模板名称。 |
2658
2659**返回值:**
2660
2661| 类型               | 说明            |
2662| ------------------ | --------------- |
2663| Promise\<boolean\> | Promise方式返回模板是否存在的结果。 |
2664
2665**错误码:**
2666
2667错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2668
2669| 错误码ID | 错误信息                            |
2670| -------- | ----------------------------------- |
2671| 1600001  | Internal error.                     |
2672| 1600002  | Marshalling or unmarshalling error. |
2673| 1600003  | Failed to connect service.          |
2674| 1600011  | Read template config failed.        |
2675
2676**示例:**
2677
2678```javascript
2679let templateName = 'process';
2680
2681Notification.isSupportTemplate(templateName).then((data) => {
2682    console.info("isSupportTemplate success, data: " + JSON.stringify(data));
2683});
2684```
2685
2686
2687
2688## Notification.requestEnableNotification
2689
2690requestEnableNotification(callback: AsyncCallback\<void\>): void
2691
2692应用请求通知使能(Callback形式)。
2693
2694**系统能力**:SystemCapability.Notification.Notification
2695
2696**参数:**
2697
2698| 参数名   | 类型                     | 必填 | 说明                       |
2699| -------- | ------------------------ | ---- | -------------------------- |
2700| callback | AsyncCallback\<void\> | 是   | 应用请求通知使能的回调函数。 |
2701
2702**错误码:**
2703
2704错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2705
2706| 错误码ID | 错误信息                            |
2707| -------- | ----------------------------------- |
2708| 1600001  | Internal error.                     |
2709| 1600002  | Marshalling or unmarshalling error. |
2710| 1600003  | Failed to connect service.          |
2711
2712**示例:**
2713
2714```javascript
2715function requestEnableNotificationCallback(err) {
2716    if (err) {
2717        console.info("requestEnableNotification failed " + JSON.stringify(err));
2718    } else {
2719        console.info("requestEnableNotification success");
2720    }
2721};
2722
2723Notification.requestEnableNotification(requestEnableNotificationCallback);
2724```
2725
2726
2727
2728## Notification.requestEnableNotification
2729
2730requestEnableNotification(): Promise\<void\>
2731
2732应用请求通知使能(Promise形式)。
2733
2734**系统能力**:SystemCapability.Notification.Notification
2735
2736**错误码:**
2737
2738错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2739
2740| 错误码ID | 错误信息                            |
2741| -------- | ----------------------------------- |
2742| 1600001  | Internal error.                     |
2743| 1600002  | Marshalling or unmarshalling error. |
2744| 1600003  | Failed to connect service.          |
2745
2746**示例:**
2747
2748```javascript
2749Notification.requestEnableNotification().then(() => {
2750    console.info("requestEnableNotification success");
2751});
2752```
2753
2754
2755
2756## Notification.setDistributedEnable
2757
2758setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void
2759
2760设置设备是否支持分布式通知(Callback形式)。
2761
2762**系统能力**:SystemCapability.Notification.Notification
2763
2764**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2765
2766**系统API**: 此接口为系统接口,三方应用不支持调用。
2767
2768**参数:**
2769
2770| 参数名   | 类型                     | 必填 | 说明                       |
2771| -------- | ------------------------ | ---- | -------------------------- |
2772| enable   | boolean                  | 是   | 是否支持。 |
2773| callback | AsyncCallback\<void\> | 是   | 设置设备是否支持分布式通知的回调函数。 |
2774
2775**错误码:**
2776
2777错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2778
2779| 错误码ID | 错误信息                            |
2780| -------- | ----------------------------------- |
2781| 1600001  | Internal error.                     |
2782| 1600002  | Marshalling or unmarshalling error. |
2783| 1600003  | Failed to connect service.          |
2784| 1600010  | Distributed operation failed.       |
2785
2786**示例:**
2787
2788```javascript
2789function setDistributedEnableCallback(err) {
2790    if (err) {
2791        console.info("setDistributedEnable failed " + JSON.stringify(err));
2792    } else {
2793        console.info("setDistributedEnable success");
2794    }
2795};
2796
2797let enable = true;
2798
2799Notification.setDistributedEnable(enable, setDistributedEnableCallback);
2800```
2801
2802
2803
2804## Notification.setDistributedEnable
2805
2806setDistributedEnable(enable: boolean): Promise\<void>
2807
2808设置设备是否支持分布式通知(Promise形式)。
2809
2810**系统能力**:SystemCapability.Notification.Notification
2811
2812**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2813
2814**系统API**: 此接口为系统接口,三方应用不支持调用。
2815
2816**参数:**
2817
2818| 参数名   | 类型                     | 必填 | 说明                       |
2819| -------- | ------------------------ | ---- | -------------------------- |
2820| enable   | boolean                  | 是   | 是否支持。 |
2821
2822**错误码:**
2823
2824错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2825
2826| 错误码ID | 错误信息                            |
2827| -------- | ----------------------------------- |
2828| 1600001  | Internal error.                     |
2829| 1600002  | Marshalling or unmarshalling error. |
2830| 1600003  | Failed to connect service.          |
2831| 1600010  | Distributed operation failed.       |
2832
2833**示例:**
2834
2835```javascript
2836let enable = true;
2837
2838Notification.setDistributedEnable(enable).then(() => {
2839        console.info("setDistributedEnable success");
2840    });
2841```
2842
2843
2844## Notification.isDistributedEnabled
2845
2846isDistributedEnabled(callback: AsyncCallback\<boolean>): void
2847
2848查询设备是否支持分布式通知(Callback形式)。
2849
2850**系统能力**:SystemCapability.Notification.Notification
2851
2852**参数:**
2853
2854| 参数名   | 类型                     | 必填 | 说明                       |
2855| -------- | ------------------------ | ---- | -------------------------- |
2856| callback | AsyncCallback\<boolean\> | 是   | 设备是否支持分布式通知的回调函数。 |
2857
2858**错误码:**
2859
2860错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2861
2862| 错误码ID | 错误信息                            |
2863| -------- | ----------------------------------- |
2864| 1600001  | Internal error.                     |
2865| 1600002  | Marshalling or unmarshalling error. |
2866| 1600003  | Failed to connect service.          |
2867| 1600010  | Distributed operation failed.       |
2868
2869**示例:**
2870
2871```javascript
2872function isDistributedEnabledCallback(err, data) {
2873    if (err) {
2874        console.info("isDistributedEnabled failed " + JSON.stringify(err));
2875    } else {
2876        console.info("isDistributedEnabled success " + JSON.stringify(data));
2877    }
2878};
2879
2880Notification.isDistributedEnabled(isDistributedEnabledCallback);
2881```
2882
2883
2884
2885## Notification.isDistributedEnabled
2886
2887isDistributedEnabled(): Promise\<boolean>
2888
2889查询设备是否支持分布式通知(Promise形式)。
2890
2891**系统能力**:SystemCapability.Notification.Notification
2892
2893**返回值:**
2894
2895| 类型               | 说明                                          |
2896| ------------------ | --------------------------------------------- |
2897| Promise\<boolean\> | Promise方式返回设备是否支持分布式通知的结果。 |
2898
2899**错误码:**
2900
2901错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2902
2903| 错误码ID | 错误信息                            |
2904| -------- | ----------------------------------- |
2905| 1600001  | Internal error.                     |
2906| 1600002  | Marshalling or unmarshalling error. |
2907| 1600003  | Failed to connect service.          |
2908| 1600010  | Distributed operation failed.       |
2909
2910**示例:**
2911
2912```javascript
2913Notification.isDistributedEnabled()
2914    .then((data) => {
2915        console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
2916    });
2917```
2918
2919
2920## Notification.setDistributedEnableByBundle
2921
2922setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void
2923
2924设置指定应用是否支持分布式通知(Callback形式)。
2925
2926**系统能力**:SystemCapability.Notification.Notification
2927
2928**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2929
2930**系统API**: 此接口为系统接口,三方应用不支持调用。
2931
2932**参数:**
2933
2934| 参数名   | 类型                     | 必填 | 说明                       |
2935| -------- | ------------------------ | ---- | -------------------------- |
2936| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | 是   | 应用的包信息。                   |
2937| enable   | boolean                  | 是   | 是否支持。                       |
2938| callback | AsyncCallback\<void\> | 是   | 应用程序是否支持分布式通知的回调函数。 |
2939
2940**错误码:**
2941
2942错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2943
2944| 错误码ID | 错误信息                                 |
2945| -------- | ---------------------------------------- |
2946| 1600001  | Internal error.                          |
2947| 1600002  | Marshalling or unmarshalling error.      |
2948| 1600003  | Failed to connect service.               |
2949| 1600010  | Distributed operation failed.            |
2950| 17700001 | The specified bundle name was not found. |
2951
2952**示例:**
2953
2954```javascript
2955function setDistributedEnableByBundleCallback(err) {
2956    if (err) {
2957        console.info("enableDistributedByBundle failed " + JSON.stringify(err));
2958    } else {
2959        console.info("enableDistributedByBundle success");
2960    }
2961};
2962
2963let bundle = {
2964    bundle: "bundleName1",
2965};
2966
2967let enable = true
2968
2969Notification.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback);
2970```
2971
2972
2973
2974## Notification.setDistributedEnableByBundle
2975
2976setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<void>
2977
2978设置指定应用是否支持分布式通知(Promise形式)。
2979
2980**系统能力**:SystemCapability.Notification.Notification
2981
2982**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
2983
2984**系统API**: 此接口为系统接口,三方应用不支持调用。
2985
2986**参数:**
2987
2988| 参数名   | 类型                     | 必填 | 说明                       |
2989| -------- | ------------------------ | ---- | -------------------------- |
2990| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | 是   | 应用的包。                |
2991| enable   | boolean                  | 是   | 是否支持。                  |
2992
2993**错误码:**
2994
2995错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
2996
2997| 错误码ID | 错误信息                                 |
2998| -------- | ---------------------------------------- |
2999| 1600001  | Internal error.                          |
3000| 1600002  | Marshalling or unmarshalling error.      |
3001| 1600003  | Failed to connect service.               |
3002| 1600010  | Distributed operation failed.            |
3003| 17700001 | The specified bundle name was not found. |
3004
3005**示例:**
3006
3007```javascript
3008let bundle = {
3009    bundle: "bundleName1",
3010};
3011
3012let enable = true
3013
3014Notification.setDistributedEnableByBundle(bundle, enable).then(() => {
3015        console.info("setDistributedEnableByBundle success");
3016    });
3017```
3018
3019## Notification.isDistributedEnabledByBundle
3020
3021isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void
3022
3023根据应用的包获取应用程序是否支持分布式通知(Callback形式)。
3024
3025**系统能力**:SystemCapability.Notification.Notification
3026
3027**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
3028
3029**系统API**: 此接口为系统接口,三方应用不支持调用。
3030
3031**参数:**
3032
3033| 参数名   | 类型                     | 必填 | 说明                       |
3034| -------- | ------------------------ | ---- | -------------------------- |
3035| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | 是   | 应用的包。                     |
3036| callback | AsyncCallback\<boolean\> | 是   | 查询指定应用是否支持分布式通知的回调函数。 |
3037
3038**错误码:**
3039
3040错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3041
3042| 错误码ID | 错误信息                                 |
3043| -------- | ---------------------------------------- |
3044| 1600001  | Internal error.                          |
3045| 1600002  | Marshalling or unmarshalling error.      |
3046| 1600003  | Failed to connect service.               |
3047| 1600010  | Distributed operation failed.            |
3048| 17700001 | The specified bundle name was not found. |
3049
3050**示例:**
3051
3052```javascript
3053function isDistributedEnabledByBundleCallback(err, data) {
3054    if (err) {
3055        console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err));
3056    } else {
3057        console.info("isDistributedEnabledByBundle success" + JSON.stringify(data));
3058    }
3059};
3060
3061let bundle = {
3062    bundle: "bundleName1",
3063};
3064
3065Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback);
3066```
3067
3068
3069
3070## Notification.isDistributedEnabledByBundle
3071
3072isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
3073
3074查询指定应用是否支持分布式通知(Promise形式)。
3075
3076**系统能力**:SystemCapability.Notification.Notification
3077
3078**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
3079
3080**系统API**: 此接口为系统接口,三方应用不支持调用。
3081
3082**参数:**
3083
3084| 参数名   | 类型                     | 必填 | 说明                       |
3085| -------- | ------------------------ | ---- | -------------------------- |
3086| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption)             | 是   | 应用的包。                |
3087
3088**返回值:**
3089
3090| 类型               | 说明                                              |
3091| ------------------ | ------------------------------------------------- |
3092| Promise\<boolean\> | Promise方式返回指定应用是否支持分布式通知的结果。 |
3093
3094**错误码:**
3095
3096错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3097
3098| 错误码ID | 错误信息                                 |
3099| -------- | ---------------------------------------- |
3100| 1600001  | Internal error.                          |
3101| 1600002  | Marshalling or unmarshalling error.      |
3102| 1600003  | Failed to connect service.               |
3103| 1600010  | Distributed operation failed.            |
3104| 17700001 | The specified bundle name was not found. |
3105
3106**示例:**
3107
3108```javascript
3109let bundle = {
3110    bundle: "bundleName1",
3111};
3112
3113Notification.isDistributedEnabledByBundle(bundle).then((data) => {
3114    console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
3115});
3116```
3117
3118
3119## Notification.getDeviceRemindType
3120
3121getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
3122
3123获取通知的提醒方式(Callback形式)。
3124
3125**系统能力**:SystemCapability.Notification.Notification
3126
3127**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
3128
3129**系统API**: 此接口为系统接口,三方应用不支持调用。
3130
3131**参数:**
3132
3133| 参数名   | 类型                               | 必填 | 说明                       |
3134| -------- | --------------------------------- | ---- | -------------------------- |
3135| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | 是   | 获取通知提醒方式的回调函数。 |
3136
3137**错误码:**
3138
3139错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3140
3141| 错误码ID | 错误信息                            |
3142| -------- | ----------------------------------- |
3143| 1600001  | Internal error.                     |
3144| 1600002  | Marshalling or unmarshalling error. |
3145| 1600003  | Failed to connect service.          |
3146
3147**示例:**
3148
3149```javascript
3150function getDeviceRemindTypeCallback(err, data) {
3151    if (err) {
3152        console.info("getDeviceRemindType failed " + JSON.stringify(err));
3153    } else {
3154        console.info("getDeviceRemindType success");
3155    }
3156};
3157
3158Notification.getDeviceRemindType(getDeviceRemindTypeCallback);
3159```
3160
3161
3162
3163## Notification.getDeviceRemindType
3164
3165getDeviceRemindType(): Promise\<DeviceRemindType\>
3166
3167获取通知的提醒方式(Promise形式)。
3168
3169**系统能力**:SystemCapability.Notification.Notification
3170
3171**需要权限**: ohos.permission.NOTIFICATION_CONTROLLER
3172
3173**系统API**: 此接口为系统接口,三方应用不支持调用。
3174
3175**返回值:**
3176
3177| 类型               | 说明            |
3178| ------------------ | --------------- |
3179| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise方式返回获取通知提醒方式的结果。 |
3180
3181**错误码:**
3182
3183错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3184
3185| 错误码ID | 错误信息                            |
3186| -------- | ----------------------------------- |
3187| 1600001  | Internal error.                     |
3188| 1600002  | Marshalling or unmarshalling error. |
3189| 1600003  | Failed to connect service.          |
3190
3191**示例:**
3192
3193```javascript
3194Notification.getDeviceRemindType().then((data) => {
3195    console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
3196});
3197```
3198
3199
3200## Notification.publishAsBundle
3201
3202publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void
3203
3204发布代理通知(callback形式)。
3205
3206**系统能力**:SystemCapability.Notification.Notification
3207
3208**需要权限**: ohos.permission.NOTIFICATION_CONTROLLERohos.permission.NOTIFICATION_AGENT_CONTROLLER
3209
3210**系统API**: 此接口为系统接口,三方应用不支持调用。
3211
3212**参数:**
3213
3214| 参数名               | 类型                                        | 必填 | 说明                                     |
3215| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- |
3216| request              | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
3217| representativeBundle | string                                      | 是   | 被代理应用的包名。                       |
3218| userId               | number                                      | 是   | 用户ID。                                 |
3219| callback             | AsyncCallback                               | 是   | 发布代理通知的回调方法。                 |
3220
3221**错误码:**
3222
3223错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3224
3225| 错误码ID | 错误信息                                  |
3226| -------- | ----------------------------------------- |
3227| 1600001  | Internal error.                           |
3228| 1600002  | Marshalling or unmarshalling error.       |
3229| 1600003  | Failed to connect service.                |
3230| 1600004  | Notification is not enabled.              |
3231| 1600005  | Notification slot is not enabled.         |
3232| 1600008  | The user is not exist.                    |
3233| 1600009  | Over max number notifications per second. |
3234
3235**示例:**
3236
3237```js
3238//publishAsBundle回调
3239function callback(err) {
3240    if (err) {
3241        console.info("publishAsBundle failed " + JSON.stringify(err));
3242    } else {
3243        console.info("publishAsBundle success");
3244    }
3245}
3246// 被代理应用的包名
3247let representativeBundle = "com.example.demo";
3248// 用户ID
3249let userId = 100;
3250// NotificationRequest对象
3251let request = {
3252    id: 1,
3253    content: {
3254        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
3255        normal: {
3256            title: "test_title",
3257            text: "test_text",
3258            additionalText: "test_additionalText"
3259        }
3260    }
3261};
3262
3263Notification.publishAsBundle(request, representativeBundle, userId, callback);
3264```
3265
3266## Notification.publishAsBundle
3267
3268publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\>
3269
3270发布代理通知(Promise形式)。
3271
3272**系统能力**:SystemCapability.Notification.Notification
3273
3274**需要权限**: ohos.permission.NOTIFICATION_CONTROLLERohos.permission.NOTIFICATION_AGENT_CONTROLLER
3275
3276**系统API**: 此接口为系统接口,三方应用不支持调用。
3277
3278**参数:**
3279
3280
3281| 参数名               | 类型                                        | 必填 | 说明                                          |
3282| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
3283| request              | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是   | 用于设置要发布通知的内容和相关配置信息。 |
3284| representativeBundle | string                                      | 是   | 被代理应用的包名。                            |
3285| userId               | number                                      | 是   | 用户ID。                            |
3286
3287**错误码:**
3288
3289错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3290
3291| 错误码ID | 错误信息                                  |
3292| -------- | ----------------------------------------- |
3293| 1600001  | Internal error.                           |
3294| 1600002  | Marshalling or unmarshalling error.       |
3295| 1600003  | Failed to connect service.                |
3296| 1600004  | Notification is not enabled.              |
3297| 1600005  | Notification slot is not enabled.         |
3298| 1600008  | The user is not exist.                    |
3299| 1600009  | Over max number notifications per second. |
3300
3301**示例:**
3302
3303```js
3304// 被代理应用的包名
3305let representativeBundle = "com.example.demo";
3306// 用户ID
3307let userId = 100;
3308// NotificationRequest对象
3309let request = {
3310    id: 1,
3311    content: {
3312        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
3313        normal: {
3314            title: "test_title",
3315            text: "test_text",
3316            additionalText: "test_additionalText"
3317        }
3318    }
3319};
3320
3321Notification.publishAsBundle(request, representativeBundle, userId).then(() => {
3322	console.info("publishAsBundle success");
3323});
3324```
3325
3326## Notification.cancelAsBundle
3327
3328cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void
3329
3330取消代理通知(callback形式)。
3331
3332**系统能力**:SystemCapability.Notification.Notification
3333
3334**系统API**:此接口为系统接口,三方应用不支持调用。
3335
3336**需要权限**: ohos.permission.NOTIFICATION_CONTROLLERohos.permission.NOTIFICATION_AGENT_CONTROLLER
3337
3338**系统API**: 此接口为系统接口,三方应用不支持调用。
3339
3340**参数:**
3341
3342| 参数名               | 类型          | 必填 | 说明                     |
3343| -------------------- | ------------- | ---- | ------------------------ |
3344| id                   | number        | 是   | 通知ID。                 |
3345| representativeBundle | string        | 是   | 被代理应用的包名。       |
3346| userId               | number        | 是   | 用户ID。       |
3347| callback             | AsyncCallback | 是   | 取消代理通知的回调方法。 |
3348
3349**错误码:**
3350
3351错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3352
3353| 错误码ID | 错误信息                            |
3354| -------- | ----------------------------------- |
3355| 1600001  | Internal error.                     |
3356| 1600002  | Marshalling or unmarshalling error. |
3357| 1600003  | Failed to connect service.          |
3358| 1600007  | The notification is not exist.      |
3359| 1600008  | The user is not exist.              |
3360
3361**示例:**
3362
3363```js
3364// cancelAsBundle
3365function cancelAsBundleCallback(err) {
3366    if (err) {
3367        console.info("cancelAsBundle failed " + JSON.stringify(err));
3368    } else {
3369        console.info("cancelAsBundle success");
3370    }
3371}
3372// 被代理应用的包名
3373let representativeBundle = "com.example.demo";
3374// 用户ID
3375let userId = 100;
3376
3377Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback);
3378```
3379
3380## Notification.cancelAsBundle
3381
3382cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\>
3383
3384取消代理通知(Promise形式)。
3385
3386**系统能力**:SystemCapability.Notification.Notification
3387
3388**系统API**:此接口为系统接口,三方应用不支持调用。
3389
3390**需要权限**: ohos.permission.NOTIFICATION_CONTROLLERohos.permission.NOTIFICATION_AGENT_CONTROLLER
3391
3392**系统API**: 此接口为系统接口,三方应用不支持调用。
3393
3394**参数:**
3395
3396| 参数名               | 类型   | 必填 | 说明               |
3397| -------------------- | ------ | ---- | ------------------ |
3398| id                   | number | 是   | 通知ID。           |
3399| representativeBundle | string | 是   | 被代理应用的包名。 |
3400| userId               | number | 是   | 用户ID。 |
3401
3402**错误码:**
3403
3404错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3405
3406| 错误码ID | 错误信息                            |
3407| -------- | ----------------------------------- |
3408| 1600001  | Internal error.                     |
3409| 1600002  | Marshalling or unmarshalling error. |
3410| 1600003  | Failed to connect service.          |
3411| 1600007  | The notification is not exist.      |
3412| 1600008  | The user is not exist.              |
3413
3414**示例:**
3415
3416```js
3417// 被代理应用的包名
3418let representativeBundle = "com.example.demo";
3419// 用户ID
3420let userId = 100;
3421
3422Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
3423	console.info("cancelAsBundle success");
3424});
3425```
3426
3427## Notification.setNotificationEnableSlot
3428
3429setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void
3430
3431设置指定应用的指定渠道类型的使能状态(Callback形式)。
3432
3433**系统能力**:SystemCapability.Notification.Notification
3434
3435**系统API**:此接口为系统接口,三方应用不支持调用。
3436
3437**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3438
3439**参数:**
3440
3441| 参数名   | 类型                          | 必填 | 说明                   |
3442| -------- | ----------------------------- | ---- | ---------------------- |
3443| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 应用的包信息。           |
3444| type     | [SlotType](#slottype)         | 是   | 指定渠道类型。         |
3445| enable   | boolean                       | 是   | 使能状态。             |
3446| callback | AsyncCallback\<void\>         | 是   | 设置渠道使能回调函数。 |
3447
3448**错误码:**
3449
3450错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3451
3452| 错误码ID | 错误信息                                 |
3453| -------- | ---------------------------------------- |
3454| 1600001  | Internal error.                          |
3455| 1600002  | Marshalling or unmarshalling error.      |
3456| 1600003  | Failed to connect service.               |
3457| 17700001 | The specified bundle name was not found. |
3458
3459**示例:**
3460
3461```js
3462// setNotificationEnableSlot
3463function setNotificationEnableSlotCallback(err) {
3464    if (err) {
3465        console.info("setNotificationEnableSlot failed " + JSON.stringify(err));
3466    } else {
3467        console.info("setNotificationEnableSlot success");
3468    }
3469};
3470
3471Notification.setNotificationEnableSlot(
3472    { bundle: "ohos.samples.notification", },
3473    Notification.SlotType.SOCIAL_COMMUNICATION,
3474    true,
3475    setNotificationEnableSlotCallback);
3476```
3477
3478## Notification.setNotificationEnableSlot
3479
3480setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void>
3481
3482设置指定应用的指定渠道类型的使能状态(Promise形式)。
3483
3484**系统能力**:SystemCapability.Notification.Notification
3485
3486**系统API**:此接口为系统接口,三方应用不支持调用。
3487
3488**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3489
3490**参数:**
3491
3492| 参数名 | 类型                          | 必填 | 说明           |
3493| ------ | ----------------------------- | ---- | -------------- |
3494| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 应用的包信息。   |
3495| type   | [SlotType](#slottype)         | 是   | 渠道类型。 |
3496| enable | boolean                       | 是   | 使能状态。     |
3497
3498**错误码:**
3499
3500错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3501
3502| 错误码ID | 错误信息                                 |
3503| -------- | ---------------------------------------- |
3504| 1600001  | Internal error.                          |
3505| 1600002  | Marshalling or unmarshalling error.      |
3506| 1600003  | Failed to connect service.               |
3507| 17700001 | The specified bundle name was not found. |
3508
3509**示例:**
3510
3511```js
3512// setNotificationEnableSlot
3513Notification.setNotificationEnableSlot(
3514    { bundle: "ohos.samples.notification", },
3515    Notification.SlotType.SOCIAL_COMMUNICATION,
3516    true).then(() => {
3517        console.info("setNotificationEnableSlot success");
3518    });
3519```
3520
3521## Notification.isNotificationSlotEnabled
3522
3523isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void
3524
3525获取指定应用的指定渠道类型的使能状态(Callback形式)。
3526
3527**系统能力**:SystemCapability.Notification.Notification
3528
3529**系统API**:此接口为系统接口,三方应用不支持调用。
3530
3531**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3532
3533**参数:**
3534
3535| 参数名   | 类型                          | 必填 | 说明                   |
3536| -------- | ----------------------------- | ---- | ---------------------- |
3537| bundle   | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 应用的包信息。           |
3538| type     | [SlotType](#slottype)         | 是   | 渠道类型。         |
3539| callback | AsyncCallback\<boolean\>         | 是   | 获取渠道使能状态回调函数。 |
3540
3541**错误码:**
3542
3543错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3544
3545| 错误码ID | 错误信息                                 |
3546| -------- | ---------------------------------------- |
3547| 1600001  | Internal error.                          |
3548| 1600002  | Marshalling or unmarshalling error.      |
3549| 1600003  | Failed to connect service.               |
3550| 17700001 | The specified bundle name was not found. |
3551
3552**示例:**
3553
3554```js
3555// isNotificationSlotEnabled
3556function getEnableSlotCallback(err, data) {
3557    if (err) {
3558        console.info("isNotificationSlotEnabled failed " + JSON.stringify(err));
3559    } else {
3560        console.info("isNotificationSlotEnabled success");
3561    }
3562};
3563
3564Notification.isNotificationSlotEnabled(
3565    { bundle: "ohos.samples.notification", },
3566    Notification.SlotType.SOCIAL_COMMUNICATION,
3567    getEnableSlotCallback);
3568```
3569
3570## Notification.isNotificationSlotEnabled
3571
3572isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\>
3573
3574获取指定应用的指定渠道类型的使能状态(Promise形式)。
3575
3576**系统能力**:SystemCapability.Notification.Notification
3577
3578**系统API**:此接口为系统接口,三方应用不支持调用。
3579
3580**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3581
3582**参数:**
3583
3584| 参数名 | 类型                          | 必填 | 说明           |
3585| ------ | ----------------------------- | ---- | -------------- |
3586| bundle | [BundleOption](./js-apis-inner-notification-notificationCommonDef.md#bundleoption) | 是   | 应用的包信息。   |
3587| type   | [SlotType](#slottype)         | 是   | 渠道类型。 |
3588
3589**返回值:**
3590
3591| 类型                                                        | 说明                                                         |
3592| ----------------------------------------------------------- | ------------------------------------------------------------ |
3593| Promise\<boolean\> | 以Promise形式返回指定类型的渠道使能状态。 |
3594
3595**错误码:**
3596
3597错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3598
3599| 错误码ID | 错误信息                                 |
3600| -------- | ---------------------------------------- |
3601| 1600001  | Internal error.                          |
3602| 1600002  | Marshalling or unmarshalling error.      |
3603| 1600003  | Failed to connect service.               |
3604| 17700001 | The specified bundle name was not found. |
3605
3606**示例:**
3607
3608```js
3609// isNotificationSlotEnabled
3610Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
3611    Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => {
3612    console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
3613});
3614```
3615
3616
3617## Notification.setSyncNotificationEnabledWithoutApp
3618
3619setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void
3620
3621设置是否将通知同步到未安装应用程序的设备(callback形式)。
3622
3623**系统能力**:SystemCapability.Notification.Notification
3624
3625**系统API**:此接口为系统接口,三方应用不支持调用。
3626
3627**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3628
3629**参数:**
3630
3631| 参数名 | 类型                          | 必填 | 说明           |
3632| ------ | ----------------------------- | ---- | -------------- |
3633| userId | number | 是   | 用户ID。   |
3634| enable | boolean | 是   | 是否启用。   |
3635| callback | AsyncCallback\<void\>    | 是   | 设置是否将通知同步到未安装应用程序的设备的回调函数。 |
3636
3637**错误码:**
3638
3639错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3640
3641| 错误码ID | 错误信息                            |
3642| -------- | ----------------------------------- |
3643| 1600001  | Internal error.                     |
3644| 1600002  | Marshalling or unmarshalling error. |
3645| 1600003  | Failed to connect service.          |
3646| 1600008  | The user is not exist.              |
3647
3648**示例:**
3649
3650```js
3651let userId = 100;
3652let enable = true;
3653
3654function callback(err) {
3655    if (err) {
3656        console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err));
3657    } else {
3658        console.info("setSyncNotificationEnabledWithoutApp success");
3659    }
3660}
3661
3662Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback);
3663```
3664
3665
3666## Notification.setSyncNotificationEnabledWithoutApp
3667
3668setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void>
3669
3670设置是否将通知同步到未安装应用程序的设备(Promise形式)。
3671
3672**系统能力**:SystemCapability.Notification.Notification
3673
3674**系统API**:此接口为系统接口,三方应用不支持调用。
3675
3676**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3677
3678**参数:**
3679
3680| 参数名 | 类型                          | 必填 | 说明           |
3681| ------ | ----------------------------- | ---- | -------------- |
3682| userId | number | 是   | 用户ID。   |
3683| enable | boolean | 是   | 是否启用。   |
3684
3685**返回值:**
3686
3687| 类型                                                        | 说明                                                         |
3688| ----------------------------------------------------------- | ------------------------------------------------------------ |
3689| Promise\<void\> | 以Promise形式返回设置是否将通知同步到未安装应用程序的设备的结果。 |
3690
3691**错误码:**
3692
3693错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3694
3695| 错误码ID | 错误信息                            |
3696| -------- | ----------------------------------- |
3697| 1600001  | Internal error.                     |
3698| 1600002  | Marshalling or unmarshalling error. |
3699| 1600003  | Failed to connect service.          |
3700| 1600008  | The user is not exist.              |
3701
3702**示例:**
3703
3704```js
3705let userId = 100;
3706let enable = true;
3707
3708Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
3709    console.info('setSyncNotificationEnabledWithoutApp success');
3710}).catch((err) => {
3711    console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err));
3712});
3713```
3714
3715
3716## Notification.getSyncNotificationEnabledWithoutApp
3717
3718getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void
3719
3720获取同步通知到未安装应用程序设备的开关是否开启(callback形式)。
3721
3722**系统能力**:SystemCapability.Notification.Notification
3723
3724**系统API**:此接口为系统接口,三方应用不支持调用。
3725
3726**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3727
3728**参数:**
3729
3730| 参数名 | 类型                          | 必填 | 说明           |
3731| ------ | ----------------------------- | ---- | -------------- |
3732| userId | number | 是   | 用户ID。   |
3733| callback | AsyncCallback\<boolean\>         | 是   | 获取同步通知到未安装应用程序设备的开关是否开启的回调函数。 |
3734
3735**错误码:**
3736
3737错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3738
3739| 错误码ID | 错误信息                            |
3740| -------- | ----------------------------------- |
3741| 1600001  | Internal error.                     |
3742| 1600002  | Marshalling or unmarshalling error. |
3743| 1600003  | Failed to connect service.          |
3744| 1600008  | The user is not exist.              |
3745
3746**示例:**
3747
3748```js
3749let userId = 100;
3750
3751function getSyncNotificationEnabledWithoutAppCallback(err, data) {
3752    if (err) {
3753        console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err);
3754    } else {
3755        console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data);
3756    }
3757}
3758
3759Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback);
3760```
3761
3762
3763## Notification.getSyncNotificationEnabledWithoutApp
3764
3765getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean>
3766
3767获取同步通知到未安装应用程序设备的开关是否开启(Promise形式)。
3768
3769**系统能力**:SystemCapability.Notification.Notification
3770
3771**系统API**:此接口为系统接口,三方应用不支持调用。
3772
3773**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER
3774
3775**参数:**
3776
3777| 参数名 | 类型                          | 必填 | 说明           |
3778| ------ | ----------------------------- | ---- | -------------- |
3779| userId | number | 是   | 用户ID。   |
3780
3781**返回值:**
3782
3783| 类型               | 说明                                                         |
3784| ------------------ | ------------------------------------------------------------ |
3785| Promise\<boolean\> | 以Promise形式返回获取同步通知到未安装应用程序设备的开关是否开启的结果。 |
3786
3787**错误码:**
3788
3789错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)。
3790
3791| 错误码ID | 错误信息                            |
3792| -------- | ----------------------------------- |
3793| 1600001  | Internal error.                     |
3794| 1600002  | Marshalling or unmarshalling error. |
3795| 1600003  | Failed to connect service.          |
3796| 1600008  | The user is not exist.              |
3797
3798**示例:**
3799
3800```js
3801let userId = 100;
3802Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => {
3803    console.info('getSyncNotificationEnabledWithoutApp, data:' + data);
3804}).catch((err) => {
3805    console.info('getSyncNotificationEnabledWithoutApp, err:' + err);
3806});
3807    .catch((err) => {
3808        console.info('getSyncNotificationEnabledWithoutApp, err:', err);
3809    });
3810```
3811
3812
3813
3814
3815## DoNotDisturbDate
3816
3817**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
3818
3819**系统API**:此接口为系统接口,三方应用不支持调用。
3820
3821| 名称  | 类型                                  | 可读 | 可写 | 说明                   |
3822| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
3823| type  | [DoNotDisturbType](#donotdisturbtype) | 是   | 是   | 免打扰设置的时间类型。 |
3824| begin | Date                                  | 是   | 是   | 免打扰设置的起点时间。 |
3825| end   | Date                                  | 是   | 是   | 免打扰设置的终点时间。 |
3826
3827
3828
3829## DoNotDisturbType
3830
3831**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
3832
3833**系统API**: 此接口为系统接口,三方应用不支持调用。
3834
3835| 名称         | 值               | 说明                                       |
3836| ------------ | ---------------- | ------------------------------------------ |
3837| TYPE_NONE    | 0 | 非通知勿扰类型。                           |
3838| TYPE_ONCE    | 1 | 以设置时间段(只看小时和分钟)一次执行勿扰。 |
3839| TYPE_DAILY   | 2 | 以设置时间段(只看小时和分钟)每天执行勿扰。 |
3840| TYPE_CLEARLY | 3 | 以设置时间段(明确年月日时分)执行勿扰。     |
3841
3842
3843## ContentType
3844
3845**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
3846
3847| 名称                              | 值          | 说明               |
3848| --------------------------------- | ----------- | ------------------ |
3849| NOTIFICATION_CONTENT_BASIC_TEXT   | NOTIFICATION_CONTENT_BASIC_TEXT | 普通类型通知。     |
3850| NOTIFICATION_CONTENT_LONG_TEXT    | NOTIFICATION_CONTENT_LONG_TEXT | 长文本类型通知。   |
3851| NOTIFICATION_CONTENT_PICTURE      | NOTIFICATION_CONTENT_PICTURE | 图片类型通知。     |
3852| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | 社交类型通知。     |
3853| NOTIFICATION_CONTENT_MULTILINE    | NOTIFICATION_CONTENT_MULTILINE | 多行文本类型通知。 |
3854
3855## SlotLevel
3856
3857**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
3858
3859| 名称                              | 值          | 说明               |
3860| --------------------------------- | ----------- | ------------------ |
3861| LEVEL_NONE                        | 0           | 表示关闭通知功能。     |
3862| LEVEL_MIN                         | 1           | 表示通知功能已启用,但状态栏中不显示通知图标,且没有横幅或提示音。 |
3863| LEVEL_LOW                         | 2           | 表示通知功能已启用,且状态栏中显示通知图标,但没有横幅或提示音。 |
3864| LEVEL_DEFAULT                     | 3           | 表示通知功能已启用,状态栏中显示通知图标,没有横幅但有提示音。 |
3865| LEVEL_HIGH                        | 4           | 表示通知功能已启用,状态栏中显示通知图标,有横幅和提示音。 |
3866
3867
3868## SlotType
3869
3870**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
3871
3872| 名称                 | 值       | 说明       |
3873| -------------------- | -------- | ---------- |
3874| UNKNOWN_TYPE         | 0 | 未知类型。 |
3875| SOCIAL_COMMUNICATION | 1 | 社交类型。 |
3876| SERVICE_INFORMATION  | 2 | 服务类型。 |
3877| CONTENT_INFORMATION  | 3 | 内容类型。 |
3878| OTHER_TYPES          | 0xFFFF | 其他类型。 |
3879
3880
3881
3882
3883## DeviceRemindType
3884
3885**系统能力**:SystemCapability.Notification.Notification
3886
3887**系统API**: 此接口为系统接口,三方应用不支持调用。
3888
3889| 名称                 | 值  | 说明                               |
3890| -------------------- | --- | --------------------------------- |
3891| IDLE_DONOT_REMIND    | 0   | 设备未被使用,无需提醒。            |
3892| IDLE_REMIND          | 1   | 提醒设备未被使用。                 |
3893| ACTIVE_DONOT_REMIND  | 2   | 设备正在使用,无需提醒。            |
3894| ACTIVE_REMIND        | 3   | 提醒设备正在使用。                 |
3895
3896
3897## SourceType
3898
3899**系统能力**:SystemCapability.Notification.Notification
3900
3901**系统API**: 此接口为系统接口,三方应用不支持调用。
3902
3903| 名称                 | 值  | 说明                  |
3904| -------------------- | --- | -------------------- |
3905| TYPE_NORMAL          | 0   | 一般通知。            |
3906| TYPE_CONTINUOUS      | 1   | 连续通知。            |
3907| TYPE_TIMER           | 2   | 计划通知。            |
3908