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