js-apis-overlay.md 29.8 KB
Newer Older
G
Gloria 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# @ohos.bundle.overlay (overlay)

The **overlay** module provides APIs for installing a [module with the overlay feature](#module-with-the-overlay-feature), querying the [module information](js-apis-bundleManager-overlayModuleInfo.md), and disabling and enabling the module.

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

## Modules to Import

``` ts
import overlay from '@ohos.bundle.overlay'
```

## overlay.setOverlayEnabled

setOverlayEnabled(moduleName:string, isEnabled: boolean): Promise\<void>;

Enables or disables a module with the overlay feature in the current application. This API uses a promise to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| moduleName  | string | Yes   | HAP name of the module with the overlay feature.              |
| isEnabled   | boolean  | Yes | Whether to enable the module with the overlay feature. The value **true** means to enable the module, and **false** means to disable the module.|

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
| Promise\<void> | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
42 43
| 17700002 | The specified module name is not found. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
44 45 46 47 48 49 50 51 52 53 54

**Example**

```ts
var moduleName = "feature";
var isEnabled = false;

try {
    overlay.setOverlayEnabled(moduleName, isEnabled)
        .then(() => {
            console.info('setOverlayEnabled success');
55 56
        }).catch((err) => {
            console.info('setOverlayEnabled failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
57
        });
58 59
} catch (err) {
    console.info('setOverlayEnabled failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
}
```

## overlay.setOverlayEnabled

setOverlayEnabled(moduleName:string, isEnabled: boolean, callback: AsyncCallback\<void>): void;

Enables or disables a module with the overlay feature in the current application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| moduleName  | string | Yes   | HAP name of the module with the overlay feature.              |
| isEnabled   | boolean  | Yes | Whether to enable the module with the overlay feature. The value **true** means to enable the module, and **false** means to disable the module.|
| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
85 86
| 17700002 | The specified module name is not found. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
87 88 89 90 91 92 93 94

**Example**

```ts
var moduleName = "feature";
var isEnabled = false;

try {
95 96 97
    overlay.setOverlayEnabled(moduleName, isEnabled, (err, data) => {
        if (err) {
            console.info('setOverlayEnabled failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
98 99 100 101
            return;
        }
        console.info('setOverlayEnabled success');
    });
102 103
} catch (err) {
    console.info('setOverlayEnabled failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116
}
```

## overlay.setOverlayEnabledByBundleName

setOverlayEnabledByBundleName(bundleName:string, moduleName:string, isEnabled: boolean): Promise\<void>;

Enables or disables a module with the overlay feature in another application. This API uses a promise to return the result. If the operation is successful, the processing result is returned; otherwise, an error message is returned.

**Required permissions**: ohos.permission.CHANGE_OVERLAY_ENABLED_STATE

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

117
**System API**: This is a system API.
G
Gloria 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName  | string | Yes   | Bundle name of the application.                |
| moduleName  | string | Yes   | HAP name of the module with the overlay feature.   |
| isEnabled   | boolean  | Yes | Whether to enable the module with the overlay feature. The value **true** means to enable the module, and **false** means to disable the module.|

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
| Promise\<void> | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
139 140 141 142
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified module name is not found. |
| 17700032 | The specified bundle does not contain any overlay module. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
143 144 145 146 147

**Example**

```ts
var bundleName = "com.example.myapplication_xxxxx";
148
var moduleName = "feature";
G
Gloria 已提交
149 150 151 152 153 154
var isEnabled = false;

try {
    overlay.setOverlayEnabledByBundleName(bundleName, moduleName, isEnabled)
        .then((data) => {
            console.info('setOverlayEnabledByBundleName successfully');
155 156
        }).catch((err) => {
            console.info('setOverlayEnabledByBundleName failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
157
        });
158 159
} catch (err) {
    console.info('setOverlayEnabledByBundleName failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172
}
```

## overlay.setOverlayEnabledByBundleName

setOverlayEnabledByBundleName(bundleName:string, moduleName:string, isEnabled: boolean, callback: AsyncCallback\<void>): void;

Enables or disables a module with the overlay feature in another application. This API uses an asynchronous callback to return the result. If the operation is successful, the processing result is returned; otherwise, an error message is returned.

**Required permissions**: ohos.permission.CHANGE_OVERLAY_ENABLED_STATE

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

173
**System API**: This is a system API.
G
Gloria 已提交
174 175 176 177 178 179 180 181

**Parameters**

| Name      | Type    | Mandatory  | Description                                 |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName  | string | Yes   | Bundle name of the application.                |
| moduleName  | string | Yes   | HAP name of the module with the overlay feature.   |
| isEnabled   | boolean  | Yes | Whether to enable the module with the overlay feature. The value **true** means to enable the module, and **false** means to disable the module.|
182
| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined** and data is the processing result obtained; otherwise, **err** is an error object.                   |
G
Gloria 已提交
183 184 185 186 187 188 189

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
190 191 192 193
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified module name is not found. |
| 17700032 | The specified bundle does not contain any overlay module. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
194 195 196 197 198

**Example**

```ts
var bundleName = "com.example.myapplication_xxxxx";
199
var moduleName = "feature";
G
Gloria 已提交
200 201 202
var isEnabled = false;

try {
203 204 205
    overlay.setOverlayEnabledByBundleName(bundleName, moduleName, isEnabled, (err, data) => {
        if (err) {
            console.info('setOverlayEnabledByBundleName failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
206 207 208 209
            return;
        }
        console.info('setOverlayEnabledByBundleName successfully');
    });
210 211
} catch (err) {
    console.info('setOverlayEnabledByBundleName failed due to err code: ' + err.code + ' ' + 'message:' + err.message);
G
Gloria 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
}
```

## overlay.getOverlayModuleInfo

getOverlayModuleInfo(moduleName: string): Promise\<OverlayModuleInfo>;

Obtains the information about a module with the overlay feature in the current application. This API uses a promise to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | ------------------------------------------ |
| moduleName | string | Yes   | HAP name of the module with the overlay feature.    |

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
| Promise\<OverlayModuleInfo> | Promise used to return the result, which is an **OverlayModuleInfo** object.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
241
| 17700002 | The specified module name is not found. |
242
| 17700032 | The specified bundle does not contain any overlay module. |
243
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
244 245 246 247

**Example**

```ts
248
var moduleName = "feature";
G
Gloria 已提交
249 250 251 252 253 254

(async() => {
    try {
        let overlayModuleInfo = await overlay.getOverlayModuleInfo(moduleName);
        console.log('overlayModuleInfo is ' + JSON.stringify(overlayModuleInfo));
    } catch(err) {
255
        console.log('getOverlayModuleInfo failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    }
})();
```

## overlay.getOverlayModuleInfo

getOverlayModuleInfo(moduleName: string, callback: AsyncCallback\<OverlayModuleInfo>): void;

Obtains the information about a module with the overlay feature in the current application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| moduleName | string | Yes   | HAP name of the module with the overlay feature.    |
273
| callback    | AsyncCallback\<OverlayModuleInfo> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
274 275 276 277 278 279 280

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
281
| 17700002 | The specified module name is not found. |
282
| 17700032 | The specified bundle does not contain any overlay module. |
283
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
284 285 286 287

**Example**

```ts
288
var moduleName = "feature";
G
Gloria 已提交
289
try {
290 291 292
    overlay.getOverlayModuleInfo(moduleName, (err, data) => {
        if (err) {
            console.log('getOverlayModuleInfo failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
293 294 295 296
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
297 298
} catch (err) {
    console.log('getOverlayModuleInfo failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
}
```

## overlay.getTargetOverlayModuleInfos

getTargetOverlayModuleInfos(targetModuleName: string): Promise\<Array\<OverlayModuleInfo>>;

Obtains the information about modules with the overlay feature in the current application based on the target module name. This API uses a promise to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| targetModuleName | string | Yes   | HAP name of the target module, which is **targetModuleName** specified by modules with the overlay feature.    |

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
| Promise\<Array\<OverlayModuleInfo>> | Promise used to return the result, which is an array of **OverlayModuleInfo** objects.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
328 329
| 17700002 | The specified module name is not found. |
| 17700034 | The specified module is an overlay module. |
G
Gloria 已提交
330 331 332 333

**Example**

```ts
334
var targetModuleName = "feature";
G
Gloria 已提交
335 336 337 338 339 340

(async() => {
    try {
        let overlayModuleInfos = await overlay.getTargetOverlayModuleInfos(targetModuleName);
        console.log('overlayModuleInfos are ' + JSON.stringify(overlayModuleInfos));
    } catch(err) {
341
        console.log('getTargetOverlayModuleInfos failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    }
})();
```

## overlay.getTargetOverlayModuleInfos

getTargetOverlayModuleInfos(targetModuleName: string, callback: AsyncCallback\<Array\<OverlayModuleInfo>>): void;

Obtains the information about modules with the overlay feature in the current application based on the target module name. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| targetModuleName | string | Yes   | HAP name of the target module specified by modules with the overlay feature.    |
359
| callback    | AsyncCallback\<Array\<OverlayModuleInfo>> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
360 361 362 363 364 365 366

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
367 368
| 17700002 | The specified module name is not found.  |
| 17700034 | The specified module is an overlay module. |
G
Gloria 已提交
369 370 371 372

**Example**

```ts
373
var targetModuleName = "feature";
G
Gloria 已提交
374
try {
375 376 377
    overlay.getTargetOverlayModuleInfos(targetModuleName, (err, data) => {
        if (err) {
            console.log('getTargetOverlayModuleInfos failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
378 379 380 381
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
382 383
} catch (err) {
    console.log('getTargetOverlayModuleInfos failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
384 385 386 387 388 389 390 391 392 393 394 395 396
}
```

## overlay.getOverlayModuleInfoByBundleName

getOverlayModuleInfoByBundleName(bundleName: string, moduleName?: string): Promise\<Array\<OverlayModuleInfo>>;

Obtains the information about a module with the overlay feature in another application. This API uses a promise to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

397
**System API**: This is a system API.
G
Gloria 已提交
398 399 400 401 402 403

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName | string | Yes   | Bundle name of the application.                   |
404
| moduleName | string | No   | HAP name of the module with the overlay feature. By default, no value is passed, and the API obtains the information of all modules with the overlay feature in that application.    |
G
Gloria 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
| Promise\<Array\<OverlayModuleInfo>> | Promise used to return the result, which is an array of **OverlayModuleInfo** objects.|

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
418
| 17700001 | The specified bundleName is not found. |
419 420 421
| 17700002 | The specified module name is not found. |
| 17700032 | The specified bundle does not contain any overlay module. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
422 423 424 425 426

**Example**

```ts
var bundleName = "com.example.myapplication_xxxxx";
427
var moduleName = "feature";
G
Gloria 已提交
428 429 430 431 432 433

(async() => {
    try {
        let overlayModuleInfos = await overlay.getOverlayModuleInfoByBundleName(bundleName, moduleName);
        console.log('overlayModuleInfos are ' + JSON.stringify(overlayModuleInfos));
    } catch(err) {
434
        console.log('getTargetOverlayModuleInfos failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448
    }
})();
```

## overlay.getOverlayModuleInfoByBundleName

getOverlayModuleInfoByBundleName(bundleName: string, moduleName: string, callback: AsyncCallback\<Array\<OverlayModuleInfo>>): void;

Obtains the information about a module with the overlay feature in another application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

449
**System API**: This is a system API.
G
Gloria 已提交
450 451 452 453 454 455 456

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName | string | Yes   | Bundle name of the application.                   |
| moduleName | string | Yes   | HAP name of the module with the overlay feature. If this parameter is not specified, the API obtains the information of all modules with the overlay feature in that application.    |
457
| callback    | AsyncCallback\<Array\<OverlayModuleInfo>> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
458 459 460 461 462 463 464

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
465
| 17700001 | The specified bundleName is not found. |
466 467 468
| 17700002 | The specified module name is not found. |
| 17700032 | The specified bundle does not contain any overlay module. |
| 17700033 | The specified module is not an overlay module. |
G
Gloria 已提交
469 470 471 472 473

**Example**

```ts
var bundleName = "com.example.myapplication_xxxxx";
474
var moduleName = "feature";
G
Gloria 已提交
475 476

try {
477 478 479
    overlay.getOverlayModuleInfoByBundleName(bundleName, moduleName, (err, data) => {
        if (err) {
            console.log('getOverlayModuleInfoByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
480 481 482 483
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
484 485
} catch (err) {
    console.log('getOverlayModuleInfoByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498
}
```

## overlay.getOverlayModuleInfoByBundleName

getOverlayModuleInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<OverlayModuleInfo>>): void;

