openharmony 鸿蒙 js-apis-app-ability-verticalpanelmanager-sys

2026-08-25 浏览 (1)

@ohos.app.ability.verticalPanelManager (Vertical Panel Management) (System API)

The module provides capabilities for vertical panel management. Currently, it only supports launching the vertical panel for application selection.

NOTE

The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module can be used only in the stage model.

The APIs provided by this module are system APIs.

Modules to Import

import { verticalPanelManager } from '@kit.AbilityKit';

verticalPanelManager.startVerticalPanel

startVerticalPanel(context: common.UIAbilityContext, wantParam: Record<string, Object>, panelConfig: PanelConfig, panelStartCallback: PanelStartCallback): Promise<void>

Launches a vertical panel for selecting a target application to start. This API must be called when the caller (source application) is running in the foreground. This API uses a promise to return the result.

As shown in the figure below, the source application (sourceAppInfo), which is currently displayed on the screen, calls startVerticalPanel via an intermediary application (the launcher application) to launch the vertical panel. After the user manually selects the target application, the source and target applications automatically enter a split-screen layout.

app-startverticalpanel-procedure

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
contextcommon.UIAbilityContextYesContext of the caller.
wantParamRecord<string, Object>YesParameters passed for starting the UIExtensionAbility.
panelConfigPanelConfigYesConfiguration parameters of the vertical panel.
panelStartCallbackPanelStartCallbackYesCallback for launching the vertical panel.

Return value

NameDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
202The application is not a system application.
16000050Failed to connect to the system service or system server handle failed.
16000135The main window of this ability of this context does not exits.

Example

import { common, verticalPanelManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  @State message: string = 'StartVerticalPanel';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('StartVerticalPanel')
        .fontSize($r('app.float.page_text_font_size'))
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          this.callStartVerticalPanelNapi();
        })
    }
    .height('100%')
    .width('100%');
  }

  // Construct parameters and call startVerticalPanel to launch the vertical panel.
  callStartVerticalPanelNapi() {
    // Param[0] UIAbilityContext
    const context = this.getUIContext().getHostContext() as common.UIAbilityContext;

    // Param[1] wantParam: Record<string, Object>
    let wantParam: Record<string, Object> = {
      'sceneType': 3,
      'destinationName': 'Lianqiu Lake R&D Center'
    };

    // Param[2] PanelConfig
    let sourceAppInfo: Record<string, string> = {};
    sourceAppInfo[verticalPanelManager.SOURCE_APP_BUNDLE_NAME] = 'com.huawei.hmos.browser';
    sourceAppInfo[verticalPanelManager.SOURCE_APP_MODULE_NAME] = 'entry';
    sourceAppInfo[verticalPanelManager.SOURCE_APP_ABILITY_NAME] = 'MainAbility';
    sourceAppInfo[verticalPanelManager.SOURCE_APP_WINDOW_ID] = '0';
    sourceAppInfo[verticalPanelManager.SOURCE_APP_SCREEN_MODE] = '1';

    let panelConfig: verticalPanelManager.PanelConfig = {
      type: verticalPanelManager.VerticalType.NAVIGATION,
      sourceAppInfo: sourceAppInfo
    };

    // Param[3] PanelStartCallback
    let callback: verticalPanelManager.PanelStartCallback = {
      onError: (code: number, name: string, message: string): void => {
        console.info(`startVerticalPanel onError code ${code} name: ${name} message: ${message}`);
      },
      onResult: (result: common.AbilityResult): void => {
        console.info(`startVerticalPanel onResult result ${JSON.stringify(result)}`);
      },
    };

    try {
      console.info(`call startVerticalPanel`);
      verticalPanelManager.startVerticalPanel(context, wantParam, panelConfig, callback)
        .then(() => {
          console.info(`call startVerticalPanel end`);
        })
        .catch((error: BusinessError) => {
          console.error(`call startVerticalPanel promise catch error : ${error}`);
        });
    } catch (error) {
      console.error(`call startVerticalPanel catch error : ${error}`);
    }
  }
}

