• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License"),
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file Information carried when a notification is sent
18 * @kit NotificationKit
19 */
20
21import notification from '../@ohos.notification';
22import image from '../@ohos.multimedia.image';
23import type notificationManager from '../@ohos.notificationManager';
24import type notificationSubscribe from '../@ohos.notificationSubscribe';
25import { WantAgent } from '../@ohos.wantAgent';
26import { NotificationContent } from './notificationContent';
27import { NotificationActionButton } from './notificationActionButton';
28import { NotificationTemplate } from './notificationTemplate';
29import { NotificationFlags } from './notificationFlags';
30import type { BundleOption } from './NotificationCommonDef';
31
32/**
33 * Defines a NotificationRequest instance.
34 *
35 * @typedef NotificationRequest
36 * @syscap SystemCapability.Notification.Notification
37 * @since 7
38 */
39/**
40 * Defines a NotificationRequest instance.
41 *
42 * @typedef NotificationRequest
43 * @syscap SystemCapability.Notification.Notification
44 * @crossplatform
45 * @since 12
46 */
47export interface NotificationRequest {
48  /**
49   * Notification content.
50   *
51   * @type { NotificationContent }
52   * @syscap SystemCapability.Notification.Notification
53   * @since 7
54   */
55  /**
56   * Notification content.
57   *
58   * @type { NotificationContent }
59   * @syscap SystemCapability.Notification.Notification
60   * @crossplatform
61   * @since 12
62   */
63  content: NotificationContent;
64
65  /**
66   * Notification ID.
67   *
68   * @type { ?number }
69   * @syscap SystemCapability.Notification.Notification
70   * @since 7
71   */
72  /**
73   * Notification ID.
74   *
75   * @type { ?number }
76   * @syscap SystemCapability.Notification.Notification
77   * @crossplatform
78   * @since 12
79   */
80  id?: number;
81
82  /**
83   * Globally unique notification message ID defined by application.
84   *
85   * @type { ?string }
86   * @syscap SystemCapability.Notification.Notification
87   * @since 12
88   */
89  appMessageId?: string;
90
91  /**
92   * Notification slot type.
93   *
94   * @type { ?notification.SlotType }
95   * @syscap SystemCapability.Notification.Notification
96   * @since 7
97   * @deprecated since 11
98   * @useinstead NotificationRequest#notificationSlotType
99   */
100  slotType?: notification.SlotType;
101
102  /**
103   * Notification slot type.
104   *
105   * @type { ?notificationManager.SlotType }
106   * @syscap SystemCapability.Notification.Notification
107   * @since 11
108   */
109  notificationSlotType?: notificationManager.SlotType;
110
111  /**
112   * Whether the notification is an ongoing notification.
113   *
114   * @type { ?boolean }
115   * @syscap SystemCapability.Notification.Notification
116   * @since 7
117   */
118  /**
119   * Whether the notification is an ongoing notification.
120   *
121   * @type { ?boolean }
122   * @syscap SystemCapability.Notification.Notification
123   * @crossplatform
124   * @since 12
125   */
126  isOngoing?: boolean;
127
128  /**
129   * Whether the notification can be removed.
130   *
131   * @type { ?boolean }
132   * @syscap SystemCapability.Notification.Notification
133   * @since 7
134   */
135  isUnremovable?: boolean;
136
137  /**
138   * Time when the notification is sent.
139   *
140   * @type { ?number }
141   * @syscap SystemCapability.Notification.Notification
142   * @since 7
143   */
144  /**
145   * Time when the notification is sent.
146   *
147   * @type { ?number }
148   * @syscap SystemCapability.Notification.Notification
149   * @crossplatform
150   * @since 12
151   */
152  deliveryTime?: number;
153
154  /**
155   * Whether the notification is automatically cleared.
156   *
157   * @type { ?boolean }
158   * @syscap SystemCapability.Notification.Notification
159   * @since 7
160   */
161  /**
162   * Whether the notification is automatically cleared.
163   *
164   * @type { ?boolean }
165   * @syscap SystemCapability.Notification.Notification
166   * @crossplatform
167   * @since 12
168   */
169  tapDismissed?: boolean;
170
171  /**
172   * Time when the notification is automatically cleared.
173   *
174   * @type { ?number }
175   * @syscap SystemCapability.Notification.Notification
176   * @since 7
177   */
178  /**
179   * Time when the notification is automatically cleared.
180   *
181   * @type { ?number }
182   * @syscap SystemCapability.Notification.Notification
183   * @crossplatform
184   * @since 12
185   */
186  autoDeletedTime?: number;
187
188  /**
189   * WantAgent instance to which the notification will be redirected after being clicked.
190   *
191   * @type { ?WantAgent }
192   * @syscap SystemCapability.Notification.Notification
193   * @since 7
194   */
195  wantAgent?: WantAgent;
196
197  /**
198   * Extended parameter.
199   *
200   * @type { ?object }
201   * @syscap SystemCapability.Notification.Notification
202   * @since 7
203   */
204  extraInfo?: { [key: string]: any };
205
206  /**
207   * Background color of the notification.
208   *
209   * @type { ?number }
210   * @syscap SystemCapability.Notification.Notification
211   * @since 7
212   */
213  color?: number;
214
215  /**
216   * Whether the notification background color can be enabled.
217   *
218   * @type { ?boolean }
219   * @syscap SystemCapability.Notification.Notification
220   * @since 7
221   */
222  colorEnabled?: boolean;
223
224  /**
225   * Whether the notification triggers an alert only once.
226   *
227   * @type { ?boolean }
228   * @syscap SystemCapability.Notification.Notification
229   * @since 7
230   */
231  /**
232   * Whether the notification triggers an alert only once.
233   *
234   * @type { ?boolean }
235   * @syscap SystemCapability.Notification.Notification
236   * @crossplatform
237   * @since 12
238   */
239  isAlertOnce?: boolean;
240
241  /**
242   * Whether to display the stopwatch.
243   *
244   * @type { ?boolean }
245   * @syscap SystemCapability.Notification.Notification
246   * @since 7
247   */
248  isStopwatch?: boolean;
249
250  /**
251   * Whether to display the countdown time.
252   *
253   * @type { ?boolean }
254   * @syscap SystemCapability.Notification.Notification
255   * @since 7
256   */
257  isCountDown?: boolean;
258
259  /**
260   * Whether the notification is displayed as a floating icon.
261   *
262   * @type { ?boolean }
263   * @syscap SystemCapability.Notification.Notification
264   * @since 7
265   */
266  isFloatingIcon?: boolean;
267
268  /**
269   * Notification label.
270   *
271   * @type { ?string }
272   * @syscap SystemCapability.Notification.Notification
273   * @since 7
274   */
275  label?: string;
276
277  /**
278   * Notification badge type.
279   *
280   * @type { ?number }
281   * @syscap SystemCapability.Notification.Notification
282   * @since 7
283   */
284  badgeIconStyle?: number;
285
286  /**
287   * Whether to display the time when the notification is delivered.
288   *
289   * @type { ?boolean }
290   * @syscap SystemCapability.Notification.Notification
291   * @since 7
292   */
293  /**
294   * Whether to display the time when the notification is delivered.
295   *
296   * @type { ?boolean }
297   * @syscap SystemCapability.Notification.Notification
298   * @crossplatform
299   * @since 12
300   */
301  showDeliveryTime?: boolean;
302
303  /**
304   * Buttons in the notification. Up to two buttons are allowed.
305   *
306   * @type { ?Array<NotificationActionButton> }
307   * @syscap SystemCapability.Notification.Notification
308   * @since 7
309   */
310  actionButtons?: Array<NotificationActionButton>;
311
312  /**
313   * Small notification icon.
314   *
315   * @type { ?image.PixelMap }
316   * @syscap SystemCapability.Notification.Notification
317   * @since 7
318   */
319  smallIcon?: image.PixelMap;
320
321  /**
322   * Large notification icon.
323   *
324   * @type { ?image.PixelMap }
325   * @syscap SystemCapability.Notification.Notification
326   * @since 7
327   */
328  largeIcon?: image.PixelMap;
329
330  /**
331   * Overlay notification icon.
332   *
333   * @type { ?image.PixelMap }
334   * @syscap SystemCapability.Notification.Notification
335   * @systemapi
336   * @since 11
337   */
338  overlayIcon?: image.PixelMap;
339
340  /**
341   * The group information for this notification.
342   *
343   * @type { ?string }
344   * @syscap SystemCapability.Notification.Notification
345   * @since 8
346   */
347  /**
348   * The group information for this notification.
349   *
350   * @type { ?string }
351   * @syscap SystemCapability.Notification.Notification
352   * @crossplatform
353   * @since 12
354   */
355  groupName?: string;
356
357  /**
358   * Read-only name of the package for which a notification is created.
359   *
360   * @type { ?string }
361   * @readonly
362   * @syscap SystemCapability.Notification.Notification
363   * @since 7
364   */
365  readonly creatorBundleName?: string;
366
367  /**
368   * Read-only UID of the notification creator.
369   *
370   * @type { ?number }
371   * @readonly
372   * @syscap SystemCapability.Notification.Notification
373   * @since 7
374   */
375  readonly creatorUid?: number;
376
377  /**
378   * Read-only PID of the notification creator.
379   *
380   * @type { ?number }
381   * @readonly
382   * @syscap SystemCapability.Notification.Notification
383   * @since 7
384   */
385  readonly creatorPid?: number;
386
387  /**
388   * Read-only UserId of the notification creator.
389   *
390   * @type { ?number }
391   * @readonly
392   * @syscap SystemCapability.Notification.Notification
393   * @since 8
394   */
395  readonly creatorUserId?: number;
396
397  /**
398   * Application instance key.
399   *
400   * @type { ?number }
401   * @readonly
402   * @syscap SystemCapability.Notification.Notification
403   * @systemapi
404   * @since 12
405   */
406  readonly creatorInstanceKey?: number;
407
408  /**
409   * Obtain the prompt tone resource path of the notification.
410   *
411   * @type { ?string }
412   * @syscap SystemCapability.Notification.Notification
413   * @since 12
414   */
415  sound?: string;
416
417  /**
418   * Obtains the classification of this notification.
419   *
420   * @type { ?string }
421   * @syscap SystemCapability.Notification.Notification
422   * @systemapi
423   * @since 7
424   */
425  classification?: string;
426
427  /**
428   * Obtains the unique hash code of a notification in the current application.
429   *
430   * @type { ?string }
431   * @readonly
432   * @syscap SystemCapability.Notification.Notification
433   * @since 7
434   */
435  readonly hashCode?: string;
436
437  /**
438   * Whether the notification can be remove.
439   *
440   * @type { ?boolean }
441   * @default true
442   * @syscap SystemCapability.Notification.Notification
443   * @systemapi
444   * @since 8
445   */
446  /**
447   * Whether the notification can be remove.
448   *
449   * @permission ohos.permission.SET_UNREMOVABLE_NOTIFICATION
450   * @type { ?boolean }
451   * @default true
452   * @syscap SystemCapability.Notification.Notification
453   * @systemapi
454   * @since 11
455   */
456  isRemoveAllowed?: boolean;
457
458  /**
459   * Notification source. enum SourceType
460   *
461   * @type { ?number }
462   * @syscap SystemCapability.Notification.Notification
463   * @systemapi
464   * @since 8
465   */
466  readonly source?: number;
467
468  /**
469   * Obtains the template of this notification.
470   *
471   * @type { ?NotificationTemplate }
472   * @syscap SystemCapability.Notification.Notification
473   * @since 8
474   */
475  template?: NotificationTemplate;
476
477  /**
478   * The options to distributed notification.
479   *
480   * @type { ?DistributedOptions }
481   * @syscap SystemCapability.Notification.Notification
482   * @since 8
483   */
484  distributedOption?: DistributedOptions;
485
486  /**
487   * The device ID of the notification source.
488   *
489   * @type { ?string }
490   * @syscap SystemCapability.Notification.Notification
491   * @systemapi
492   * @since 8
493   */
494  readonly deviceId?: string;
495
496  /**
497   * Obtains the set of identifiers for the notification.
498   *
499   * @type { ?NotificationFlags }
500   * @syscap SystemCapability.Notification.Notification
501   * @since 8
502   */
503  readonly notificationFlags?: NotificationFlags;
504
505  /**
506   * WantAgent instance to which the notification will be redirected when removing notification.
507   *
508   * @type { ?WantAgent }
509   * @syscap SystemCapability.Notification.Notification
510   * @since 9
511   */
512  removalWantAgent?: WantAgent;
513
514  /**
515   * Number of notifications displayed on the app icon.
516   *
517   * @type { ?number }
518   * @syscap SystemCapability.Notification.Notification
519   * @since 9
520   */
521  /**
522   * Number of notifications displayed on the app icon.
523   *
524   * @type { ?number }
525   * @syscap SystemCapability.Notification.Notification
526   * @crossplatform
527   * @since 12
528   */
529  badgeNumber?: number;
530
531  /**
532   * Whether the notification need to be agent display.
533   *
534   * @type { ?BundleOption }
535   * @syscap SystemCapability.Notification.Notification
536   * @systemapi
537   * @since 12
538   */
539  representativeBundle?: BundleOption;
540
541  /**
542   * Proxy identity of creation notification.
543   *
544   * @type { ?BundleOption }
545   * @syscap SystemCapability.Notification.Notification
546   * @systemapi
547   * @since 12
548   */
549  readonly agentBundle?: BundleOption;
550
551  /**
552   * Unified aggregation of information across applications.
553   *
554   * @type { ?UnifiedGroupInfo }
555   * @syscap SystemCapability.Notification.Notification
556   * @systemapi
557   * @since 12
558   */
559  unifiedGroupInfo?: UnifiedGroupInfo;
560
561  /**
562   * Notification control flags.
563   *
564   * @type { ?number }
565   * @syscap SystemCapability.Notification.Notification
566   * @systemapi
567   * @since 12
568   */
569  notificationControlFlags?: number;
570}
571
572/**
573 * Describes distributed options.
574 *
575 * @typedef DistributedOptions
576 * @syscap SystemCapability.Notification.Notification
577 * @since 8
578 */
579export interface DistributedOptions {
580  /**
581   * Obtains whether is the distributed notification.
582   *
583   * @type { ?boolean }
584   * @default true
585   * @syscap SystemCapability.Notification.Notification
586   * @since 8
587   */
588  isDistributed?: boolean;
589
590  /**
591   * Obtains the types of devices to which the notification can be synchronized.
592   *
593   * @type { ?Array<string> }
594   * @syscap SystemCapability.Notification.Notification
595   * @since 8
596   */
597  supportDisplayDevices?: Array<string>;
598
599  /**
600   * Obtains the devices on which notifications can be open.
601   *
602   * @type { ?Array<string> }
603   * @syscap SystemCapability.Notification.Notification
604   * @since 8
605   */
606  supportOperateDevices?: Array<string>;
607
608  /**
609   * Obtains the remind mode of the notification. enum DeviceRemindType.
610   *
611   * @type { ?number }
612   * @syscap SystemCapability.Notification.Notification
613   * @systemapi
614   * @since 8
615   */
616  readonly remindType?: number;
617}
618
619/**
620 * Describes notification filter.
621 *
622 * @typedef NotificationFilter
623 * @syscap SystemCapability.Notification.Notification
624 * @systemapi
625 * @since 11
626 */
627export interface NotificationFilter {
628  /**
629   * BundleOption of the notification.
630   *
631   * @type { BundleOption }
632   * @syscap SystemCapability.Notification.Notification
633   * @systemapi
634   * @since 11
635   */
636  bundle: BundleOption;
637
638  /**
639   * Indicates the label and id of the notification.
640   *
641   * @type { notificationSubscribe.NotificationKey }
642   * @syscap SystemCapability.Notification.Notification
643   * @systemapi
644   * @since 11
645   */
646  notificationKey: notificationSubscribe.NotificationKey;
647
648  /**
649   * Indicates the additional information filter keys list.
650   *
651   * @type { ?Array<string> }
652   * @syscap SystemCapability.Notification.Notification
653   * @systemapi
654   * @since 11
655   */
656  extraInfoKeys?: Array<string>;
657}
658
659/**
660 * Describes notification check information.
661 *
662 * @typedef NotificationCheckRequest
663 * @syscap SystemCapability.Notification.Notification
664 * @systemapi
665 * @since 11
666 */
667export interface NotificationCheckRequest {
668  /**
669   * The notification content type.
670   *
671   * @type { notificationManager.ContentType }
672   * @syscap SystemCapability.Notification.Notification
673   * @systemapi
674   * @since 11
675   */
676  contentType: notificationManager.ContentType;
677
678  /**
679   * Type of the notification slot..
680   *
681   * @type { notificationManager.SlotType }
682   * @syscap SystemCapability.Notification.Notification
683   * @systemapi
684   * @since 11
685   */
686  slotType: notificationManager.SlotType;
687
688  /**
689   * Additional information of the notification.
690   *
691   * @type { Array<string> }
692   * @syscap SystemCapability.Notification.Notification
693   * @systemapi
694   * @since 11
695   */
696  extraInfoKeys: Array<string>;
697}
698
699/**
700 * Unified aggregation of information across applications.
701 *
702 * @typedef UnifiedGroupInfo
703 * @syscap SystemCapability.Notification.Notification
704 * @systemapi
705 * @since 12
706 */
707export interface UnifiedGroupInfo {
708  /**
709   * The key is aggregated across applications.
710   *
711   * @type { ?string }
712   * @syscap SystemCapability.Notification.Notification
713   * @systemapi
714   * @since 12
715   */
716  key?: string;
717
718  /**
719   * The title is aggregated across applications.
720   *
721   * @type { ?string }
722   * @syscap SystemCapability.Notification.Notification
723   * @systemapi
724   * @since 12
725   */
726  title?: string;
727
728  /**
729   * The content is aggregated across applications.
730   *
731   * @type { ?string }
732   * @syscap SystemCapability.Notification.Notification
733   * @systemapi
734   * @since 12
735   */
736  content?: string;
737
738  /**
739   * Aggregation scenario name.
740   *
741   * @type { ?string }
742   * @syscap SystemCapability.Notification.Notification
743   * @systemapi
744   * @since 12
745   */
746  sceneName?: string;
747
748  /**
749   * Other information is aggregated across applications.
750   *
751   * @type { ?object }
752   * @syscap SystemCapability.Notification.Notification
753   * @systemapi
754   * @since 12
755   */
756  extraInfo?: { [key: string]: any };
757}
758