Obtains the information about all modules with the overlay feature in another application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

499
**System API**: This is a system API.
G
Gloria 已提交
500 501 502 503 504 505

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName | string | Yes   | Bundle name of the application.                   |
506
| callback    | AsyncCallback\<Array\<OverlayModuleInfo>> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
507 508 509 510 511 512 513

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
514
| 17700001 | The specified bundleName is not found. |
515
| 17700032 | The specified bundle does not contain any overlay module. |
G
Gloria 已提交
516 517 518 519 520 521 522

**Example**

```ts
var bundleName = "com.example.myapplication_xxxxx";

try {
523 524 525
    overlay.getOverlayModuleInfoByBundleName(bundleName, (err, data) => {
        if (err) {
            console.log('getOverlayModuleInfoByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
526 527 528 529
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
530 531
} catch (err) {
    console.log('getOverlayModuleInfoByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544
}
```

## overlay.getTargetOverlayModuleInfosByBundleName

getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName?: string): Promise\<Array\<OverlayModuleInfo>>;

Obtains the information about modules with the overlay feature in another application based on the target module name. This API uses a promise to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

545
**System API**: This is a system API.
G
Gloria 已提交
546 547 548 549 550 551

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| targetBundleName | string | Yes   | Bundle name of the application.                   |
552
| moduleName | string | No   | HAP name of the target module, which is **targetModuleName** specified by modules with the overlay feature. By default, no value is passed, and the API obtains the information associated with all modules in that application.    |
G
Gloria 已提交
553 554 555 556 557

