# @ohos.bundle.distributedBundleManager (distributedBundleManager模å—)(系统接å£) 本模å—æ供分布å¼åº”用的管ç†èƒ½åŠ›ã€‚ > **说明:** > > 本模å—首批接å£ä»ŽAPI version 9 开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 > > 本模å—为系统接å£ã€‚ ## å¯¼å…¥æ¨¡å— ``` ts import distributedBundle from '@ohos.bundle.distributedBundleManager'; ``` ## 系统能力 SystemCapability.BundleManager.DistributedBundleFramework ## æƒé™åˆ—表 | æƒé™ | æƒé™ç‰çº§ | 说明 | | ------------------------------------------ | ------------ | ------------------ | | ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | å…许查询应用的基本信æ¯å’Œå…¶ä»–æ•æ„Ÿä¿¡æ¯ã€‚ | æƒé™ç‰çº§å‚考[æƒé™APLç‰çº§è¯´æ˜Ž](../../security/AccessToken/app-permission-mgmt-overview.md#æƒé™æœºåˆ¶ä¸çš„基本概念)。 ## distributedBundle.getRemoteAbilityInfo getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback\<RemoteAbilityInfo>): void 以异æ¥æ–¹æ³•èŽ·å–ç”±elementName指定的远程设备上的应用的AbilityInfoä¿¡æ¯ã€‚使用callback异æ¥å›žè°ƒã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **需è¦æƒé™ï¼š** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED **系统能力:** SystemCapability.BundleManager.DistributedBundleFramework **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是 | ElementNameä¿¡æ¯ã€‚ | | callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)> | 是 | 回调函数,调用æˆåŠŸè¿”回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|--------------------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----------- | -------------------------------------------- | ---- | ----------------------- | | elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是 | ElementNameä¿¡æ¯ã€‚ | **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | --------------------------------- | | Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)> | Promise对象,调用æˆåŠŸè¿”回RemoteAbilityInfo对象;调用失败返回错误对象。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | ElementNameä¿¡æ¯,最大数组长度为10。 | | callback | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)>> | 是 | 回调函数,调用æˆåŠŸè¿”回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------------ | --------------------------------------------------- | ---- | ----------------------- | | elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | ElementNameä¿¡æ¯ï¼Œæœ€å¤§æ•°ç»„长度为10。 | **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | --------------------------------- | | Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)>> | Promise对象,调用æˆåŠŸè¿”回RemoteAbilityInfo对象;调用失败返回错误对象。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | | elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是 | ElementNameä¿¡æ¯ã€‚ | | locale | string |是 | è¯è¨€åœ°åŒºã€‚ | | callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)> | 是 | 回调函数,调用æˆåŠŸè¿”回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----------- | -------------------------------------------- | ---- | ----------------------- | | elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是 | ElementNameä¿¡æ¯ã€‚ | | locale | string |是 | è¯è¨€åœ°åŒºã€‚ | **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | --------------------------------- | | Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)> | Promise对象,调用æˆåŠŸè¿”回RemoteAbilityInfo对象;调用失败返回错误对象。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- | | elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | ElementNameä¿¡æ¯,最大数组长度为10。 | | locale | string |是 | è¯è¨€åœ°åŒºã€‚ | | callback | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)>> | 是 | 回调函数,调用æˆåŠŸè¿”回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |---------------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`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 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------------ | --------------------------------------------------- | ---- | ----------------------- | | elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | ElementNameä¿¡æ¯,最大数组长度为10。 | | locale | string |是 | è¯è¨€åœ°åŒºã€‚ | **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | --------------------------------- | | Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo-sys.md)>> | Promise对象,调用æˆåŠŸè¿”回RemoteAbilityInfo对象;调用失败返回错误对象。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[通用错误ç ](../errorcode-universal.md)å’Œ[ohos.bundle错误ç ](errorcode-bundle.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | |----------|-------------------------| | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 801 | Capability not supported. | | 17700001 | The specified bundle name is not found. | | 17700003 | The specified ability name is not found. | | 17700007 | The specified device ID is not found. | | 17700027 | The distributed service is not running. | **示例:** ```ts 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.log(`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.log(`Operation failed: error code is ${code} and error message is ${message}`); } ```