• 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   * Whether the notification can only be updated.
139   *
140   * @type { ?boolean }
141   * @syscap SystemCapability.Notification.Notification
142   * @since 18
143   */
144  updateOnly?: boolean;
145
146  /**
147   * Time when the notification is sent.
148   *
149   * @type { ?number }
150   * @syscap SystemCapability.Notification.Notification
151   * @since 7
152   */
153  /**
154   * Time when the notification is sent.
155   *
156   * @type { ?number }
157   * @syscap SystemCapability.Notification.Notification
158   * @crossplatform
159   * @since 12
160   */
161  deliveryTime?: number;
162
163  /**
164   * Whether the notification is automatically cleared.
165   *
166   * @type { ?boolean }
167   * @syscap SystemCapability.Notification.Notification
168   * @since 7
169   */
170  /**
171   * Whether the notification is automatically cleared.
172   *
173   * @type { ?boolean }
174   * @syscap SystemCapability.Notification.Notification
175   * @crossplatform
176   * @since 12
177   */
178  tapDismissed?: boolean;
179
180  /**
181   * Time when the notification is automatically cleared.
182   *
183   * @type { ?number }
184   * @syscap SystemCapability.Notification.Notification
185   * @since 7
186   */
187  /**
188   * Time when the notification is automatically cleared.
189   *
190   * @type { ?number }
191   * @syscap SystemCapability.Notification.Notification
192   * @crossplatform
193   * @since 12
194   */
195  autoDeletedTime?: number;
196
197  /**
198   * WantAgent instance to which the notification will be redirected after being clicked.
199   *
200   * @type { ?WantAgent }
201   * @syscap SystemCapability.Notification.Notification
202   * @since 7
203   */
204  wantAgent?: WantAgent;
205
206  /**
207   * Extended parameter.
208   *
209   * @type { ?object }
210   * @syscap SystemCapability.Notification.Notification
211   * @since 7
212   */
213  extraInfo?: { [key: string]: any };
214
215  /**
216   * Background color of the notification.
217   *
218   * @type { ?number }
219   * @syscap SystemCapability.Notification.Notification
220   * @since 7
221   */
222  color?: number;
223
224  /**
225   * Whether the notification background color can be enabled.
226   *
227   * @type { ?boolean }
228   * @syscap SystemCapability.Notification.Notification
229   * @since 7
230   */
231  colorEnabled?: boolean;
232
233  /**
234   * Whether the notification triggers an alert only once.
235   *
236   * @type { ?boolean }
237   * @syscap SystemCapability.Notification.Notification
238   * @since 7
239   */
240  /**
241   * Whether the notification triggers an alert only once.
242   *
243   * @type { ?boolean }
244   * @syscap SystemCapability.Notification.Notification
245   * @crossplatform
246   * @since 12
247   */
248  isAlertOnce?: boolean;
249
250  /**
251   * Whether to display the stopwatch.
252   *
253   * @type { ?boolean }
254   * @syscap SystemCapability.Notification.Notification
255   * @since 7
256   */
257  isStopwatch?: boolean;
258
259  /**
260   * Whether to display the countdown time.
261   *
262   * @type { ?boolean }
263   * @syscap SystemCapability.Notification.Notification
264   * @since 7
265   */
266  isCountDown?: boolean;
267
268  /**
269   * Whether the notification is displayed as a floating icon.
270   *
271   * @type { ?boolean }
272   * @syscap SystemCapability.Notification.Notification
273   * @since 7
274   */
275  isFloatingIcon?: boolean;
276
277  /**
278   * Notification label.
279   *
280   * @type { ?string }
281   * @syscap SystemCapability.Notification.Notification
282   * @since 7
283   */
284  label?: string;
285
286  /**
287   * Notification badge type.
288   *
289   * @type { ?number }
290   * @syscap SystemCapability.Notification.Notification
291   * @since 7
292   */
293  badgeIconStyle?: number;
294
295  /**
296   * Whether to display the time when the notification is delivered.
297   *
298   * @type { ?boolean }
299   * @syscap SystemCapability.Notification.Notification
300   * @since 7
301   */
302  /**
303   * Whether to display the time when the notification is delivered.
304   *
305   * @type { ?boolean }
306   * @syscap SystemCapability.Notification.Notification
307   * @crossplatform
308   * @since 12
309   */
310  showDeliveryTime?: boolean;
311
312  /**
313   * Buttons in the notification. Up to two buttons are allowed.
314   *
315   * @type { ?Array<NotificationActionButton> }
316   * @syscap SystemCapability.Notification.Notification
317   * @since 7
318   */
319  actionButtons?: Array<NotificationActionButton>;
320
321  /**
322   * Small notification icon.
323   *
324   * @type { ?image.PixelMap }
325   * @syscap SystemCapability.Notification.Notification
326   * @since 7
327   */
328  smallIcon?: image.PixelMap;
329
330  /**
331   * Large notification icon.
332   *
333   * @type { ?image.PixelMap }
334   * @syscap SystemCapability.Notification.Notification
335   * @since 7
336   */
337  largeIcon?: image.PixelMap;
338
339  /**
340   * Overlay notification icon.
341   *
342   * @type { ?image.PixelMap }
343   * @syscap SystemCapability.Notification.Notification
344   * @systemapi
345   * @since 11
346   */
347  overlayIcon?: image.PixelMap;
348
349  /**
350   * The group information for this notification.
351   *
352   * @type { ?string }
353   * @syscap SystemCapability.Notification.Notification
354   * @since 8
355   */
356  /**
357   * The group information for this notification.
358   *
359   * @type { ?string }
360   * @syscap SystemCapability.Notification.Notification
361   * @crossplatform
362   * @since 12
363   */
364  groupName?: string;
365
366  /**
367   * Read-only name of the package for which a notification is created.
368   *
369   * @type { ?string }
370   * @readonly
371   * @syscap SystemCapability.Notification.Notification
372   * @since 7
373   */
374  readonly creatorBundleName?: string;
375
376  /**
377   * Read-only UID of the notification creator.
378   *
379   * @type { ?number }
380   * @readonly
381   * @syscap SystemCapability.Notification.Notification
382   * @since 7
383   */
384  readonly creatorUid?: number;
385
386  /**
387   * Read-only PID of the notification creator.
388   *
389   * @type { ?number }
390   * @readonly
391   * @syscap SystemCapability.Notification.Notification
392   * @since 7
393   */
394  readonly creatorPid?: number;
395
396  /**
397   * Read-only UserId of the notification creator.
398   *
399   * @type { ?number }
400   * @readonly
401   * @syscap SystemCapability.Notification.Notification
402   * @since 8
403   */
404  readonly creatorUserId?: number;
405
406  /**
407   * Application instance key.
408   *
409   * @type { ?number }
410   * @readonly
411   * @syscap SystemCapability.Notification.Notification
412   * @systemapi
413   * @since 12
414   * @deprecated since 15
415   * @useinstead NotificationRequest#appInstanceKey
416   */
417  readonly creatorInstanceKey?: number;
418
419  /**
420   * Obtain the prompt tone resource path of the notification.
421   *
422   * @type { ?string }
423   * @syscap SystemCapability.Notification.Notification
424   * @since 12
425   */
426  sound?: string;
427
428  /**
429   * Obtains the classification of this notification.
430   *
431   * @type { ?string }
432   * @syscap SystemCapability.Notification.Notification
433   * @systemapi
434   * @since 7
435   */
436  classification?: string;
437
438  /**
439   * Obtains the unique hash code of a notification in the current application.
440   *
441   * @type { ?string }
442   * @readonly
443   * @syscap SystemCapability.Notification.Notification
444   * @since 7
445   */
446  readonly hashCode?: string;
447
448  /**
449   * Whether the notification can be remove.
450   *
451   * @type { ?boolean }
452   * @default true
453   * @syscap SystemCapability.Notification.Notification
454   * @systemapi
455   * @since 8
456   */
457  /**
458   * Whether the notification can be remove.
459   *
460   * @permission ohos.permission.SET_UNREMOVABLE_NOTIFICATION
461   * @type { ?boolean }
462   * @default true
463   * @syscap SystemCapability.Notification.Notification
464   * @systemapi
465   * @since 11
466   */
467  isRemoveAllowed?: boolean;
468
469  /**
470   * Notification source. enum SourceType
471   *
472   * @type { ?number }
473   * @readonly
474   * @syscap SystemCapability.Notification.Notification
475   * @systemapi
476   * @since 8
477   */
478  readonly source?: number;
479
480  /**
481   * Obtains the template of this notification.
482   *
483   * @type { ?NotificationTemplate }
484   * @syscap SystemCapability.Notification.Notification
485   * @since 8
486   */
487  template?: NotificationTemplate;
488
489  /**
490   * The options to distributed notification.
491   *
492   * @type { ?DistributedOptions }
493   * @syscap SystemCapability.Notification.Notification
494   * @since 8
495   */
496  distributedOption?: DistributedOptions;
497
498  /**
499   * The device ID of the notification source.
500   *
501   * @type { ?string }
502   * @readonly
503   * @syscap SystemCapability.Notification.Notification
504   * @systemapi
505   * @since 8
506   */
507  readonly deviceId?: string;
508
509  /**
510   * Obtains the set of identifiers for the notification.
511   *
512   * @type { ?NotificationFlags }
513   * @readonly
514   * @syscap SystemCapability.Notification.Notification
515   * @since 8
516   */
517  readonly notificationFlags?: NotificationFlags;
518
519  /**
520   * WantAgent instance to which the notification will be redirected when removing notification.
521   *
522   * @type { ?WantAgent }
523   * @syscap SystemCapability.Notification.Notification
524   * @since 9
525   */
526  removalWantAgent?: WantAgent;
527
528  /**
529   * Number of notifications displayed on the app icon.
530   *
531   * @type { ?number }
532   * @syscap SystemCapability.Notification.Notification
533   * @since 9
534   */
535  /**
536   * Number of notifications displayed on the app icon.
537   *
538   * @type { ?number }
539   * @syscap SystemCapability.Notification.Notification
540   * @crossplatform
541   * @since 12
542   */
543  badgeNumber?: number;
544
545  /**
546   * Whether the notification need to be agent display.
547   *
548   * @type { ?BundleOption }
549   * @syscap SystemCapability.Notification.Notification
550   * @systemapi
551   * @since 12
552   */
553  representativeBundle?: BundleOption;
554
555  /**
556   * Proxy identity of creation notification.
557   *
558   * @type { ?BundleOption }
559   * @readonly
560   * @syscap SystemCapability.Notification.Notification
561   * @systemapi
562   * @since 12
563   */
564  readonly agentBundle?: BundleOption;
565
566  /**
567   * Unified aggregation of information across applications.
568   *
569   * @type { ?UnifiedGroupInfo }
570   * @syscap SystemCapability.Notification.Notification
571   * @systemapi
572   * @since 12
573   */
574  unifiedGroupInfo?: UnifiedGroupInfo;
575
576  /**
577   * Notification control flags.
578   *
579   * @type { ?number }
580   * @syscap SystemCapability.Notification.Notification
581   * @systemapi
582   * @since 12
583   */
584  notificationControlFlags?: number;
585
586  /**
587   * Application instance key.
588   *
589   * @type { ?string }
590   * @readonly
591   * @syscap SystemCapability.Notification.Notification
592   * @systemapi
593   * @since 15
594   */
595  readonly appInstanceKey?: string;
596
597  /**
598   * Force distributed forwarding flag.
599   *
600   * @type { ?boolean }
601   * @default false
602   * @syscap SystemCapability.Notification.Notification
603   * @systemapi
604   * @since 18
605   */
606  forceDistributed?: boolean;
607
608  /**
609   * Distributed forwarding flag.
610   *
611   * @type { ?boolean }
612   * @default false
613   * @syscap SystemCapability.Notification.Notification
614   * @systemapi
615   * @since 18
616   */
617  notDistributed?: boolean;
618}
619
620/**
621 * Describes distributed options.
622 *
623 * @typedef DistributedOptions
624 * @syscap SystemCapability.Notification.Notification
625 * @since 8
626 */
627export interface DistributedOptions {
628  /**
629   * Obtains whether is the distributed notification.
630   *
631   * @type { ?boolean }
632   * @default true
633   * @syscap SystemCapability.Notification.Notification
634   * @since 8
635   */
636  isDistributed?: boolean;
637
638  /**
639   * Obtains the types of devices to which the notification can be synchronized.
640   *
641   * @type { ?Array<string> }
642   * @syscap SystemCapability.Notification.Notification
643   * @since 8
644   */
645  supportDisplayDevices?: Array<string>;
646
647  /**
648   * Obtains the devices on which notifications can be open.
649   *
650   * @type { ?Array<string> }
651   * @syscap SystemCapability.Notification.Notification
652   * @since 8
653   */
654  supportOperateDevices?: Array<string>;
655
656  /**
657   * Obtains the remind mode of the notification. enum DeviceRemindType.
658   *
659   * @type { ?number }
660   * @readonly
661   * @syscap SystemCapability.Notification.Notification
662   * @systemapi
663   * @since 8
664   */
665  readonly remindType?: number;
666}
667
668/**
669 * Describes notification filter.
670 *
671 * @typedef NotificationFilter
672 * @syscap SystemCapability.Notification.Notification
673 * @systemapi
674 * @since 11
675 */
676export interface NotificationFilter {
677  /**
678   * BundleOption of the notification.
679   *
680   * @type { BundleOption }
681   * @syscap SystemCapability.Notification.Notification
682   * @systemapi
683   * @since 11
684   */
685  bundle: BundleOption;
686
687  /**
688   * Indicates the label and id of the notification.
689   *
690   * @type { notificationSubscribe.NotificationKey }
691   * @syscap SystemCapability.Notification.Notification
692   * @systemapi
693   * @since 11
694   */
695  notificationKey: notificationSubscribe.NotificationKey;
696
697  /**
698   * Indicates the additional information filter keys list.
699   *
700   * @type { ?Array<string> }
701   * @syscap SystemCapability.Notification.Notification
702   * @systemapi
703   * @since 11
704   */
705  extraInfoKeys?: Array<string>;
706}
707
708/**
709 * Describes notification check information.
710 *
711 * @typedef NotificationCheckRequest
712 * @syscap SystemCapability.Notification.Notification
713 * @systemapi
714 * @since 11
715 */
716export interface NotificationCheckRequest {
717  /**
718   * The notification content type.
719   *
720   * @type { notificationManager.ContentType }
721   * @syscap SystemCapability.Notification.Notification
722   * @systemapi
723   * @since 11
724   */
725  contentType: notificationManager.ContentType;
726
727  /**
728   * Type of the notification slot..
729   *
730   * @type { notificationManager.SlotType }
731   * @syscap SystemCapability.Notification.Notification
732   * @systemapi
733   * @since 11
734   */
735  slotType: notificationManager.SlotType;
736
737  /**
738   * Additional information of the notification.
739   *
740   * @type { Array<string> }
741   * @syscap SystemCapability.Notification.Notification
742   * @systemapi
743   * @since 11
744   */
745  extraInfoKeys: Array<string>;
746}
747
748/**
749 * Unified aggregation of information across applications.
750 *
751 * @typedef UnifiedGroupInfo
752 * @syscap SystemCapability.Notification.Notification
753 * @systemapi
754 * @since 12
755 */
756export interface UnifiedGroupInfo {
757  /**
758   * The key is aggregated across applications.
759   *
760   * @type { ?string }
761   * @syscap SystemCapability.Notification.Notification
762   * @systemapi
763   * @since 12
764   */
765  key?: string;
766
767  /**
768   * The title is aggregated across applications.
769   *
770   * @type { ?string }
771   * @syscap SystemCapability.Notification.Notification
772   * @systemapi
773   * @since 12
774   */
775  title?: string;
776
777  /**
778   * The content is aggregated across applications.
779   *
780   * @type { ?string }
781   * @syscap SystemCapability.Notification.Notification
782   * @systemapi
783   * @since 12
784   */
785  content?: string;
786
787  /**
788   * Aggregation scenario name.
789   *
790   * @type { ?string }
791   * @syscap SystemCapability.Notification.Notification
792   * @systemapi
793   * @since 12
794   */
795  sceneName?: string;
796
797  /**
798   * Other information is aggregated across applications.
799   *
800   * @type { ?object }
801   * @syscap SystemCapability.Notification.Notification
802   * @systemapi
803   * @since 12
804   */
805  extraInfo?: { [key: string]: any };
806}
807