• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.distributedBundleManager (distributedBundleManager模块)
2
3本模块提供分布式应用的管理能力。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9本模块接口为系统接口。
10
11## 导入模块
12
13``` ts
14import distributedBundle from '@ohos.bundle.distributedBundleManager';
15```
16
17## 系统能力
18
19SystemCapability.BundleManager.DistributedBundleFramework
20
21## 权限列表
22
23| 权限                                       | 权限等级     | 说明               |
24| ------------------------------------------ | ------------ | ------------------ |
25| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 允许查询应用的基本信息和其他敏感信息。 |
26
27权限等级参考[权限等级说明](../../security/accesstoken-overview.md#权限等级说明)。
28
29## distributedBundle.getRemoteAbilityInfo
30
31getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback\<RemoteAbilityInfo>): void
32
33以异步方法获取由elementName指定的远程设备上的应用的AbilityInfo信息。使用callback异步回调。
34
35**系统接口:** 此接口为系统接口。
36
37**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
38
39**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
40
41**参数:**
42
43| 参数名      | 类型                                                         | 必填 | 说明                                                         |
44| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
45| elementName | [ElementName](js-apis-bundleManager-elementName.md)          | 是   | ElementName信息。                                            |
46| callback    | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | 是   | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 |
47
48**错误码:**
49
50以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
51
52| 错误码ID |    错误信息                   |
53|----------|--------------------------------------|
54| 17700001 | The specified bundle name is not found. |
55| 17700003 | The specified ability name is not found. |
56| 17700007 | The specified device ID is not found. |
57| 17700027 | The distributed service is not running. |
58
59**示例:**
60
61```ts
62import distributedBundle from '@ohos.bundle.distributedBundleManager';
63import { BusinessError } from '@ohos.base';
64
65try {
66    distributedBundle.getRemoteAbilityInfo(
67        {
68            deviceId: '1',
69            bundleName: 'com.example.application',
70            abilityName: 'EntryAbility'
71        }, (err: BusinessError, data: distributedBundle.RemoteAbilityInfo) => {
72          if (err) {
73            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
74          } else {
75            console.info('Operation succeed:' + JSON.stringify(data));
76          }
77        });
78} catch (err) {
79    let code = (err as BusinessError).code;
80    let message = (err as BusinessError).message;
81    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
82}
83```
84
85## distributedBundle.getRemoteAbilityInfo
86
87getRemoteAbilityInfo(elementName: ElementName): Promise\<RemoteAbilityInfo>
88
89以异步方法获取由elementName指定的远程设备上的应用的AbilityInfo信息。使用Promise异步回调。
90
91**系统接口:** 此接口为系统接口。
92
93**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
94
95**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
96
97**参数:**
98
99| 参数名       | 类型                                         | 必填 | 说明                    |
100| ----------- | -------------------------------------------- | ---- | ----------------------- |
101| elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是   | ElementName信息。 |
102
103**返回值:**
104
105| 类型                                                         | 说明                              |
106| ------------------------------------------------------------ | --------------------------------- |
107| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
108
109**错误码:**
110
111以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
112
113| 错误码ID |    错误信息                   |
114|----------|-------------------------|
115| 17700001 | The specified bundle name is not found. |
116| 17700003 | The specified ability name is not found. |
117| 17700007 | The specified device ID is not found. |
118| 17700027 | The distributed service is not running. |
119
120**示例:**
121
122```ts
123import distributedBundle from '@ohos.bundle.distributedBundleManager';
124import { BusinessError } from '@ohos.base';
125
126try {
127    distributedBundle.getRemoteAbilityInfo(
128        {
129            deviceId: '1',
130            bundleName: 'com.example.application',
131            abilityName: 'EntryAbility'
132        }).then((data: distributedBundle.RemoteAbilityInfo) => {
133            console.info('Operation succeed:' + JSON.stringify(data));
134        }).catch((err: BusinessError) => {
135            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
136        });
137} catch (err) {
138    let code = (err as BusinessError).code;
139    let message = (err as BusinessError).message;
140    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
141}
142```
143
144## distributedBundle.getRemoteAbilityInfo
145
146getRemoteAbilityInfo(elementNames: Array\<ElementName>, callback: AsyncCallback\<Array\<RemoteAbilityInfo>>): void
147
148以异步方法获取由elementName指定的远程设备上的应用的AbilityInfo数组信息。使用callback异步回调。
149
150**系统接口:** 此接口为系统接口。
151
152**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
153
154**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
155
156**参数:**
157
158| 参数名       | 类型                                                         | 必填 | 说明                                                         |
159| ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
160| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)>   | 是   | ElementName信息,最大数组长度为10。                             |
161| callback     | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | 是   | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 |
162
163**错误码:**
164
165以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
166
167| 错误码ID |    错误信息                   |
168|----------|-------------------------|
169| 17700001 | The specified bundle name is not found. |
170| 17700003 | The specified ability name is not found. |
171| 17700007 | The specified device ID is not found. |
172| 17700027 | The distributed service is not running. |
173
174**示例:**
175
176```ts
177import distributedBundle from '@ohos.bundle.distributedBundleManager';
178import { BusinessError } from '@ohos.base';
179
180try {
181    distributedBundle.getRemoteAbilityInfo(
182        [
183            {
184                deviceId: '1',
185                bundleName: 'com.example.application1',
186                abilityName: 'EntryAbility1'
187            },
188            {
189                deviceId: '1',
190                bundleName: 'com.example.application2',
191                abilityName: 'EntryAbility'
192            }
193        ], (err: BusinessError, data: distributedBundle.RemoteAbilityInfo[]) => {
194          if (err) {
195            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
196          } else {
197            console.info('Operation succeed:' + JSON.stringify(data));
198          }
199        });
200} catch (err) {
201    let code = (err as BusinessError).code;
202    let message = (err as BusinessError).message;
203    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
204}
205```
206
207## distributedBundle.getRemoteAbilityInfo
208
209getRemoteAbilityInfo(elementNames: Array\<ElementName>): Promise\<Array\<RemoteAbilityInfo>>
210
211以异步方法获取由elementName指定的远程设备上的应用的AbilityInfo数组信息。使用Promise异步回调。
212
213**系统接口:** 此接口为系统接口。
214
215**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
216
217**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
218
219**参数:**
220
221| 参数名        | 类型                                                | 必填 | 说明                    |
222| ------------ | --------------------------------------------------- | ---- | ----------------------- |
223| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是   | ElementName信息,最大数组长度为10。 |
224
225**返回值:**
226
227| 类型                                                         | 说明                              |
228| ------------------------------------------------------------ | --------------------------------- |
229| Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
230
231**错误码:**
232
233以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
234
235| 错误码ID |    错误信息                   |
236|----------|-------------------------|
237| 17700001 | The specified bundle name is not found. |
238| 17700003 | The specified ability name is not found. |
239| 17700007 | The specified device ID is not found. |
240| 17700027 | The distributed service is not running. |
241
242**示例:**
243
244```ts
245import distributedBundle from '@ohos.bundle.distributedBundleManager';
246import { BusinessError } from '@ohos.base';
247
248try {
249    distributedBundle.getRemoteAbilityInfo(
250        [
251            {
252                deviceId: '1',
253                bundleName: 'com.example.application',
254                abilityName: 'EntryAbility'
255            },
256            {
257                deviceId: '1',
258                bundleName: 'com.example.application2',
259                abilityName: 'EntryAbility'
260            }
261        ]).then((data: distributedBundle.RemoteAbilityInfo[]) => {
262            console.info('Operation succeed:' + JSON.stringify(data));
263        }).catch((err: BusinessError) => {
264            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
265        });
266} catch (err) {
267    let code = (err as BusinessError).code;
268    let message = (err as BusinessError).message;
269    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
270}
271```
272
273## distributedBundle.getRemoteAbilityInfo
274
275getRemoteAbilityInfo(elementName: ElementName, locale: string, callback: AsyncCallback\<RemoteAbilityInfo>): void
276
277以异步方法获取由elementName和locale指定的远程设备上的应用的AbilityInfo信息。使用callback异步回调。
278
279**系统接口:** 此接口为系统接口。
280
281**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
282
283**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
284
285**参数:**
286
287| 参数名       | 类型                                                         | 必填 | 说明                                               |
288| ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
289| elementName | [ElementName](js-apis-bundleManager-elementName.md)                 | 是   | ElementName信息。                            |
290| locale  | string |是 | 语言地区。 |
291| callback    | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | 是   | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 |
292
293**错误码:**
294
295以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
296
297| 错误码ID |    错误信息                   |
298|----------|-------------------------|
299| 17700001 | The specified bundle name is not found. |
300| 17700003 | The specified ability name is not found. |
301| 17700007 | The specified device ID is not found. |
302| 17700027 | The distributed service is not running. |
303
304**示例:**
305
306```ts
307import distributedBundle from '@ohos.bundle.distributedBundleManager';
308import { BusinessError } from '@ohos.base';
309
310try {
311    distributedBundle.getRemoteAbilityInfo(
312        {
313            deviceId: '1',
314            bundleName: 'com.example.application',
315            abilityName: 'EntryAbility'
316        }, 'zh-Hans-CN', (err: BusinessError, data: distributedBundle.RemoteAbilityInfo) => {
317          if (err) {
318            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
319          } else {
320            console.info('Operation succeed:' + JSON.stringify(data));
321          }
322        });
323} catch (err) {
324    let code = (err as BusinessError).code;
325    let message = (err as BusinessError).message;
326    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
327}
328```
329
330## distributedBundle.getRemoteAbilityInfo
331
332getRemoteAbilityInfo(elementName: ElementName, locale: string): Promise\<RemoteAbilityInfo>
333
334以异步方法获取由elementName和locale指定的远程设备上的应用的AbilityInfo信息。使用Promise异步回调。
335
336**系统接口:** 此接口为系统接口。
337
338**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
339
340**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
341
342**参数:**
343
344| 参数名       | 类型                                         | 必填 | 说明                    |
345| ----------- | -------------------------------------------- | ---- | ----------------------- |
346| elementName | [ElementName](js-apis-bundleManager-elementName.md) | 是   | ElementName信息。 |
347| locale  | string |是 | 语言地区。 |
348
349**返回值:**
350
351| 类型                                                         | 说明                              |
352| ------------------------------------------------------------ | --------------------------------- |
353| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
354
355**错误码:**
356
357以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
358
359| 错误码ID |    错误信息                   |
360|----------|-------------------------|
361| 17700001 | The specified bundle name is not found. |
362| 17700003 | The specified ability name is not found. |
363| 17700007 | The specified device ID is not found. |
364| 17700027 | The distributed service is not running. |
365
366**示例:**
367
368```ts
369import distributedBundle from '@ohos.bundle.distributedBundleManager';
370import { BusinessError } from '@ohos.base';
371
372try {
373    distributedBundle.getRemoteAbilityInfo(
374        {
375            deviceId: '1',
376            bundleName: 'com.example.application',
377            abilityName: 'EntryAbility'
378        }, 'zh-Hans-CN').then((data: distributedBundle.RemoteAbilityInfo) => {
379            console.info('Operation succeed:' + JSON.stringify(data));
380        }).catch((err: BusinessError) => {
381            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
382        });
383} catch (err) {
384    let code = (err as BusinessError).code;
385    let message = (err as BusinessError).message;
386    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
387}
388```
389
390## distributedBundle.getRemoteAbilityInfo
391
392getRemoteAbilityInfo(elementNames: Array\<ElementName>, locale: string, callback: AsyncCallback\<Array\<RemoteAbilityInfo>>): void
393
394以异步方法获取由elementName和locale指定的远程设备上的应用的AbilityInfo数组信息。使用callback异步回调。
395
396**系统接口:** 此接口为系统接口。
397
398**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
399
400**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
401
402**参数:**
403
404| 参数名        | 类型                                                         | 必填 | 说明                                               |
405| ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
406| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)>          | 是   | ElementName信息,最大数组长度为10。                   |
407| locale  | string |是 | 语言地区。 |
408| callback     | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | 是   | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo数组对象;调用失败err为错误对象, data为undefined。 |
409
410**错误码:**
411
412以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
413
414| 错误码ID        |    错误信息                   |
415|---------------|-------------------------|
416| 17700001 | The specified bundle name is not found. |
417| 17700003 | The specified ability name is not found. |
418| 17700007 | The specified device ID is not found. |
419| 17700027 | The distributed service is not running. |
420
421**示例:**
422
423```ts
424import distributedBundle from '@ohos.bundle.distributedBundleManager';
425import { BusinessError } from '@ohos.base';
426
427try {
428    distributedBundle.getRemoteAbilityInfo(
429        [
430            {
431                deviceId: '1',
432                bundleName: 'com.example.application1',
433                abilityName: 'EntryAbility1'
434            },
435            {
436                deviceId: '1',
437                bundleName: 'com.example.application2',
438                abilityName: 'EntryAbility'
439            }
440        ], 'zh-Hans-CN', (err: BusinessError, data: distributedBundle.RemoteAbilityInfo[]) => {
441          if (err) {
442           console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
443          } else {
444            console.info('Operation succeed:' + JSON.stringify(data));
445          }
446        });
447} catch (err) {
448    let code = (err as BusinessError).code;
449    let message = (err as BusinessError).message;
450    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
451}
452```
453
454## distributedBundle.getRemoteAbilityInfo
455
456getRemoteAbilityInfo(elementNames: Array\<ElementName>, locale: string): Promise\<Array\<RemoteAbilityInfo>>
457
458以异步方法获取由elementName和locale指定的远程设备上的应用的AbilityInfo数组信息。使用Promise异步回调。
459
460**系统接口:** 此接口为系统接口。
461
462**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
463
464**系统能力:** SystemCapability.BundleManager.DistributedBundleFramework
465
466**参数:**
467
468| 参数名        | 类型                                                | 必填 | 说明                    |
469| ------------ | --------------------------------------------------- | ---- | ----------------------- |
470| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | 是   | ElementName信息,最大数组长度为10。 |
471| locale  | string |是 | 语言地区。 |
472
473**返回值:**
474
475| 类型                                                         | 说明                              |
476| ------------------------------------------------------------ | --------------------------------- |
477| Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Promise对象,调用成功返回RemoteAbilityInfo对象;调用失败返回错误对象。 |
478
479**错误码:**
480
481以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。
482
483| 错误码ID |    错误信息                   |
484|----------|-------------------------|
485| 17700001 | The specified bundle name is not found. |
486| 17700003 | The specified ability name is not found. |
487| 17700007 | The specified device ID is not found. |
488| 17700027 | The distributed service is not running. |
489
490**示例:**
491
492```ts
493import distributedBundle from '@ohos.bundle.distributedBundleManager';
494import { BusinessError } from '@ohos.base';
495
496try {
497    distributedBundle.getRemoteAbilityInfo(
498        [
499            {
500                deviceId: '1',
501                bundleName: 'com.example.application',
502                abilityName: 'EntryAbility'
503            },
504            {
505                deviceId: '1',
506                bundleName: 'com.example.application2',
507                abilityName: 'EntryAbility'
508            }
509        ], 'zh-Hans-CN').then((data: distributedBundle.RemoteAbilityInfo[]) => {
510            console.info('Operation succeed:' + JSON.stringify(data));
511        }).catch((err: BusinessError) => {
512            console.log(`Operation failed: error code is ${err.code}  and error message is ${err.message}`);
513        });
514} catch (err) {
515    let code = (err as BusinessError).code;
516    let message = (err as BusinessError).message;
517    console.log(`Operation failed: error code is ${code}  and error message is ${message}`);
518}
519```
520