本模块提供分布式应用的管理能力。
说明:
本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口为系统接口。
导入模块
import distributedBundle from '@ohos.bundle.distributedBundleManager';
系统能力
SystemCapability.BundleManager.DistributedBundleFramework
权限列表
权限 | 权限等级 | 说明 |
---|---|---|
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 允许查询应用的基本信息和其他敏感信息。 |
权限等级参考权限等级说明。
distributedBundle.getRemoteAbilityInfo
getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback<RemoteAbilityInfo>): void
以异步方法获取由elementName指定的远程设备上的应用的AbilityInfo信息。使用callback异步回调。
系统接口: 此接口为系统接口。
需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
系统能力: SystemCapability.BundleManager.DistributedBundleFramework
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
elementName | ElementName | 是 | ElementName信息。 |
callback | AsyncCallback<RemoteAbilityInfo> | 是 | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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 | 是 | ElementName信息。 |
返回值:
类型 | 说明 |
---|---|
Promise<RemoteAbilityInfo> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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> | 是 | ElementName信息,最大数组长度为10。 |
callback | AsyncCallback<Array<RemoteAbilityInfo>> | 是 | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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> | 是 | ElementName信息,最大数组长度为10。 |
返回值:
类型 | 说明 |
---|---|
Promise<Array<RemoteAbilityInfo>> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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 | 是 | ElementName信息。 |
locale | string | 是 | 语言地区。 |
callback | AsyncCallback<RemoteAbilityInfo> | 是 | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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 | 是 | ElementName信息。 |
locale | string | 是 | 语言地区。 |
返回值:
类型 | 说明 |
---|---|
Promise<RemoteAbilityInfo> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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> | 是 | ElementName信息,最大数组长度为10。 |
locale | string | 是 | 语言地区。 |
callback | AsyncCallback<Array<RemoteAbilityInfo>> | 是 | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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> | 是 | ElementName信息,最大数组长度为10。 |
locale | string | 是 | 语言地区。 |
返回值:
类型 | 说明 |
---|---|
Promise<Array<RemoteAbilityInfo>> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
错误码:
以下错误码的详细介绍请参见ohos.bundle错误码。
错误码ID | 错误信息 |
---|---|
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. |
示例:
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}`);
}
最后
有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。
这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。
希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!
获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
鸿蒙(HarmonyOS NEXT)最新学习路线
-
HarmonOS基础技能
- HarmonOS就业必备技能
- HarmonOS多媒体技术
- 鸿蒙NaPi组件进阶
- HarmonOS高级技能
- 初识HarmonOS内核
- 实战就业级设备开发
有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。
获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
《鸿蒙 (OpenHarmony)开发入门教学视频》
《鸿蒙生态应用开发V2.0白皮书》
《鸿蒙 (OpenHarmony)开发基础到实战手册》
OpenHarmony北向、南向开发环境搭建
《鸿蒙开发基础》
- ArkTS语言
- 安装DevEco Studio
- 运用你的第一个ArkTS应用
- ArkUI声明式UI开发
- .……
《鸿蒙开发进阶》
- Stage模型入门
- 网络管理
- 数据管理
- 电话服务
- 分布式应用开发
- 通知与窗口管理
- 多媒体技术
- 安全技能
- 任务管理
- WebGL
- 国际化开发
- 应用测试
- DFX面向未来设计
- 鸿蒙系统移植和裁剪定制
- ……
《鸿蒙进阶实战》
- ArkTS实践
- UIAbility应用
- 网络案例
- ……
获取以上完整鸿蒙HarmonyOS学习资料,请点击→纯血版全套鸿蒙HarmonyOS学习资料
总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑战,也是一个机会。只有积极应对变化,不断学习和提升自己,他们才能在这个变革的时代中立于不败之地。