**Return value**

| Type                       | Description                |
| ------------------------- | ------------------ |
558
| Promise\<Array\<OverlayModuleInfo>> | Promise used to return the result, which is an array of **OverlayModuleInfo** objects.|
G
Gloria 已提交
559 560 561 562 563 564 565

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
566
| 17700001 | The specified bundleName is not found. |
567 568 569
| 17700002 | The specified module name is not found. |
| 17700034 | The specified module is an overlay module. |
| 17700035 | The specified bundle is an overlay bundle. |
G
Gloria 已提交
570 571 572 573 574

**Example**

```ts
var targetBundleName = "com.example.myapplication_xxxxx";
575
var moduleName = "feature";
G
Gloria 已提交
576 577 578 579 580 581

(async() => {
    try {
        let overlayModuleInfos = await overlay.getTargetOverlayModuleInfosByBundleName(targetBundleName, moduleName);
        console.log('overlayModuleInfos are ' + JSON.stringify(overlayModuleInfos));
    } catch(err) {
582
        console.log('getTargetOverlayModuleInfosByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
583 584 585 586 587 588
    }
})();
```

## overlay.getTargetOverlayModuleInfosByBundleName

589
getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName: string, callback: AsyncCallback&lt;Array&lt;OverlayModuleInfo&gt;&gt;): void;
G
Gloria 已提交
590 591 592 593 594 595 596

