目录

LiveViewCardExtensionAbility

LiveViewCardExtensionAbility is an ExtensionAbility component for the custom extension area of live view widgets. It is designed for real-time activity scenarios that require rich custom content in the extension area. By inheriting from this class and implementing the app's extension component, you can present customized content in the live view extension area.

Since: 26.0.0

Constraints

Modules to Import

import { LiveViewCardExtensionAbility } from '@kit.LiveViewKit';

Device behavior differences: This module is supported on phones and tablets, but does not respond on other device types.

LiveViewCardExtensionAbility

Model restriction: This attribute can be used only in the stage model.

System capability: SystemCapability.LiveView.LiveViewService

Device behavior differences: This API is supported on phones and tablets, but does not respond on other device types.

Since: 26.0.0

[h2]Attributes

Name Type Read-Only Optional Description
context LiveViewCardExtensionContext No No Context of LiveViewCardExtensionAbility, which inherits from ExtensionContext.

[h2]onRender

onRender(param: Record<string, string>): CardInfo

Callback triggered by the system when an instance of the component that you implement by inheriting from the LiveViewCardExtensionAbility is loaded. Within onRender, you can implement the service logic and UI component rendering for the widget extension area of a live view widget, and return CardInfo to be loaded to the system for page rendering.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.LiveView.LiveViewService

Device behavior differences: This API is supported on phones and tablets, but does not respond on other device types.

Since: 26.0.0

Parameters:

Name Type Mandatory Description
param Record<string, string> Yes

CustomLayout.abilityParameters passed in when you create a custom extension area for a live view widget.

By default, it contains the following keys (their values are assigned by the system; manual modifications will not take effect):

ohos.extra.param.key.colorMode: dark or light mode of the live view widget (dark: dark mode; light: light mode)

