• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.uiExtensionHost (System API)
2
3Intended only for the **UIExtensionComponent** that has process isolation requirements, the **uiExtensionHost** module provides APIs for obtaining the host application window information and information about the component itself.
4
5> **NOTE**
6>
7> No new function will be added to this module. Related functions will be provided in the [uiExtension](js-apis-arkui-uiExtension.md) interface.
8>
9> The initial APIs of this module are supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version.
10>
11> The APIs provided by this module are system APIs.
12
13## Modules to Import
14
15```
16import { uiExtensionHost } from '@kit.ArkUI'
17```
18
19## UIExtensionHostWindowProxy
20
21### getWindowAvoidArea
22
23getWindowAvoidArea(type: window.AvoidAreaType): window.AvoidArea
24
25Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area.
26
27**System capability**: SystemCapability.ArkUI.ArkUI.Full
28
29**System API**: This is a system API and cannot be called by third-party applications.
30
31| Name | Type | Mandatory | Description |
32| -------- | -------- | -------- | -------- |
33| type | [window.AvoidAreaType](js-apis-window.md#avoidareatype7) | Yes | Type of the area. |
34
35**Return value**
36
37| Type | Description |
38| -------- | -------- |
39| [window.AvoidArea](js-apis-window.md#avoidarea7) | Area where the window cannot be displayed. |
40
41**Return value**
42
43| ID | Error Message        |
44| -------- | ---------------- |
45| 401      | Parameter error. |
46
47**Example**
48
49```ts
50// ExtensionProvider.ts
51
52import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
53import { window } from '@kit.ArkUI';
54
55export default class EntryAbility extends UIExtensionAbility {
56  onSessionCreate(want: Want, session: UIExtensionContentSession) {
57    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
58    // Obtain the information about the area where the window cannot be displayed.
59    const avoidArea = extensionHostWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
60    console.log(`avoidArea: ${JSON.stringify(avoidArea)}`);
61  }
62}
63```
64
65### on('avoidAreaChange')
66
67on(type: 'avoidAreaChange', callback: Callback<{ type: window.AvoidAreaType, area: window.AvoidArea }>): void
68
69Subscribes to the event indicating changes to the area where the window cannot be displayed.
70
71**System capability**: SystemCapability.ArkUI.ArkUI.Full
72
73**System API**: This is a system API and cannot be called by third-party applications.
74
75| Name  | Type  | Mandatory | Description                  |
76| -------- | ------ | ---- | ---------------------- |
77| type     | string | Yes  | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed. |
78| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback)<{ type: [window.AvoidAreaType](js-apis-window.md#avoidareatype7), area: [window.AvoidArea](js-apis-window.md#avoidarea7) }> | Yes | Callback used to return the area information. **type** indicates the type of the area where the window cannot be displayed, and **area** indicates the area. |
79
80**Error codes**
81
82| ID | Error Message                                                    |
83| -------- | ------------------------------------------------------------ |
84| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
85
86**Example**
87
88```ts
89// ExtensionProvider.ts
90import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
91
92export default class EntryAbility extends UIExtensionAbility {
93  onSessionCreate(want: Want, session: UIExtensionContentSession) {
94    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
95    // Subscribe to the event indicating changes to the area where the window cannot be displayed.
96    extensionHostWindow.on('avoidAreaChange', (info) => {
97      console.info(`The avoid area of the host window is: ${JSON.stringify(info.area)}.`);
98    });
99  }
100}
101```
102
103### off('avoidAreaChange')
104
105off(type: 'avoidAreaChange', callback?: Callback<{ type: window.AvoidAreaType, area: window.AvoidArea }>): void
106
107Unsubscribes from the event indicating changes to the area where the window cannot be displayed.
108
109**System capability**: SystemCapability.ArkUI.ArkUI.Full
110
111**System API**: This is a system API and cannot be called by third-party applications.
112
113| Name  | Type  | Mandatory | Description                  |
114| -------- | ------ | ---- | ---------------------- |
115| type     | string | Yes  | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed. |
116| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback)<{ type: [window.AvoidAreaType](js-apis-window.md#avoidareatype7), area: [window.AvoidArea](js-apis-window.md#avoidarea7) }> | No | Callback used for unsubscription. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. |
117
118**Error codes**
119
120| ID | Error Message                                                    |
121| -------- | ------------------------------------------------------------ |
122| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
123
124**Example**
125
126```ts
127// ExtensionProvider.ts
128import { UIExtensionAbility, UIExtensionContentSession} from '@kit.AbilityKit';
129
130export default class EntryAbility extends UIExtensionAbility {
131  onSessionDestroy(session: UIExtensionContentSession) {
132    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
133    // Cancel all subscriptions to the event indicating changes to the area where the window cannot be displayed.
134    extensionHostWindow.off('avoidAreaChange');
135  }
136}
137```
138
139### on('windowSizeChange')
140
141on(type: 'windowSizeChange', callback: Callback<window.Size>): void
142
143Subscribes to the window size change event.
144
145**System capability**: SystemCapability.ArkUI.ArkUI.Full
146
147**System API**: This is a system API and cannot be called by third-party applications.
148
149| Name  | Type                 | Mandatory | Description                  |
150| -------- | --------------------- | ---- | ---------------------- |
151| type     | string                | Yes  | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event. |
152| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback)<[window.Size](js-apis-window.md#size7)> | Yes  | Callback used to return the window size. |
153
154**Error codes**
155
156| ID | Error Message                                                    |
157| -------- | ------------------------------------------------------------ |
158| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
159
160**Example**
161
162```ts
163// ExtensionProvider.ts
164import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
165
166export default class EntryAbility extends UIExtensionAbility {
167  onSessionCreate(want: Want, session: UIExtensionContentSession) {
168    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
169    // Subscribe to the window size change event of the host application.
170    extensionHostWindow.on('windowSizeChange', (size) => {
171      console.info(`The avoid area of the host window is: ${JSON.stringify(size)}.`);
172    });
173  }
174}
175```
176
177### off('windowSizeChange')
178
179off(type: 'windowSizeChange', callback?: Callback<window.Size>): void
180
181Unsubscribes from the window size change event.
182
183**System capability**: SystemCapability.ArkUI.ArkUI.Full
184
185**System API**: This is a system API and cannot be called by third-party applications.
186
187| Name  | Type                 | Mandatory | Description                  |
188| -------- | --------------------- | ---- | ---------------------- |
189| type     | string                | Yes  | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event. |
190| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback)<[window.Size](js-apis-window.md#size7)> | No  | Callback used for unsubscription. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. |
191
192**Error codes**
193
194| ID | Error Message                                                    |
195| -------- | ------------------------------------------------------------ |
196| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
197
198**Example**
199
200```ts
201// ExtensionProvider.ts
202import { UIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit';
203
204export default class EntryAbility extends UIExtensionAbility {
205  onSessionDestroy(session: UIExtensionContentSession) {
206    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
207    // Unsubscribe from the window size change event of the host application.
208    extensionHostWindow.off('windowSizeChange');
209  }
210}
211```
212
213### properties
214
215properties: UIExtensionHostWindowProxyProperties
216
217Provides the information about the host application window and the **UIExtensionComponent**.
218
219**System capability**: SystemCapability.ArkUI.ArkUI.Full
220
221**System API**: This is a system API and cannot be called by third-party applications.
222
223| Name    | Type                                | Description                            |
224| ---------- | ------------------------------------ | -------------------------------- |
225| properties | [UIExtensionHostWindowProxyProperties](#uiextensionhostwindowproxyproperties) | Information about the host application window and the **UIExtensionComponent**. |
226
227**Example**
228
229```ts
230// ExtensionProvider.ts
231import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
232
233export default class EntryAbility extends UIExtensionAbility {
234  onSessionCreate(want: Want, session: UIExtensionContentSession) {
235    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
236    // Obtain the position and size of the <UIExtensionComponent>.
237    const rect = extensionHostWindow.properties.uiExtensionHostWindowProxyRect;
238    console.log(`Rect Info: ${JSON.stringify(rect)}`);
239  }
240}
241```
242
243### hideNonSecureWindows
244
245hideNonSecureWindows(shouldHide: boolean): Promise&lt;void&gt;
246
247Sets whether to hide insecure windows.
248> **NOTE**
249>
250> Insecure windows refer to the windows that may block the **UIExtensionComponent**, such as global floating windows, host subwindows, and dialog box windows created by the host application, excluding the aforementioned types of windows created by system applications. When the **UIExtensionComponent** is used to present important information, you can hide insecure windows to prevent such information from being obscured. When the **UIExtensionComponent** is not displayed or is destroyed, you must unhide the insecure windows. The **UIExtensionComponent** created using the **CreateModalUIExtension** API will hide insecure windows by default, which cannot be changed manually.
251
252**System capability**: SystemCapability.ArkUI.ArkUI.Full
253
254**System API**: This is a system API and cannot be called by third-party applications.
255
256**Parameters**
257
258| Name     | Type                     | Mandatory | Description      |
259| ----------- | ------------------------- | ---- | ---------- |
260| shouldHide  | boolean                   | Yes  | Whether to hide insecure windows. The value **true** means to hide insecure windows, and **false** means the opposite. |
261
262**Return value**
263
264| Type               | Description                     |
265| ------------------- | ------------------------- |
266| Promise&lt;void&gt; | Promise that returns no value. |
267
268**Error codes**
269
270| ID | Error Message                                                    |
271| -------- | ------------------------------------------------------------ |
272| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
273
274**Example**
275
276```ts
277// ExtensionProvider.ts
278
279import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
280import { BusinessError } from '@kit.BasicServicesKit';
281
282export default class EntryAbility extends UIExtensionAbility {
283  onSessionCreate(want: Want, session: UIExtensionContentSession) {
284    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
285    // Hide insecure windows.
286    extensionHostWindow.hideNonSecureWindows(true).then(()=> {
287      console.log(`Succeeded in hiding the non-secure windows.`);
288    }).catch((err: BusinessError)=> {
289      console.log(`Failed to hide the non-secure windows. Cause:${JSON.stringify(err)}`);
290    })
291  }
292  onSessionDestroy(session: UIExtensionContentSession) {
293    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
294    // Unhide insecure windows.
295    extensionHostWindow.hideNonSecureWindows(false).then(()=> {
296      console.log(`Succeeded in showing the non-secure windows.`);
297    }).catch((err: BusinessError)=> {
298      console.log(`Failed to show the non-secure windows. Cause:${JSON.stringify(err)}`);
299    })
300  }
301}
302```
303
304### createSubWindowWithOptions<sup>12+</sup>
305
306createSubWindowWithOptions(name: string, subWindowOptions: window.SubWindowOptions): Promise&lt;window.Window&gt;
307
308Creates a subwindow for this **UIExtensionHostWindowProxy** instance. This API uses a promise to return the result.
309
310**System capability**: SystemCapability.ArkUI.ArkUI.Full
311
312**System API**: This is a system API and cannot be called by third-party applications.
313
314**Model restriction**: This API can be used only in the stage model.
315
316**Parameters**
317
318| Name | Type  | Mandatory | Description          |
319| ------ | ------ | ---- | -------------- |
320| name   | string | Yes  | Name of the subwindow. |
321| subWindowOptions | [window.SubWindowOptions](js-apis-window.md#subwindowoptions11) | Yes | Parameters used for creating the subwindow. |
322
323**Return value**
324
325| Type                            | Description                                            |
326| -------------------------------- | ------------------------------------------------ |
327| Promise&lt;[window.Window](js-apis-window.md#window)&gt; | Promise used to return the subwindow created. |
328
329**Error codes**
330
331For details about the error codes, see [Window Error Codes](errorcode-window.md).
332
333| ID | Error Message |
334| ------- | ------------------------------ |
335| 401 | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified.<br> 2. Incorrect parameters types.<br> 3. Parameter verification failed. |
336| 801 | Capability not supported on this device. |
337| 1300002 | This window state is abnormal. |
338| 1300005 | This window proxy is abnormal. |
339
340**Example:**
341
342```ts
343// ExtensionProvider.ts
344import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
345import { BusinessError } from '@kit.BasicServicesKit';
346import { window } from '@kit.ArkUI';
347
348export default class EntryAbility extends UIExtensionAbility {
349  onSessionCreate(want: Want, session: UIExtensionContentSession) {
350    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
351    const subWindowOpts: window.SubWindowOptions = {
352      title: 'This is a subwindow',
353      decorEnabled: true
354    };
355    // Create a subwindow.
356    extensionHostWindow.createSubWindowWithOptions('subWindowForHost', subWindowOpts)
357      .then((subWindow: window.Window) => {
358        subWindow.loadContent('pages/Index', (err, data) =>{
359          if (err && err.code != 0) {
360            return;
361          }
362          subWindow?.resize(300, 300, (err, data)=>{
363            if (err && err.code != 0) {
364              return;
365            }
366            subWindow?.moveWindowTo(100, 100, (err, data)=>{
367              if (err && err.code != 0) {
368                return;
369              }
370              subWindow?.showWindow((err, data) => {
371                if (err && err.code == 0) {
372                  console.info(`The subwindow has been shown!`);
373                } else {
374                  console.error(`Failed to show the subwindow!`);
375                }
376              });
377            });
378          });
379        });
380      }).catch((error: BusinessError) => {
381        console.error(`Create subwindow failed: ${JSON.stringify(error)}`);
382      })
383  }
384}
385```
386
387### setWaterMarkFlag<sup>12+</sup>
388
389setWaterMarkFlag(enable: boolean): Promise&lt;void&gt;
390
391Adds or deletes the watermark flag for this window. This API uses a promise to return the result.
392> **NOTE**
393>
394> With the watermark flag added, the watermark is applied on the full screen when the window is in the foreground, regardless of whether the window is displayed in full screen, floating, and split screen mode.
395
396**System capability**: SystemCapability.ArkUI.ArkUI.Full
397
398**System API**: This is a system API and cannot be called by third-party applications.
399
400**Parameters**
401
402| Name | Type    | Mandatory | Description                                           |
403| ------ | ------- | --- | ------------------------------------------------ |
404| enable | boolean | Yes  | Whether to add or delete the flag. The value **true** means to add the watermark flag, and **false** means to delete the watermark flag. |
405
406**Return value**
407
408| Type               | Description                     |
409| ------------------- | ------------------------- |
410| Promise&lt;void&gt; | Promise that returns no value. |
411
412**Error codes**
413
414| ID | Error Message |
415| ------- | ---------------------------------------------- |
416| 1300002 | This window state is abnormal.                 |
417| 1300003 | This window manager service works abnormally.  |
418| 1300008 | The operation is on invalid display. |
419
420**Example**
421
422```ts
423// ExtensionProvider.ts
424import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
425import { BusinessError } from '@kit.BasicServicesKit';
426
427export default class EntryAbility extends UIExtensionAbility {
428  onSessionCreate(want: Want, session: UIExtensionContentSession) {
429    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
430    // Add the watermark flag.
431    extensionHostWindow.setWaterMarkFlag(true).then(() => {
432      console.log(`Succeeded in setting water mark flag of window.`);
433    }).catch((err: BusinessError) => {
434      console.log(`Failed to setting water mark flag of window. Cause:${JSON.stringify(err)}`);
435    })
436  }
437  onSessionDestroy(session: UIExtensionContentSession) {
438    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
439    // Delete the watermark flag.
440    extensionHostWindow.setWaterMarkFlag(false).then(() => {
441      console.log(`Succeeded in deleting water mark flag of window.`);
442    }).catch((err: BusinessError) => {
443      console.log(`Failed to deleting water mark flag of window. Cause:${JSON.stringify(err)}`);
444    })
445  }
446}
447```
448
449## UIExtensionHostWindowProxyProperties
450
451Defines information about the host application window and **UIExtensionComponent**.
452
453**System capability**: SystemCapability.ArkUI.ArkUI.Full
454
455**System API**: This is a system API.
456
457| Name                        | Type       | Mandatory     | Description                            |
458| ------------------------------ | ----------- | -------------------------------- | -------------------------------- |
459| uiExtensionHostWindowProxyRect | [window.Rect](js-apis-window.md#rect7) | Yes | Position, width, and height of the **UIExtensionComponent**. |
460
461## Example
462
463This example shows how to use all the available APIs in the UIExtensionAbility. The bundle name of the sample application, which requires a system signature, is **com.example.uiextensiondemo**, and the UIExtensionAbility to start is **ExampleUIExtensionAbility**.
464
465- The EntryAbility (UIAbility) of the sample application loads the **pages/Index.ets** file, whose content is as follows:
466
467  ```ts
468  // The UIAbility loads pages/Index.ets when started.
469  import { Want } from '@kit.AbilityKit';
470
471  @Entry
472  @Component
473  struct Index {
474    @State message: string = 'Message: '
475    private want: Want = {
476      bundleName: "com.example.uiextensiondemo",
477      abilityName: "ExampleUIExtensionAbility",
478      parameters: {
479        "ability.want.params.uiExtensionType": "sys/commonUI"
480      }
481    }
482
483    build() {
484      Row() {
485        Column() {
486          Text(this.message).fontSize(30)
487          UIExtensionComponent(this.want)
488            .width('100%')
489            .height('90%')
490        }
491        .width('100%')
492      }
493      .height('100%')
494    }
495  }
496  ```
497
498- The UIExtensionAbility to start by the **UIExtensionComponent** is implemented in the **ets/extensionAbility/ExampleUIExtensionAbility** file. The file content is as follows:
499
500  ```ts
501  import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
502
503  const TAG: string = '[ExampleUIExtensionAbility]'
504  export default class ExampleUIExtensionAbility extends UIExtensionAbility {
505    onCreate() {
506      console.log(TAG, `onCreate`);
507    }
508
509    onForeground() {
510      console.log(TAG, `onForeground`);
511    }
512
513    onBackground() {
514      console.log(TAG, `onBackground`);
515    }
516
517    onDestroy() {
518      console.log(TAG, `onDestroy`);
519    }
520
521    onSessionCreate(want: Want, session: UIExtensionContentSession) {
522      console.log(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`);
523      let param: Record<string, UIExtensionContentSession> = {
524        'session': session
525      };
526      let storage: LocalStorage = new LocalStorage(param);
527      session.loadContent('pages/extension', storage);
528    }
529  }
530  ```
531
532- The entry page file of the UIExtensionAbility is **pages/extension.ets**, whose content is as follows:
533
534  ```ts
535  import { UIExtensionContentSession } from '@kit.AbilityKit';
536  import { BusinessError } from '@kit.BasicServicesKit';
537  import { uiExtensionHost, window } from '@kit.ArkUI';
538
539  let storage = LocalStorage.getShared()
540
541  @Entry(storage)
542  @Component
543  struct Extension {
544    @State message: string = 'UIExtensionAbility Index';
545    private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');
546    private extensionWindow: uiExtensionHost.UIExtensionHostWindowProxy | undefined = this.session?.getUIExtensionHostWindowProxy();
547    private subWindow: window.Window | undefined = undefined;
548
549    aboutToAppear(): void {
550      this.extensionWindow?.on('windowSizeChange', (size) => {
551          console.info(`size = ${JSON.stringify(size)}`);
552      });
553      this.extensionWindow?.on('avoidAreaChange', (info) => {
554          console.info(`type = ${JSON.stringify(info.type)}, area = ${JSON.stringify(info.area)}`);
555      });
556      let promise = this.extensionWindow?.hideNonSecureWindows(true);
557      promise?.then(()=> {
558        console.log(`Succeeded in hiding the non-secure windows.`);
559      }).catch((err: BusinessError)=> {
560        console.log(`Failed to hide the non-secure windows. Cause:${JSON.stringify(err)}`);
561      })
562    }
563
564    aboutToDisappear(): void {
565      this.extensionWindow?.off('windowSizeChange');
566      this.extensionWindow?.off('avoidAreaChange');
567      let promise = this.extensionWindow?.hideNonSecureWindows(false);
568      promise?.then(()=> {
569        console.log(`Succeeded in showing the non-secure windows.`);
570      }).catch((err: BusinessError)=> {
571        console.log(`Failed to show the non-secure windows. Cause:${JSON.stringify(err)}`);
572      })
573    }
574
575    build() {
576      Column() {
577        Text(this.message)
578          .fontSize(20)
579          .fontWeight(FontWeight.Bold)
580        Button("Obtain Component Size").width('90%').margin({top: 5, bottom: 5}).fontSize(16).onClick(() => {
581          let rect = this.extensionWindow?.properties.uiExtensionHostWindowProxyRect;
582          console.info(`Width, height, and position of the UIExtensionComponent: ${JSON.stringify(rect)}`);
583        })
584        Button("Obtain Avoid Area Info").width('90%').margin({top: 5, bottom: 5}).fontSize(16).onClick(() => {
585          let avoidArea: window.AvoidArea | undefined = this.extensionWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
586          console.info(`System avoid area: ${JSON.stringify(avoidArea)}`);
587        })
588        Button("Create Subwindow").width('90%').margin({top: 5, bottom: 5}).fontSize(16).onClick(() => {
589          let subWindowOpts: window.SubWindowOptions = {
590            'title': 'This is a subwindow',
591            decorEnabled: true
592          };
593          this.extensionWindow?.createSubWindowWithOptions('subWindowForHost', subWindowOpts)
594            .then((subWindow: window.Window) => {
595              this.subWindow = subWindow;
596              this.subWindow.loadContent('pages/Index', storage, (err, data) =>{
597                if (err && err.code != 0) {
598                  return;
599                }
600                this.subWindow?.resize(300, 300, (err, data)=>{
601                  if (err && err.code != 0) {
602                    return;
603                  }
604                  this.subWindow?.moveWindowTo(100, 100, (err, data)=>{
605                    if (err && err.code != 0) {
606                      return;
607                    }
608                    this.subWindow?.showWindow((err, data) => {
609                      if (err && err.code == 0) {
610                        console.info(`The subwindow has been shown!`);
611                      } else {
612                        console.error(`Failed to show the subwindow!`);
613                      }
614                    });
615                  });
616                });
617              });
618            }).catch((error: BusinessError) => {
619              console.error(`Create subwindow failed: ${JSON.stringify(error)}`);
620            })
621        })
622      }.width('100%').height('100%')
623    }
624  }
625  ```
626
627- Add an item to **extensionAbilities** in the **module.json5** file of the sample application. The details are as follows:
628  ```json
629  {
630    "name": "ExampleUIExtensionAbility",
631    "srcEntry": "./ets/extensionAbility/ExampleUIExtensionAbility.ets",
632    "type": "sys/commonUI",
633  }
634  ```
635