• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.WindowExtensionAbility (WindowExtensionAbility)
2
3**WindowExtensionAbility** inherits from **ExtensionAbility**. The content in a **WindowExtensionAbility** object can be displayed as an ability component in other application windows.
4
5> **NOTE**
6>
7> 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.
10>
11> The APIs of this module can be used only in the stage model.
12
13## Modules to Import
14
15```ts
16import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
17```
18
19## Attributes
20
21**System capability**: SystemCapability.WindowManager.WindowManager.Core
22
23| Name     | Type| Readable| Writable| Description                     |
24| --------- | -------- | ---- | ---- | ------------------------- |
25| context      | [WindowExtensionContext](js-apis-inner-application-windowExtensionContext.md)   | Yes  | No  | Context of an Extension ability.     |
26
27## WindowExtensionAbility.onConnect
28
29onConnect(want: Want): void
30
31Called when this Window Extension ability is connected to an ability for the first time.
32
33**System capability**: SystemCapability.WindowManager.WindowManager.Core
34
35**Parameters**
36
37| Name| Type| Mandatory| Description|
38| -------- | -------- | -------- | -------- |
39| want | [Want](js-apis-app-ability-want.md) | Yes| Information related to this Window Extension ability, including the ability name and bundle name.|
40
41**Example**
42
43```ts
44import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
45import Want from '@ohos.app.ability.Want';
46
47export default class MyWindowExtensionAbility extends WindowExtensionAbility {
48  onConnect(want: Want) {
49    console.info('WindowExtAbility onConnect, abilityName: ${want.abilityName}');
50  }
51}
52```
53
54## WindowExtensionAbility.onDisconnect
55
56onDisconnect(want: Want): void
57
58Called when this Window Extension ability is disconnected from all connected abilities.
59
60**System capability**: SystemCapability.WindowManager.WindowManager.Core
61
62**Parameters**
63
64| Name| Type| Mandatory| Description|
65| -------- | -------- | -------- | -------- |
66| want | [Want](js-apis-app-ability-want.md) | Yes| Information related to this Window Extension ability, including the ability name and bundle name.|
67
68
69**Example**
70
71```ts
72import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
73import Want from '@ohos.app.ability.Want';
74
75export default class MyWindowExtensionAbility extends WindowExtensionAbility {
76  onDisconnect(want: Want) {
77    console.info('WindowExtAbility onDisconnect, abilityName: ${want.abilityName}');
78  }
79}
80```
81
82## WindowExtensionAbility.onWindowReady
83
84onWindowReady(window: window.Window): void
85
86Called when a window is ready.
87
88**System capability**: SystemCapability.WindowManager.WindowManager.Core
89
90**Parameters**
91
92| Name| Type| Mandatory| Description|
93| -------- | -------- | -------- | -------- |
94| window | [window.Window](js-apis-window.md#window) | Yes| Current **Window** instance.|
95
96
97**Example**
98
99```ts
100import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
101import window from '@ohos.window';
102import {BusinessError} from '@ohos.base';
103
104export default class MyWindowExtensionAbility extends WindowExtensionAbility {
105  onWindowReady(window: window.Window) {
106    window.setUIContent('WindowExtAbility/pages/index1',(err:BusinessError) => {
107      let pro = window.getWindowProperties();
108      console.log('WindowExtension pro: ${JSON.stringify(pro)}');
109      window.showWindow();
110    });
111  }
112}
113```
114