js-apis-distributedBundle.md 18.7 KB
Newer Older
G
Gloria 已提交
1 2 3 4 5 6 7
# distributedBundle

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.
8 9
>
> The APIs provided by this module are system APIs.
G
Gloria 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

## Modules to Import

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

## System Capability

SystemCapability.BundleManager.DistributedBundleFramework

## Required Permissions

| Permission                                      | Permission Level    | Description              |
| ------------------------------------------ | ------------ | ------------------ |
25
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.|
G
Gloria 已提交
26

27
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
G
Gloria 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

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

43 44 45
| Name     | Type                                                        | Mandatory| Description                                                        |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| elementName | [ElementName](js-apis-bundleManager-elementName.md)          | Yes  | Target element name.                                           |
G
Gloria 已提交
46 47 48 49
| callback    | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Yes  | Callback 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.|

**Error codes**

50
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
51

52 53 54
| ID|    Error Message                  |
|----------|--------------------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
55
| 17700003 | The specified ability name is not found. |
56
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
57 58 59 60
| 17700027 | The distributed service is not running. |

**Example**

61
```ts
G
Gloria 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
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>;

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

94
| Name      | Type                                        | Mandatory| Description                   |
G
Gloria 已提交
95 96 97 98 99 100 101 102 103 104 105
| ----------- | -------------------------------------------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes  | Target element name.|

**Return value**

| Type                                                        | Description                             |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise used to return the **RemoteAbilityInfo** object obtained.|

**Error codes**

106
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
107

108 109 110
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
111
| 17700003 | The specified ability name is not found. |
112
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
113 114 115 116
| 17700027 | The distributed service is not running. |

**Example**

117
```ts
G
Gloria 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
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;

Obtains information about 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**

148 149 150
| Name      | Type                                                        | Mandatory| Description                                                        |
| ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)>   | Yes  | **ElementName** array, whose maximum length is 10.                            |
G
Gloria 已提交
151 152 153 154
| callback     | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Yes  | Callback 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.|

**Error codes**

155
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
156

157 158 159
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
160
| 17700003 | The specified ability name is not found. |
161
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
162 163 164 165
| 17700027 | The distributed service is not running. |

**Example**

166
```ts
G
Gloria 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
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>>;

196
Obtains information about remote abilities that match the given element names and locales. This API uses a promise to return the result.
G
Gloria 已提交
197 198 199 200 201 202 203 204 205

**System API**: This is a system API.

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.BundleManager.DistributedBundleFramework

**Parameters**

206
| Name       | Type                                               | Mandatory| Description                   |
G
Gloria 已提交
207 208 209 210 211 212 213 214 215 216 217
| ------------ | --------------------------------------------------- | ---- | ----------------------- |
| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes  | **ElementName** array, whose maximum length is 10.|

**Return value**

| Type                                                        | Description                             |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Promise used to return the array of **RemoteAbilityInfo** objects obtained.|

**Error codes**

218
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
219

220 221 222
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
223
| 17700003 | The specified ability name is not found. |
224
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
225 226 227 228
| 17700027 | The distributed service is not running. |

**Example**

229
```ts
G
Gloria 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
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;

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

267
| Name      | Type                                                        | Mandatory| Description                                              |
G
Gloria 已提交
268 269 270 271 272 273 274
| ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md)                 | Yes  | Target element name.                           |
| locale  | string |Yes| Target locale.|
| callback    | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Yes  | Callback 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.|

**Error codes**

275
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
276

277 278 279
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
280
| 17700003 | The specified ability name is not found. |
281
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
282 283 284 285
| 17700027 | The distributed service is not running. |

**Example**

286
```ts
G
Gloria 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
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>;

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

319
| Name      | Type                                        | Mandatory| Description                   |
G
Gloria 已提交
320 321 322 323 324 325 326 327 328 329 330 331
| ----------- | -------------------------------------------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes  | Target element name.|
| locale  | string |Yes| Target locale.|

**Return value**

| Type                                                        | Description                             |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Promise used to return the **RemoteAbilityInfo** object obtained.|

**Error codes**

332
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
333

334 335 336
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
337
| 17700003 | The specified ability name is not found. |
338
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
339 340 341 342
| 17700027 | The distributed service is not running. |

**Example**

343
```ts
G
Gloria 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
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;

Obtains information about remote abilities that match the given element names and locales. 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**

374
| Name       | Type                                                        | Mandatory| Description                                              |
G
Gloria 已提交
375 376 377 378 379 380 381
| ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)>          | Yes  | **ElementName** array, whose maximum length is 10.                  |
| locale  | string |Yes| Target locale.|
| callback     | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Yes  | Callback 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.|

**Error codes**

382
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
383 384 385

| ID       |    Error Message                  |
|---------------|-------------------------|
386
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
387
| 17700003 | The specified ability name is not found. |
388
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
389 390 391 392
| 17700027 | The distributed service is not running. |

**Example**

393
```ts
G
Gloria 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
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>>;

Obtains information about remote abilities that match the given element names and locales. 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**

433
| Name       | Type                                               | Mandatory| Description                   |
G
Gloria 已提交
434 435 436 437 438 439 440 441 442 443 444 445
| ------------ | --------------------------------------------------- | ---- | ----------------------- |
| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes  | **ElementName** array, whose maximum length is 10.|
| locale  | string |Yes| Target locale.|

**Return value**

| Type                                                        | Description                             |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<Array<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Promise used to return the array of **RemoteAbilityInfo** objects obtained.|

**Error codes**

446
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
G
Gloria 已提交
447

448 449 450
| ID|    Error Message                  |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
G
Gloria 已提交
451
| 17700003 | The specified ability name is not found. |
452
| 17700007 | The specified device ID is not found. |
G
Gloria 已提交
453 454 455 456
| 17700027 | The distributed service is not running. |

**Example**

457
```ts
G
Gloria 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
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));
}
```