ohos.extra.param.key.fontColor: font color of the live view widget (the value is in #ARGB format, with a number sign (#) and 8 hexadecimal digits)

ohos.extra.param.key.contentWidth: width of the live view widget, in vp. (The distance between the left and right borders of the custom extension area and the live view widget borders is 12 vp each; that is, custom extension area width = live view widget width - 12 × 2).

Returns:

Type Description
CardInfo Widget rendering information object.

CardInfo

Widget rendering information object returned by the onRender API.

Model restriction: This attribute can be used only in the stage model.

System capability: SystemCapability.LiveView.LiveViewService

Device behavior differences: This API is supported on phones and tablets, but does not respond on other device types.

Since: 26.0.0

Name Type Read-Only Optional Description
pagePath string No No Path of the extension area page to be loaded into the system. The system will render the page.
storage LocalStorage No Yes Page-level UI state storage unit, which is used to pass the state attribute of the content specified by pagePath.

Example

import { LiveViewCardExtensionAbility } from '@kit.LiveViewKit';
import { CardInfo } from '@hms.core.liveview.LiveViewCardExtensionAbility';
import { hilog } from '@kit.PerformanceAnalysisKit';

export default class LiveViewCardExtAbility extends LiveViewCardExtensionAbility {
  onRender(param: Record<string, string>): CardInfo {
    hilog.info(0x0000, 'LiveViewCardTag', 'LiveViewCardExtAbility onRender begin.');

    // Construct the parameters from param into LocalStorage to pass them to the page for usage.
    const storage = new LocalStorage(param);

    // Load the custom extension area page of the live view widget.
    return {
      pagePath: 'pages/LiveViewCardPage',
      storage: storage
    }
  }
}
@Entry({ useSharedStorage: true })
@Component
struct LiveViewCardPage {
  private storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
  // Obtain the parameters passed in AbilityParameters.
  private words: string | undefined = this.storage?.get('words');

  // Parse and obtain the width, light/dark mode, and font color of the custom extension area of the live view widget.
  private contentWidth: string | undefined = this.storage?.get('ohos.extra.param.key.contentWidth');
  private colorMode: string | undefined = this.storage?.get('ohos.extra.param.key.colorMode');
  private fontColor: string | undefined = this.storage?.get('ohos.extra.param.key.fontColor');

  getFontColor(): string {
    // You can customize the font color based on the light/dark mode or use the default font color.
    let color = this.fontColor as string; // Default font color. If the default font color is used, delete the following colorMode-based check logic.
    // Customize the font color based on the value of colorMode.
    if (this.colorMode == 'dark') {
      // In dark mode, you can customize the font color based on service requirements. In the following example, the font color is red.
      color = '#FFFF3300';
    } else if (this.colorMode == 'light') {
      // In light mode, you can customize the font color based on your service requirements. In the following example, the font color is green.
      color = '#FF33CC66';
    }
    return color;
  }

  build() {
    Column() {
      Scroll() {
        Column() {
          Text(this.words)
            .fontColor(this.getFontColor())
        }
        .width(this.contentWidth)
      }
    }
  }
}

Appendix

The following table lists the APIs that LiveViewCardExtensionAbility is not allowed to call.

Kit Module
Ability Kit

@ohos.ability.featureAbility (FeatureAbility Module)

@ohos.ability.particleAbility (ParticleAbility Module)

@ohos.bundle.launcherBundleManager (launcherBundleManager Module)

@ohos.continuation.continuationManager (Continuation/Collaboration Management)

AppGallery Kit privacyManager (Privacy Agreement Management Service)
ArkData

@ohos.data.distributedData (Distributed Data Management)

@ohos.data.distributedDataObject (Distributed Data Object)

@ohos.data.distributedKVStore (Distributed KV Store)

ArkUI @ohos.window (Window)
Audio Kit @ohos.multimedia.audio (Audio Management)
AVSession Kit

@ohos.multimedia.avsession (Media Session Management)

@ohos.multimedia.avCastPicker (AVCastPicker)

Background Tasks Kit

@ohos.backgroundTaskManager (Background Task Management)

@ohos.resourceschedule.backgroundTaskManager (Background Task Management)

@ohos.reminderAgent (Agent-powered Reminder)

@ohos.reminderAgentManager (Agent-powered Reminder)

Basic Services Kit

@ohos.account.appAccount (Application Account Management)

@ohos.account.distributedAccount (Distributed Account Management)

@ohos.account.osAccount (OS Account Management)

@ohos.request (Upload and Download)

@ohos.wallpaper (Wallpaper)

@ohos.pasteboard (Pasteboard)

Calendar Kit @ohos.calendarManager (Calendar Manager)
Call Service Kit voipCall (In-App Call Management)
Camera Kit

@ohos.multimedia.camera (Camera Management)

@ohos.multimedia.cameraPicker (Camera Picker)

Connectivity Kit

@ohos.connectedTag (Active Tags)

@ohos.nfc.cardEmulation (Standard NFC Card Emulation)

@ohos.nfc.controller (Standard NFC)

@ohos.nfc.tag (Standard NFC Tags)

nfctech (Standard NFC Technologies)

tagSession (Standard NFC Tag Session)

Contacts Kit @ohos.contact (Contacts)
Core File Kit @ohos.file.picker (Picker)
Form Kit

@ohos.app.form.formInfo (formInfo)

@ohos.application.formError (formError)

Map Kit sceneMap (Scenario-specific Control)
MDM Kit

@ohos.enterprise.adminManager (Administrator Permission Management)

@ohos.enterprise.deviceInfo (Device Information Management)

Media Kit @ohos.multimedia.media (Media Kit)
Media Library Kit

@ohos.file.sendablePhotoAccessHelper (Album Management Based on a Sendable Object)

@ohos.file.AlbumPickerComponent (AlbumPickerComponent)

@ohos.file.PhotoPickerComponent (PhotoPickerComponent)

@ohos.file.RecentPhotoComponent (RecentPhotoComponent)

@ohos.multimedia.movingphotoview (MovingPhotoView)

@ohos.file.photoAccessHelper (Album Management)

Notification Kit

@ohos.notification (Notification)

@ohos.notificationManager (NotificationManager)

Payment Kit paymentService (HarmonyOS Payment Service)
Performance Analysis Kit @ohos.hidebug (HiDebug)
Scan Kit

customScan (Barcode Scanning by Custom UI)

detectBarcode (Recognizing Barcodes in an Image)

generateBarcode (Barcode Image Generation)

scanBarcode (Scanning Barcodes Using the Default UI)

scanCore (Common Barcode Scanning Information)

Sensor Service Kit @ohos.vibrator (Vibrator)
Service Collaboration Kit

devicePicker (Device Selection Controller)

CollaborationDevicePicker (Hopping Control)

Share Kit

systemShare (System Share)

harmonyShare (Huawei Share)

Telephony Kit

@ohos.telephony.call (Call)

@ohos.telephony.data (Cellular Data)

@ohos.telephony.observer (Observer)

@ohos.telephony.radio (Network Search)

@ohos.telephony.sim (SIM Management)

@ohos.telephony.sms (SMS)

User Authentication Kit @ohos.userIAM.userAuth (User Authentication)
Vision Kit

CardRecognition (Card Recognition Control)

DocumentScanner (Document Scanning Control)