• 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   * @readonly
463   * @syscap SystemCapability.Notification.Notification
464   * @systemapi
465   * @since 8
466   */
467  readonly source?: number;
468
469  /**
470   * Obtains the template of this notification.
471   *
472   * @type { ?NotificationTemplate }
473   * @syscap SystemCapability.Notification.Notification
474   * @since 8
475   */
476  template?: NotificationTemplate;
477
478  /**
479   * The options to distributed notification.
480   *
481   * @type { ?DistributedOptions }
482   * @syscap SystemCapability.Notification.Notification
483   * @since 8
484   */
485  distributedOption?: DistributedOptions;
486
487  /**
488   * The device ID of the notification source.
489   *
490   * @type { ?string }
491   * @readonly
492   * @syscap SystemCapability.Notification.Notification
493   * @systemapi
494   * @since 8
495   */
496  readonly deviceId?: string;
497
498  /**
499   * Obtains the set of identifiers for the notification.
500   *
501   * @type { ?NotificationFlags }
502   * @readonly
503   * @syscap SystemCapability.Notification.Notification
504   * @since 8
505   */
506  readonly notificationFlags?: NotificationFlags;
507
508  /**
509   * WantAgent instance to which the notification will be redirected when removing notification.
510   *
511   * @type { ?WantAgent }
512   * @syscap SystemCapability.Notification.Notification
513   * @since 9
514   */
515  removalWantAgent?: WantAgent;
516
517  /**
518   * Number of notifications displayed on the app icon.
519   *
520   * @type { ?number }
521   * @syscap SystemCapability.Notification.Notification
522   * @since 9
523   */
524  /**
525   * Number of notifications displayed on the app icon.
526   *
527   * @type { ?number }
528   * @syscap SystemCapability.Notification.Notification
529   * @crossplatform
530   * @since 12
531   */
532  badgeNumber?: number;
533
534  /**
535   * Whether the notification need to be agent display.
536   *
537   * @type { ?BundleOption }
538   * @syscap SystemCapability.Notification.Notification
539   * @systemapi
540   * @since 12
541   */
542  representativeBundle?: BundleOption;
543
544  /**
545   * Proxy identity of creation notification.
546   *
547   * @type { ?BundleOption }
548   * @readonly
549   * @syscap SystemCapability.Notification.Notification
550   * @systemapi
551   * @since 12
552   */
553  readonly agentBundle?: BundleOption;
554
555  /**
556   * Unified aggregation of information across applications.
557   *
558   * @type { ?UnifiedGroupInfo }
559   * @syscap SystemCapability.Notification.Notification
560   * @systemapi
561   * @since 12
562   */
563  unifiedGroupInfo?: UnifiedGroupInfo;
564
565  /**
566   * Notification control flags.
567   *
568   * @type { ?number }
569   * @syscap SystemCapability.Notification.Notification
570   * @systemapi
571   * @since 12
572   */
573  notificationControlFlags?: number;
574}
575
576/**
577 * Describes distributed options.
578 *
579 * @typedef DistributedOptions
580 * @syscap SystemCapability.Notification.Notification
581 * @since 8
582 */
583export interface DistributedOptions {
584  /**
585   * Obtains whether is the distributed notification.
586   *
587   * @type { ?boolean }
588   * @default true
589   * @syscap SystemCapability.Notification.Notification
590   * @since 8
591   */
592  isDistributed?: boolean;
593
594  /**
595   * Obtains the types of devices to which the notification can be synchronized.
596   *
597   * @type { ?Array<string> }
598   * @syscap SystemCapability.Notification.Notification
599   * @since 8
600   */
601  supportDisplayDevices?: Array<string>;
602
603  /**
604   * Obtains the devices on which notifications can be open.
605   *
606   * @type { ?Array<string> }
607   * @syscap SystemCapability.Notification.Notification
608   * @since 8
609   */
610  supportOperateDevices?: Array<string>;
611
612  /**
613   * Obtains the remind mode of the notification. enum DeviceRemindType.
614   *
615   * @type { ?number }
616   * @readonly
617   * @syscap SystemCapability.Notification.Notification
618   * @systemapi
619   * @since 8
620   */
621  readonly remindType?: number;
622}
623
624/**
625 * Describes notification filter.
626 *
627 * @typedef NotificationFilter
628 * @syscap SystemCapability.Notification.Notification
629 * @systemapi
630 * @since 11
631 */
632export interface NotificationFilter {
633  /**
634   * BundleOption of the notification.
635   *
636   * @type { BundleOption }
637   * @syscap SystemCapability.Notification.Notification
638   * @systemapi
639   * @since 11
640   */
641  bundle: BundleOption;
642
643  /**
644   * Indicates the label and id of the notification.
645   *
646   * @type { notificationSubscribe.NotificationKey }
647   * @syscap SystemCapability.Notification.Notification
648   * @systemapi
649   * @since 11
650   */
651  notificationKey: notificationSubscribe.NotificationKey;
652
653  /**
654   * Indicates the additional information filter keys list.
655   *
656   * @type { ?Array<string> }
657   * @syscap SystemCapability.Notification.Notification
658   * @systemapi
659   * @since 11
660   */
661  extraInfoKeys?: Array<string>;
662}
663
664/**
665 * Describes notification check information.
666 *
667 * @typedef NotificationCheckRequest
668 * @syscap SystemCapability.Notification.Notification
669 * @systemapi
670 * @since 11
671 */
672export interface NotificationCheckRequest {
673  /**
674   * The notification content type.
675   *
676   * @type { notificationManager.ContentType }
677   * @syscap SystemCapability.Notification.Notification
678   * @systemapi
679   * @since 11
680   */
681  contentType: notificationManager.ContentType;
682
683  /**
684   * Type of the notification slot..
685   *
686   * @type { notificationManager.SlotType }
687   * @syscap SystemCapability.Notification.Notification
688   * @systemapi
689   * @since 11
690   */
691  slotType: notificationManager.SlotType;
692
693  /**
694   * Additional information of the notification.
695   *
696   * @type { Array<string> }
697   * @syscap SystemCapability.Notification.Notification
698   * @systemapi
699   * @since 11
700   */
701  extraInfoKeys: Array<string>;
702}
703
704/**
705 * Unified aggregation of information across applications.
706 *
707 * @typedef UnifiedGroupInfo
708 * @syscap SystemCapability.Notification.Notification
709 * @systemapi
710 * @since 12
711 */
712export interface UnifiedGroupInfo {
713  /**
714   * The key is aggregated across applications.
715   *
716   * @type { ?string }
717   * @syscap SystemCapability.Notification.Notification
718   * @systemapi
719   * @since 12
720   */
721  key?: string;
722
723  /**
724   * The title is aggregated across applications.
725   *
726   * @type { ?string }
727   * @syscap SystemCapability.Notification.Notification
728   * @systemapi
729   * @since 12
730   */
731  title?: string;
732
733  /**
734   * The content is aggregated across applications.
735   *
736   * @type { ?string }
737   * @syscap SystemCapability.Notification.Notification
738   * @systemapi
739   * @since 12
740   */
741  content?: string;
742
743  /**
744   * Aggregation scenario name.
745   *
746   * @type { ?string }
747   * @syscap SystemCapability.Notification.Notification
748   * @systemapi
749   * @since 12
750   */
751  sceneName?: string;
752
753  /**
754   * Other information is aggregated across applications.
755   *
756   * @type { ?object }
757   * @syscap SystemCapability.Notification.Notification
758   * @systemapi
759   * @since 12
760   */
761  extraInfo?: { [key: string]: any };
762}
763