PanelConfig

Describes the configuration parameters of the vertical panel.

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

NameTypeRead-OnlyOptionalDescription
typeVerticalTypeNoNoType of the vertical panel.
sourceAppInfoRecord<string, string>NoNoInformation about the source application, including its bundle name, module name, ability name, window ID, and screen mode. When a target application is selected and started from the vertical panel, it automatically forms a split-screen layout with the source application.

VerticalType

Enumerates the types of vertical panels that can be launched.

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

NameValueDescription
NAVIGATION'navigation'Navigation application. For details about wantParam, see the extended panel parameter description in Using startAbilityByType to Start a Navigation Application.

PanelStartCallback

Describes the callback for launching the vertical panel.

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
onErrorOnErrorFnNoNoCallback invoked when launching the vertical panel fails.
onResultOnResultFnNoYesCallback invoked when the launched vertical panel is terminated.

OnErrorFn

type OnErrorFn = (code: number, name: string, message: string) => void

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
codenumberYesResult code returned when the UIExtensionAbility fails to start.
namestringYesName returned when the UIExtensionAbility fails to start.
messagestringYesError information returned when the UIExtensionAbility fails to start.

Example

let callback: verticalPanelManager.PanelStartCallback = {
  onError: (code: number, name: string, message: string): void => {
    console.info(`startVerticalPanel onError code ${code} name: ${name} message: ${message}`);
  },
  onResult: (result: common.AbilityResult):void => {
    console.info(`startVerticalPanel onResult result ${JSON.stringify(result)}`);
  },
}

OnResultFn

type OnResultFn = (parameter: AbilityResult) => void

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
parameterAbilityResultYesParameters returned when the UIExtensionAbility calls terminateSelfWithResult.

Example

let callback: verticalPanelManager.PanelStartCallback = {
  onError: (code: number, name: string, message: string): void => {
    console.info(`startVerticalPanel onError code ${code} name: ${name} message: ${message}`);
  },
  onResult: (result: common.AbilityResult):void => {
    console.info(`startVerticalPanel onResult result ${JSON.stringify(result)}`);
  },
}

Constants

System capability: SystemCapability.Ability.AppExtension.VerticalPanel

System API: This is a system API.

NameTypeValueDescription
SOURCE_APP_BUNDLE_NAMEstring'bundleName'Constant string bundleName, which indicates the bundle name of the source application. It can be used as a key in sourceAppInfo.
SOURCE_APP_MODULE_NAMEstring'moduleName'Constant string moduleName, which indicates the module name of the source application. It can be used as a key in sourceAppInfo.
SOURCE_APP_ABILITY_NAMEstring'abilityName'Constant string abilityName, which indicates the ability name of the source application. It can be used as a key in sourceAppInfo.
SOURCE_APP_WINDOW_IDstring'windowId'Constant string windowId, which indicates the window ID of the source application. It can be used as a key in sourceAppInfo.
SOURCE_APP_SCREEN_MODEstring'screenMode'Constant string screenMode, which indicates the screen mode of the source application. Currently, the vertical panel can be launched successfully only when the value is 1. It can be used as a key in sourceAppInfo.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-app-ability-appServiceExtensionAbility

openharmony 鸿蒙 js-apis-inner-wantAgent-triggerInfo-sys

openharmony 鸿蒙 js-apis-inner-wantAgent-wantAgentInfo-sys

openharmony 鸿蒙 js-apis-appControl-sys

openharmony 鸿蒙 js-apis-app-ability-environmentCallback

openharmony 鸿蒙 js-apis-inner-application-missionInfo-sys

openharmony 鸿蒙 js-apis-bundleManager-sharedBundleInfo-sys

openharmony 鸿蒙 js-apis-inner-application-continueMissionInfo-sys

openharmony 鸿蒙 js-apis-inner-application-appServiceExtensionContext

openharmony 鸿蒙 js-apis-bundleManager-businessAbilityInfo-sys

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/lP2nWbE8