1e41f4b71Sopenharmony_ci# @ohos.app.ability.UIServiceExtensionAbility (UIServiceExtensionAbility) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciUIServiceExtensionAbility, inherited from [ExtensionAbility](js-apis-app-ability-extensionAbility.md), provides extension capabilities related to the floating window component. It is mainly used to provide services with UIs for third-party applications.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci> **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 13. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9e41f4b71Sopenharmony_ci>
10e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model.
11e41f4b71Sopenharmony_ci>
12e41f4b71Sopenharmony_ci> The APIs of this module must be used in the main thread, but not in sub-threads such as Worker and TaskPool.
13e41f4b71Sopenharmony_ci>
14e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## Modules to Import
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci```ts
19e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility } from '@kit.AbilityKit';
20e41f4b71Sopenharmony_ci```
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Properties
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**System API**: This is a system API.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
31e41f4b71Sopenharmony_ci| context | [UIServiceExtensionContext](js-apis-inner-application-uiserviceExtensionContext-sys.md) | Yes| No| Context environment for a [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md).|
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onCreate
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_cionCreate(want: Want): void
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciCalled to initialize the service logic.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**System API**: This is a system API.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Parameters**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
47e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |  -------- |
48e41f4b71Sopenharmony_ci| want |  [Want](js-apis-app-ability-want.md) | Yes | No| [Want](js-apis-app-ability-want.md) information about the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md), including the ability name and bundle name.|
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**Example**
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci```ts
53e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility, Want } from '@kit.AbilityKit';
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ciclass UIServiceExt extends UIServiceExtensionAbility {
56e41f4b71Sopenharmony_ci  // Create a UIServiceExtensionAbility.
57e41f4b71Sopenharmony_ci  onCreate(want: Want) {
58e41f4b71Sopenharmony_ci    console.log(`onCreate, want: ${want.abilityName}`);
59e41f4b71Sopenharmony_ci  }
60e41f4b71Sopenharmony_ci}
61e41f4b71Sopenharmony_ci```
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onRequest
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_cionRequest(want: Want, startId: number): void
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciCalled to request to start a [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md). If the UIServiceExtensionAbility is started by calling [startAbility](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) or [startUIServiceExtensionAbility](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartuiserviceextensionability13), this callback will be invoked after [onCreate](#uiserviceextensionabilityoncreate). The value of **startId** is incremented for each UIServiceExtensionAbility that is started.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**System API**: This is a system API.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Parameters**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
77e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
78e41f4b71Sopenharmony_ci| want |  [Want](js-apis-app-ability-want.md) | Yes| No|  [Want](js-apis-app-ability-want.md) information about the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md), including the ability name and bundle name.|
79e41f4b71Sopenharmony_ci| startId | number | Yes|  |Number of UIServiceExtensionAbility start times. The initial value is **1**, and the value is automatically incremented for each UIServiceExtensionAbility started.|
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**Example**
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci```ts
84e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility, Want} from '@kit.AbilityKit';
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciclass UIServiceExt extends UIServiceExtensionAbility {
87e41f4b71Sopenharmony_ci  onRequest(want: Want, startId: number) {
88e41f4b71Sopenharmony_ci    console.log('onRequest, want:' + want.abilityName + ', startId:' + startId);
89e41f4b71Sopenharmony_ci  }
90e41f4b71Sopenharmony_ci}
91e41f4b71Sopenharmony_ci```
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onConnect
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_cionConnect(want: Want, proxy: UIServiceHostProxy): void
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ciCalled when the connection to a [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) is established. If the UIServiceExtensionAbility is started by calling [connectUIServiceExtensionAbility()](js-apis-inner-application-uiExtensionContext.md#uiextensioncontextconnectuiserviceextensionability13), this callback will be invoked after [onCreate()](#uiserviceextensionabilityoncreate). This callback receives a [UIServiceHostProxy](js-apis-inner-application-uiservicehostproxy-sys.md) object for communication between the client and server.
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**System API**: This is a system API.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Parameters**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
107e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
108e41f4b71Sopenharmony_ci| want |  [Want](js-apis-app-ability-want.md)| Yes| No| [Want](js-apis-app-ability-want.md) information about the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md), including the ability name and bundle name.|
109e41f4b71Sopenharmony_ci| proxy | [UIServiceHostProxy](js-apis-inner-application-uiservicehostproxy-sys.md) | Yes| No| [UIServiceHostProxy](js-apis-inner-application-uiservicehostproxy-sys.md) object, used for communication between the client and server.|
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**Example**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci```ts
115e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility, Want, common} from '@kit.AbilityKit';
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ciclass UIServiceExt extends UIServiceExtensionAbility {
118e41f4b71Sopenharmony_ci  onConnect(want: Want, proxy: common.UIServiceHostProxy){
119e41f4b71Sopenharmony_ci    console.log('onConnect, want:' + want.abilityName + '');
120e41f4b71Sopenharmony_ci  }
121e41f4b71Sopenharmony_ci}
122e41f4b71Sopenharmony_ci```
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onDisconnect
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_cionDisconnect(want: Want, proxy: UIServiceHostProxy): void
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ciCalled when the connection to a [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) is interrupted.
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**System API**: This is a system API.
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**Parameters**
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
138e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
139e41f4b71Sopenharmony_ci| want |[Want](js-apis-app-ability-want.md)| Yes| No| [Want](js-apis-app-ability-want.md) information about the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md), including the ability name and bundle name.|
140e41f4b71Sopenharmony_ci| proxy |[UIServiceHostProxy](js-apis-inner-application-uiservicehostproxy-sys.md)| Yes| No| Proxy that sends data to the sender.|
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**Example**
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci```ts
145e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility, Want, common } from '@kit.AbilityKit';
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ciclass UIServiceExt extends UIServiceExtensionAbility {
148e41f4b71Sopenharmony_ci  onDisconnect(want: Want, proxy: common.UIServiceHostProxy) {
149e41f4b71Sopenharmony_ci    console.log('onDisconnect, want: ${want.abilityName}');
150e41f4b71Sopenharmony_ci  }
151e41f4b71Sopenharmony_ci}
152e41f4b71Sopenharmony_ci```
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onWindowWillCreate
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_cionWindowWillCreate(config: window.ExtensionWindowConfig): void
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ciCalled when a window will be created for the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md). Through **window.ExtensionWindowConfig** in the callback, the foreground application sends the parameters for creating the window to the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md).
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**System API**: This is a system API.
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**Parameters**
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
168e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
169e41f4b71Sopenharmony_ci| config |[window.ExtensionWindowConfig](../apis-arkui/js-apis-window-sys.md#extensionwindowconfig12)| Yes| No| Window configuration information.|
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**Example**
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci```ts
174e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility } from '@kit.AbilityKit';
175e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ciclass UIServiceExt extends UIServiceExtensionAbility {
178e41f4b71Sopenharmony_ci  onWindowWillCreate(config : window.ExtensionWindowConfig){
179e41f4b71Sopenharmony_ci    console.log('onWindowWillCreate');
180e41f4b71Sopenharmony_ci  }
181e41f4b71Sopenharmony_ci}
182e41f4b71Sopenharmony_ci```
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onWindowDidCreate
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_cionWindowDidCreate(window: window.Window): void
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ciCalled when a window is created for the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md). Through this callback, the [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) passes the created window object to the foreground application.
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**System API**: This is a system API.
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Parameters**
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
197e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |  -------- |
198e41f4b71Sopenharmony_ci| window | [window.Window](../apis-arkui/js-apis-window-sys.md#window) | Yes| No| Window object created.|
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**Example**
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci```ts
203e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility } from '@kit.AbilityKit';
204e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ciclass ServiceExt extends UIServiceExtensionAbility {
207e41f4b71Sopenharmony_ci  onWindowDidCreate(window : window.Window){
208e41f4b71Sopenharmony_ci    console.log('onWindowDidCreate');
209e41f4b71Sopenharmony_ci  }
210e41f4b71Sopenharmony_ci}
211e41f4b71Sopenharmony_ci```
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onData
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_cionData(proxy: UIServiceHostProxy, data: Record<string, Object>): void
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ciCallback invoked when data is received.
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci**System API**: This is a system API.
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**Parameters**
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description|
226e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |  -------- |
227e41f4b71Sopenharmony_ci| proxy | [UIServiceHostProxy](js-apis-inner-application-uiservicehostproxy-sys.md) | Yes| No| Proxy that sends data to the client.|
228e41f4b71Sopenharmony_ci| data | Record<string, Object> | Yes| No| Data received.|
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**Example**
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci```ts
233e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility, common} from '@kit.AbilityKit';
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ciclass ServiceExt extends UIServiceExtensionAbility {
236e41f4b71Sopenharmony_ci  onData(proxy : common.UIServiceHostProxy, data : Record<string, Object> ){
237e41f4b71Sopenharmony_ci    console.log('onData');
238e41f4b71Sopenharmony_ci  }
239e41f4b71Sopenharmony_ci}
240e41f4b71Sopenharmony_ci```
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci## UIServiceExtensionAbility.onDestroy
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_cionDestroy(): void
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ciCalled to clear resources when this [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md) is destroyed.
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci**System API**: This is a system API.
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**Example**
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci```ts
255e41f4b71Sopenharmony_ciimport { UIServiceExtensionAbility } from '@kit.AbilityKit';
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ciclass ServiceExt extends UIServiceExtensionAbility {
258e41f4b71Sopenharmony_ci  onDestroy() {
259e41f4b71Sopenharmony_ci    console.log('onDestroy');
260e41f4b71Sopenharmony_ci  }
261e41f4b71Sopenharmony_ci}
262e41f4b71Sopenharmony_ci```
263