openharmony 鸿蒙 js-apis-distributedBundleManager-sys

2025-06-12 浏览 (1)

@ohos.bundle.distributedBundleManager (distributedBundleManager) (System API)

The distributedBundle module provides APIs for managing distributed bundles.

NOTE

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

The APIs provided by this module are system APIs.

Modules to Import

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

System Capabilities

SystemCapability.BundleManager.DistributedBundleFramework

Required Permissions

PermissionAPLDescription
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basicPermission to obtain basic information and other sensitive information about a bundle.

For details about the APL, see Basic Concepts in the Permission Mechanism.

distributedBundle.getRemoteAbilityInfo

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

Obtains information about the remote ability that matches the given element name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNameElementNameYesTarget element name.
callbackAsyncCallback<RemoteAbilityInfo>YesCallback used to return the result. If the operation is successful, err is null and data is the RemoteAbilityInfo object obtained. Otherwise, err is an error object and data is undefined.

Error codes

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

IDError Message
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.

Example

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>

Obtains information about the remote ability that matches the given element name. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNameElementNameYesTarget element name.

Return value

TypeDescription
Promise<RemoteAbilityInfo>Promise used to return the result. If the operation is successful, the RemoteAbilityInfo object is returned. Otherwise, an error object is returned.

Error codes

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

IDError Message
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.

Example

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

Obtains information about the remote abilities that match the given element names. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNamesArray<ElementName>YesElementName array, whose maximum length is 10.
callbackAsyncCallback<Array<RemoteAbilityInfo>>YesCallback used to return the result. If the operation is successful, err is null and data is the array of RemoteAbilityInfo objects obtained. Otherwise, err is an error object and data is undefined.

Error codes

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

IDError Message
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.

Example

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>>

Obtains information about the remote abilities that match the given element names. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNamesArray<ElementName>YesElementName array, whose maximum length is 10.

Return value

TypeDescription
Promise<Array<RemoteAbilityInfo>>Promise used to return the result. If the operation is successful, an array of RemoteAbilityInfo objects is returned. Otherwise, an error object is returned.

Error codes

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

IDError Message
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.

Example

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

Obtains information about the remote ability that matches the given element name and locale. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNameElementNameYesTarget element name.
localestringYesTarget locale.
callbackAsyncCallback<RemoteAbilityInfo>YesCallback used to return the result. If the operation is successful, err is null and data is the RemoteAbilityInfo object obtained. Otherwise, err is an error object and data is undefined.

Error codes

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

IDError Message
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.

Example

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>

Obtains information about the remote ability that matches the given element name and locale. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNameElementNameYesTarget element name.
localestringYesTarget locale.

Return value

TypeDescription
Promise<RemoteAbilityInfo>Promise used to return the result. If the operation is successful, the RemoteAbilityInfo object is returned. Otherwise, an error object is returned.

Error codes

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

IDError Message
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.

Example

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

Obtains information about the remote abilities that match the given element names and locale. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNamesArray<ElementName>YesElementName array, whose maximum length is 10.
localestringYesTarget locale.
callbackAsyncCallback<Array<RemoteAbilityInfo>>YesCallback used to return the result. If the operation is successful, err is null and data is the array of RemoteAbilityInfo objects obtained. Otherwise, err is an error object and data is undefined.

Error codes

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

IDError Message
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.

Example

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>>

Obtains information about the remote abilities that match the given element names and locale. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.DistributedBundleFramework

Parameters

NameTypeMandatoryDescription
elementNamesArray<ElementName>YesElementName array, whose maximum length is 10.
localestringYesTarget locale.

Return value

TypeDescription
Promise<Array<RemoteAbilityInfo>>Promise used to return the result. If the operation is successful, an array of RemoteAbilityInfo objects is returned. Otherwise, an error object is returned.

Error codes

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

IDError Message
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.

Example

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 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

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