管理中心

您当前正在浏览HarmonyOS最新文档,覆盖已发布的所有API版本,可在API参考中筛选您使用的API版本。详细的版本配套关系请参考版本说明。

指南与API参考API参考应用框架Ability Kit(程序框架服务)ArkTS API通用能力的接口(推荐)@ohos.bundle.pluginBundleManager (pluginBundleManager模块)

@ohos.bundle.pluginBundleManager (pluginBundleManager模块)

PC/2in126.0.0+

本模块提供应用对自分发插件的管理能力,包括安装、卸载本地插件。

起始版本: 26.0.0

导入模块

收起
自动换行
深色代码主题
复制
  1. import { pluginBundleManager } from '@kit.AbilityKit';

pluginBundleManager.installLocalPlugin

PC/2in126.0.0+

installLocalPlugin(pluginFilePaths: Array<string>): Promise<void>

为当前应用安装自分发插件(即应用通过自有渠道分发、自主管理的插件)。使用Promise异步回调。

起始版本: 26.0.0

需要权限: ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN

系统能力: SystemCapability.BundleManager.BundleFramework.Core

模型约束: 此接口仅可在Stage模型下使用。

参数:

展开
参数名 类型 必填 说明
pluginFilePaths Array<string> 是 插件文件路径数组,表示要安装的插件文件的路径列表。

返回值:

展开
类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码和包管理子系统通用错误码。

展开
错误码ID 错误信息
201 Calling interface without permission 'ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN'.
17700010 Failed to install the plugin because the plugin fails to be parsed.
17700011 Failed to install the plugin because the plugin signature fails to be verified.
17700012 Failed to install the plugin because the HSP path is invalid or the HSP is too large.
17700015 Failed to install the plugin because they have different configuration information.
17700016 Failed to install the plugin because of insufficient system disk space.
17700017 Failed to install the plugin since the version of the plugin to install is too early.
17700048 Failed to install the plugin because the code signature verification failed.
17700052 Failed to install the plugin because debug bundle cannot be installed under non-developer mode.
17700073 Failed to install the plugin because a plugin with the same bundle name but different signature information exists on the device.
17700087 Failed to install the plugin because the current device does not support plugins.
17700091 Failed to install the plugin because the plugin name is the same as the host bundle name.

示例:

收起
自动换行
深色代码主题
复制
  1. import { pluginBundleManager } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. // 请替换为实际的插件文件路径
  4. let pluginPaths: Array<string> = ["/data/storage/el2/base/haps/entry/plugin.hsp"];
  5. pluginBundleManager.installLocalPlugin(pluginPaths)
  6. .then(() => {
  7. console.info('installLocalPlugin success');
  8. }).catch((err: BusinessError) => {
  9. console.error(`installLocalPlugin errData is errCode:${err.code} message:${err.message}`);
  10. });

pluginBundleManager.uninstallLocalPlugin

PC/2in126.0.0+

uninstallLocalPlugin(pluginBundleName: string): Promise<void>

卸载当前应用已通过自分发方式安装的指定插件。使用Promise异步回调。

起始版本: 26.0.0

需要权限: ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN

系统能力: SystemCapability.BundleManager.BundleFramework.Core

模型约束: 此接口仅可在Stage模型下使用。

参数:

展开
参数名 类型 必填 说明
pluginBundleName string 是 插件的Bundle名称,表示要卸载的插件的应用包名。

返回值:

展开
类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码和包管理子系统通用错误码。

展开
错误码ID 错误信息
201 Calling interface without permission 'ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN'.
17700092 Failed to uninstall the plugin because the specified plugin is not found.

示例:

收起
自动换行
深色代码主题
复制
  1. import { pluginBundleManager } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. // 请替换为实际的插件Bundle名称
  4. let pluginBundleName = "com.example.plugin";
  5. pluginBundleManager.uninstallLocalPlugin(pluginBundleName)
  6. .then(() => {
  7. console.info('uninstallLocalPlugin success');
  8. }).catch((err: BusinessError) => {
  9. console.error(`uninstallLocalPlugin errData is errCode:${err.code} message:${err.message}`);
  10. });

pluginBundleManager.getAllLocalPluginInfoForSelf

PC/2in126.0.0+

getAllLocalPluginInfoForSelf(): Promise<Array<PluginBundleInfo>>

查询当前应用中所有自分发插件的信息。使用Promise异步回调。

起始版本: 26.0.0

需要权限: ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN

系统能力: SystemCapability.BundleManager.BundleFramework.Core

模型约束: 此接口仅可在Stage模型下使用。

返回值:

展开
类型 说明
Promise<Array<PluginBundleInfo>> Promise对象,返回当前应用已安装的所有本地插件信息列表。

错误码:

以下错误码的详细介绍请参见通用错误码。

展开
错误码ID 错误信息
201 Calling interface without permission 'ohos.permission.kernel.SUPPORT_LOCAL_PLUGIN'.

示例:

收起
自动换行
深色代码主题
复制
  1. import { pluginBundleManager } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. pluginBundleManager.getAllLocalPluginInfoForSelf().then((data): void => {
  4. console.info('getAllLocalPluginInfoForSelf plugin data is' + JSON.stringify(data));
  5. }).catch((err: Error): void => {
  6. const businessErr = err as BusinessError;
  7. console.error(`getAllLocalPluginInfoForSelf errData is errCode:${businessErr.code} message:${businessErr.message}`);
  8. });

PluginBundleInfo

PC/2in126.0.0+

type PluginBundleInfo = _PluginBundleInfo

插件信息。

起始版本: 26.0.0

系统能力: SystemCapability.BundleManager.BundleFramework.Core

模型约束: 此接口仅可在Stage模型下使用。

展开
类型 说明
_PluginBundleInfo 插件信息。

PluginModuleInfo

PC/2in126.0.0+

type PluginModuleInfo = _PluginModuleInfo

插件的模块信息。

起始版本: 26.0.0

系统能力: SystemCapability.BundleManager.BundleFramework.Core

模型约束: 此接口仅可在Stage模型下使用。

展开
类型 说明
_PluginModuleInfo 插件的模块信息。