openharmony 鸿蒙 js-apis-distributedBundleManager-sys

2025-06-12 浏览 (1)

@ohos.bundle.distributedBundleManager (distributedBundleManager模块)(系统接口)

本模块提供分布式应用的管理能力。

说明:

本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块为系统接口。

导入模块

import distributedBundle from '@ohos.bundle.distributedBundleManager';

系统能力

SystemCapability.BundleManager.DistributedBundleFramework

权限列表

权限权限等级说明
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basic允许查询应用的基本信息和其他敏感信息。

权限等级参考权限APL等级说明

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback<RemoteAbilityInfo>): void

获取由elementName指定的远程设备上的应用的AbilityInfo信息。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNameElementNameElementName信息。
callbackAsyncCallback<RemoteAbilityInfo>回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'EntryAbility'
        }, (err: BusinessError, data: distributedBundle.RemoteAbilityInfo) => {
            if (err) {
                console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
            } else {
                console.info('Operation succeed:' + JSON.stringify(data));
            }
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementName: ElementName): Promise<RemoteAbilityInfo>

获取由elementName指定的远程设备上的应用的AbilityInfo信息。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNameElementNameElementName信息。

返回值:

类型说明
Promise<RemoteAbilityInfo>Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'EntryAbility'
        }).then((data: distributedBundle.RemoteAbilityInfo) => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch((err: BusinessError) => {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementNames: Array<ElementName>, callback: AsyncCallback<Array<RemoteAbilityInfo>>): void

获取由elementName指定的远程设备上的应用的AbilityInfo数组信息。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNamesArray<ElementName>ElementName信息,最大数组长度为10。
callbackAsyncCallback<Array<RemoteAbilityInfo>>回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application1',
                abilityName: 'EntryAbility1'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'EntryAbility'
            }
        ], (err: BusinessError, data: distributedBundle.RemoteAbilityInfo[]) => {
          if (err) {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementNames: Array<ElementName>): Promise<Array<RemoteAbilityInfo>>

获取由elementName指定的远程设备上的应用的AbilityInfo数组信息。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNamesArray<ElementName>ElementName信息,最大数组长度为10。

返回值:

类型说明
Promise<Array<RemoteAbilityInfo>>Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application',
                abilityName: 'EntryAbility'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'EntryAbility'
            }
        ]).then((data: distributedBundle.RemoteAbilityInfo[]) => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch((err: BusinessError) => {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementName: ElementName, locale: string, callback: AsyncCallback<RemoteAbilityInfo>): void

获取由elementName和locale指定的远程设备上的应用的AbilityInfo信息。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNameElementNameElementName信息。
localestring语言地区。
callbackAsyncCallback<RemoteAbilityInfo>回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'EntryAbility'
        }, 'zh-Hans-CN', (err: BusinessError, data: distributedBundle.RemoteAbilityInfo) => {
          if (err) {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementName: ElementName, locale: string): Promise<RemoteAbilityInfo>

获取由elementName和locale指定的远程设备上的应用的AbilityInfo信息。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNameElementNameElementName信息。
localestring语言地区。

返回值:

类型说明
Promise<RemoteAbilityInfo>Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'EntryAbility'
        }, 'zh-Hans-CN').then((data: distributedBundle.RemoteAbilityInfo) => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch((err: BusinessError) => {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementNames: Array<ElementName>, locale: string, callback: AsyncCallback<Array<RemoteAbilityInfo>>): void

获取由elementName和locale指定的远程设备上的应用的AbilityInfo数组信息。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNamesArray<ElementName>ElementName信息,最大数组长度为10。
localestring语言地区。
callbackAsyncCallback<Array<RemoteAbilityInfo>>回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application1',
                abilityName: 'EntryAbility1'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'EntryAbility'
            }
        ], 'zh-Hans-CN', (err: BusinessError, data: distributedBundle.RemoteAbilityInfo[]) => {
          if (err) {
           console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

distributedBundle.getRemoteAbilityInfo

getRemoteAbilityInfo(elementNames: Array<ElementName>, locale: string): Promise<Array<RemoteAbilityInfo>>

获取由elementName和locale指定的远程设备上的应用的AbilityInfo数组信息。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

参数名类型必填说明
elementNamesArray<ElementName>ElementName信息,最大数组长度为10。
localestring语言地区。

返回值:

类型说明
Promise<Array<RemoteAbilityInfo>>Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。

错误码:

以下错误码的详细介绍请参见通用错误码ohos.bundle错误码

错误码ID错误信息
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700003The specified ability name is not found.
17700007The specified device ID is not found.
17700027The distributed service is not running.

示例:

import distributedBundle from '@ohos.bundle.distributedBundleManager';
import { BusinessError } from '@ohos.base';

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application',
                abilityName: 'EntryAbility'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'EntryAbility'
            }
        ], 'zh-Hans-CN').then((data: distributedBundle.RemoteAbilityInfo[]) => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch((err: BusinessError) => {
            console.error(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
        });
} catch (err) {
    let code = (err as BusinessError).code;
    let message = (err as BusinessError).message;
    console.error(`Operation failed: error code is ${code}  and error message is ${message}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit(程序框架服务)

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_base_common.h

harmony 鸿蒙ability_runtime_common.h

harmony 鸿蒙application_context.h

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