Obtains the information about modules with the overlay feature in another application based on the target module name. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

597
**System API**: This is a system API.
G
Gloria 已提交
598 599 600 601 602 603

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| targetBundleName | string | Yes   | Bundle name of the application.                   |
604 605
| moduleName | string | Yes   | HAP name of the target module, which is **targetModuleName** specified by modules with the overlay feature. If this parameter is not specified, the API obtains the information associated with all modules in that application.    |
| callback    | AsyncCallback\<Array\<OverlayModuleInfo>> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
606 607 608 609 610 611 612

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
613
| 17700001 | The specified bundleName is not found. |
614 615 616
| 17700002 | The specified module name is not found. |
| 17700034 | The specified module is an overlay module. |
| 17700035 | The specified bundle is an overlay bundle. |
G
Gloria 已提交
617 618 619 620 621

**Example**

```ts
var targetBundleName = "com.example.myapplication_xxxxx";
622
var moduleName = "feature";
G
Gloria 已提交
623 624

try {
625 626 627
    overlay.getTargetOverlayModuleInfosByBundleName(targetBundleName, moduleName, (err, data) => {
        if (err) {
            console.log('getTargetOverlayModuleInfosByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
628 629 630 631
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
632 633
} catch (err) {
    console.log('getTargetOverlayModuleInfosByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
634 635 636 637 638
}
```

