harmony(鸿蒙)@ohos.bundle.distributedBundle (distributedBundle模块)

2022-10-28 浏览 (814)

@ohos.bundle.distributedBundle (distributedBundle模块)

本模块提供分布式包的管理能力

说明:

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

本模块接口为系统接口。

导入模块

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

系统能力

SystemCapability.BundleManager.DistributedBundleFramework

权限列表

权限权限等级说明
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basic可查询所有应用信息。

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

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对象;否则为错误对象。

错误码:

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

错误码ID错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'MainAbility'
        }, (err, data) => {
          if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'MainAbility'
        }).then(data => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch(err => {
            console.error('Operation failed:' + JSON.stringify(err));
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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数组对象;否则返回错误对象。

错误码:

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

错误码ID错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application1',
                abilityName: 'MainAbility1'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'MainAbility'
            }
        ], (err, data) => {
          if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

distributedBundle.getRemoteAbilityInfo

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

以异步方法根据给定的ElementName和locale获取有关远程设备AbilityInfo数组信息。使用Promise异步回调。

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

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.DistributedBundleFramework

参数:

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

返回值:

类型说明
Promise<Array<RemoteAbilityInfo>>Promise对象,返回RemoteAbilityInfo数组对象。

错误码:

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

错误码ID错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application',
                abilityName: 'MainAbility'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'MainAbility'
            }
        ]).then(data => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch(err => {
            console.error('Operation failed:' + JSON.stringify(err));
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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对象;否则为错误对象。

错误码:

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

错误码ID错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'MainAbility'
        }, 'zh-Hans-CN', (err, data) => {
          if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        {
            deviceId: '1',
            bundleName: 'com.example.application',
            abilityName: 'MainAbility'
        }, 'zh-Hans-CN').then(data => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch(err => {
            console.error('Operation failed:' + JSON.stringify(err));
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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数组对象;否则返回错误对象。

错误码:

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

错误码ID错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application1',
                abilityName: 'MainAbility1'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'MainAbility'
            }
        ], 'zh-Hans-CN', (err, data) => {
          if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
          } else {
            console.info('Operation succeed:' + JSON.stringify(data));
          }
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

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错误信息
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.

示例:

try {
    distributedBundle.getRemoteAbilityInfo(
        [
            {
                deviceId: '1',
                bundleName: 'com.example.application',
                abilityName: 'MainAbility'
            },
            {
                deviceId: '1',
                bundleName: 'com.example.application2',
                abilityName: 'MainAbility'
            }
        ], 'zh-Hans-CN').then(data => {
            console.info('Operation succeed:' + JSON.stringify(data));
        }).catch(err => {
            console.error('Operation failed:' + JSON.stringify(err));
        });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)接口

harmony(鸿蒙)开发说明

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony(鸿蒙)@ohos.distributedBundle (分布式包管理)

harmony(鸿蒙)@ohos.bundle (Bundle模块)

harmony(鸿蒙)@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony(鸿蒙)@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)

harmony(鸿蒙)@ohos.ability.ability (Ability)

harmony(鸿蒙)AbilityContext

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