## overlay.getTargetOverlayModuleInfosByBundleName

639
getTargetOverlayModuleInfosByBundleName(targetBundleName: string, callback: AsyncCallback&lt;Array&lt;OverlayModuleInfo&gt;&gt;): void;
G
Gloria 已提交
640 641 642 643 644 645 646

Obtains the information about all modules with the overlay feature in another application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned; otherwise, an error message is returned.

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

**System capability**: SystemCapability.BundleManager.BundleFramework.Overlay

647
**System API**: This is a system API.
G
Gloria 已提交
648 649 650 651 652 653

**Parameters**

| Name      | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | --------------------------------------- |
| targetBundleName | string | Yes   | Bundle name of the application.                   |
654
| callback    | AsyncCallback\<Array\<OverlayModuleInfo>> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.                  |
G
Gloria 已提交
655 656 657 658 659 660 661

**Error codes**

For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).

| ID| Error Message                               |
| ------ | -------------------------------------- |
662
| 17700001 | The specified bundleName is not found. |
663
| 17700035 | The specified bundle is an overlay bundle. |
G
Gloria 已提交
664 665 666 667 668 669 670

**Example**

```ts
var targetBundleName = "com.example.myapplication_xxxxx";

try {
671 672 673
    overlay.getTargetOverlayModuleInfosByBundleName(targetBundleName, (err, data) => {
        if (err) {
            console.log('getTargetOverlayModuleInfosByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
674 675 676 677
            return;
        }
        console.log('overlayModuleInfo is ' + JSON.stringify(data));
    });
678 679
} catch (err) {
    console.log('getTargetOverlayModuleInfosByBundleName failed due to err code : ' + err.code + ' ' + 'message :' + err.message);
G
Gloria 已提交
680 681 682 683 684 685 686 687 688 689
}
```

## Module with the Overlay Feature

**Concept**
A module with the overlay feature generally provides additional resource files for modules without the overlay feature on the device, so that the target modules can use these resource files at runtime to display different colors, labels, themes, and the like. The overlay feature applies only to the stage model.

**How do I identify a module with the overlay feature?**
If the **module.json5** file of a module contains the **targetModuleName** and **targetPriority fields** during project creation on DevEco Studio, the module is identified as a module with the overlay feature in the installation phase.