• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.UIExtensionContentSession (UI Operation Class for ExtensionAbilities with UI)
2
3UIExtensionContentSession is an instance created when the [UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md) loads UI content. When the UIExtensionComponent starts a UIExtensionAbility, the UIExtensionAbility creates a UIExtensionContentSession instance and returns it through the [onSessionCreate](js-apis-app-ability-uiExtensionAbility.md#onsessioncreate) callback. One UIExtensionComponent corresponds to one UIExtensionContentSession instance, which provides methods such as UI loading and result notification. The UIExtensionContentSession instances of multiple UIExtensionAbilities are operated separately.
4
5> **NOTE**
6>
7> 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.
8>
9> The APIs of this module can be used only in the stage model.
10
11## Modules to Import
12
13```ts
14import { UIExtensionContentSession } from '@kit.AbilityKit';
15```
16
17## UIExtensionContentSession
18
19### loadContent
20
21loadContent(path: string, storage?: LocalStorage): void
22
23Loads content from a page associated with a local storage to the window corresponding to the current UIExtensionComponent.
24
25**System capability**: SystemCapability.Ability.AbilityRuntime.Core
26
27**Parameters**
28
29| Name | Type                                           | Mandatory| Description                                                        |
30| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
31| path    | string                                          | Yes  | Path of the page from which the content will be loaded.                                        |
32| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | No  | A storage unit, which provides storage for variable state properties and non-variable state properties of an application. This parameter is left blank by default.|
33
34**Error codes**
35
36For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
37
38| ID| Error Message|
39| ------- | -------------------------------- |
40| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
41| 16000050 | Internal error. |
42
43**Example**
44
45```ts
46// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
47import { UIExtensionContentSession, ShareExtensionAbility, Want } from '@kit.AbilityKit';
48
49export default class ShareExtAbility extends ShareExtensionAbility {
50  // ...
51
52  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
53    let storage: LocalStorage = new LocalStorage();
54    storage.setOrCreate('session', session);
55    session.loadContent('pages/Extension', storage);
56  }
57
58  // ...
59}
60```
61
62### loadContentByName<sup>18+</sup>
63
64loadContentByName(name: string, storage?: LocalStorage): void
65
66Loads a [named route](../../ui/arkts-routing.md#named-route) page for a [UIExtensionAbility](./js-apis-app-ability-uiExtensionAbility.md), with state properties passed to the page through [LocalStorage](../../ui/state-management/arkts-localstorage.md). This API is used to load a named route page in the [onSessionCreate](./js-apis-app-ability-uiExtensionAbility.md#onsessioncreate) lifecycle of the UIExtensionAbility.
67
68**System capability**: SystemCapability.Ability.AbilityRuntime.Core
69
70**Parameters**
71
72| Name| Type| Mandatory| Description|
73| ------ | ------ | ------ | ------ |
74| name | string | Yes| Name of the named route page.|
75| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | No| A page-level UI state storage unit, which is used to pass state properties to the page. The default value is null.|
76
77**Error codes**
78
79For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
80
81| ID| Error Message|
82| ------ | ------ |
83| 16000050 | Internal error. |
84
85**Example**
86
87Implementation of the UIExtensionAbility:
88```ts
89// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
90import { UIExtensionContentSession, ShareExtensionAbility, Want } from '@kit.AbilityKit';
91import { BusinessError } from '@kit.BasicServicesKit';
92import './pages/UIExtensionPage'; // Import the named route page. The ./pages/UIExtensionPage.ets file is used as an example in the sample code. Change the path and file name to the actual ones during your development.
93
94export default class ShareExtAbility extends ShareExtensionAbility {
95  // Other lifecycles and implementations
96
97  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
98    let storage: LocalStorage = new LocalStorage();
99    storage.setOrCreate('session', session);
100
101    let name: string = 'UIExtPage'; // Name of the named route page.
102    try {
103      session.loadContentByName(name, storage);
104    } catch (error) {
105      let code = (error as BusinessError).code;
106      let message = (error as BusinessError).message;
107      console.error(`Failed to load content by name ${name}, code: ${code}, msg: ${message}`);
108    }
109  }
110
111  // Other lifecycles and implementations
112}
113```
114
115Implementation of the named route page loaded by the UIExtensionAbility:
116```ts
117// Implementation of the ./pages/UIExtensionPage.ets file.
118import { UIExtensionContentSession } from '@kit.AbilityKit';
119
120@Entry ({routeName: 'UIExtPage'}) // Use routeName to define the name of the named route page.
121@Component
122struct UIExtensionPage {
123  @State message: string = 'Hello world';
124  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
125  private session: UIExtensionContentSession | undefined = this.storage?.get<UIExtensionContentSession>('session');
126
127  build() {
128    Row() {
129      Column() {
130        Text(this.message)
131          .fontSize(20)
132          .fontWeight(FontWeight.Bold)
133      }
134      .width('100%')
135    }
136    .height('100%')
137  }
138}
139```
140
141### terminateSelf
142
143terminateSelf(callback: AsyncCallback&lt;void&gt;): void
144
145Stops the window object corresponding to this UIExtensionContentSession instance. This API uses an asynchronous callback to return the result.
146
147**System capability**: SystemCapability.Ability.AbilityRuntime.Core
148
149**Parameters**
150
151| Name| Type| Mandatory| Description|
152| -------- | -------- | -------- | -------- |
153| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the window object is stopped, **err** is **undefined**; otherwise, **err** is an error object.|
154
155**Error codes**
156
157For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
158
159| ID| Error Message|
160| ------- | -------------------------------- |
161| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
162
163**Example**
164
165```ts
166import { UIExtensionContentSession } from '@kit.AbilityKit';
167import { BusinessError } from '@kit.BasicServicesKit';
168
169@Entry()
170@Component
171struct Index {
172  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
173  private session: UIExtensionContentSession | undefined =
174    this.storage?.get<UIExtensionContentSession>('session');
175
176  build() {
177    RelativeContainer() {
178      Button('TerminateSelf')
179        .onClick(() => {
180          this.session?.terminateSelf((err: BusinessError) => {
181            if (err) {
182              console.error(`Failed to terminate self, code: ${err.code}, msg: ${err.message}`);
183              return;
184            }
185            console.info(`Succeeded in terminating self.`);
186          });
187
188          this.storage?.clear();
189        })
190    }
191    .height('100%')
192    .width('100%')
193  }
194}
195```
196
197### terminateSelf
198
199terminateSelf(): Promise&lt;void&gt;
200
201Stops the window object corresponding to this UIExtensionContentSession instance. This API uses a promise to return the result.
202
203**System capability**: SystemCapability.Ability.AbilityRuntime.Core
204
205**Return value**
206
207| Type| Description|
208| -------- | -------- |
209| Promise&lt;void&gt; | Promise that returns no value.|
210
211**Example**
212
213```ts
214import { UIExtensionContentSession } from '@kit.AbilityKit';
215import { BusinessError } from '@kit.BasicServicesKit';
216
217@Entry()
218@Component
219struct Index {
220  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
221  private session: UIExtensionContentSession | undefined =
222    this.storage?.get<UIExtensionContentSession>('session');
223
224  build() {
225    RelativeContainer() {
226      Button('TerminateSelf')
227        .onClick(() => {
228          this.session?.terminateSelf()
229            .then(() => {
230              console.info(`Succeeded in terminating self.`);
231            })
232            .catch((err: BusinessError) => {
233              console.error(`Failed to terminate self, code: ${err.code}, msg: ${err.message}`);
234            });
235
236          this.storage?.clear();
237        })
238    }
239    .height('100%')
240    .width('100%')
241  }
242}
243```
244
245### terminateSelfWithResult
246
247terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void
248
249Stops the window object corresponding to this UIExtensionContentSession instance and returns the result to the UIExtensionComponent. This API uses an asynchronous callback to return the result.
250
251**System capability**: SystemCapability.Ability.AbilityRuntime.Core
252
253**Parameters**
254
255| Name| Type| Mandatory| Description|
256| -------- | -------- | -------- | -------- |
257| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.|
258| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the window object is stopped, **err** is **undefined**; otherwise, **err** is an error object.|
259
260**Error codes**
261
262For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
263
264| ID| Error Message|
265| ------- | -------------------------------- |
266| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
267
268**Example**
269
270```ts
271import { UIExtensionContentSession, common } from '@kit.AbilityKit';
272import { BusinessError } from '@kit.BasicServicesKit';
273
274@Entry()
275@Component
276struct Index {
277  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
278  private session: UIExtensionContentSession | undefined =
279    this.storage?.get<UIExtensionContentSession>('session');
280
281  build() {
282    RelativeContainer() {
283      Button('TerminateSelfWithResult')
284        .onClick(() => {
285          let abilityResult: common.AbilityResult = {
286            resultCode: 0,
287            want: {
288              bundleName: 'com.ohos.uiextensioncontentsession',
289              parameters: {
290                'result': 123456
291              }
292            }
293          };
294
295          this.session?.terminateSelfWithResult(abilityResult, (err: BusinessError) => {
296            if (err) {
297              console.error(`Failed to terminate self with result, code: ${err.code}, msg: ${err.message}`);
298              return;
299            }
300            console.info(`Succeeded in terminating self with result.`);
301          });
302
303          this.storage?.clear();
304        })
305    }
306    .height('100%')
307    .width('100%')
308  }
309}
310```
311
312### terminateSelfWithResult
313
314terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;
315
316Stops the window object corresponding to this UIExtensionContentSession instance and returns the result to the UIExtensionComponent. This API uses a promise to return the result.
317
318**System capability**: SystemCapability.Ability.AbilityRuntime.Core
319
320**Parameters**
321
322| Name| Type| Mandatory| Description|
323| -------- | -------- | -------- | -------- |
324| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.|
325
326**Return value**
327
328| Type| Description|
329| -------- | -------- |
330| Promise&lt;void&gt; | Promise that returns no value.|
331
332**Error codes**
333
334For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
335
336| ID| Error Message|
337| ------- | -------------------------------- |
338| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
339
340**Example**
341
342```ts
343import { UIExtensionContentSession, common } from '@kit.AbilityKit';
344import { BusinessError } from '@kit.BasicServicesKit';
345
346@Entry()
347@Component
348struct Index {
349  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
350  private session: UIExtensionContentSession | undefined =
351    this.storage?.get<UIExtensionContentSession>('session');
352
353  build() {
354    RelativeContainer() {
355      Button('TerminateSelfWithResult')
356        .onClick(() => {
357          let abilityResult: common.AbilityResult = {
358            resultCode: 0,
359            want: {
360              bundleName: 'com.ohos.uiextensioncontentsession',
361              parameters: {
362                'result': 123456
363              }
364            }
365          };
366
367          this.session?.terminateSelfWithResult(abilityResult)
368            .then(() => {
369              console.info(`Succeeded in terminating self with result.`);
370            })
371            .catch((err: BusinessError) => {
372              console.error(`Failed to terminate self with result, code: ${err.code}, msg: ${err.message}`);
373            });
374
375          this.storage?.clear();
376        })
377    }
378    .height('100%')
379    .width('100%')
380  }
381}
382```
383
384### setWindowPrivacyMode
385
386setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
387
388Sets whether the window is in privacy mode. A window in privacy mode cannot be captured or recorded. This API uses a promise to return the result.
389
390**System capability**: SystemCapability.Ability.AbilityRuntime.Core
391
392**Required permissions**: ohos.permission.PRIVACY_WINDOW
393
394**Parameters**
395
396| Name| Type| Mandatory| Description|
397| ------------- | ------- | -- | ----------------------------------------------------- |
398| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise.|
399
400**Return value**
401
402| Type| Description|
403| ------------------- | ------------------------ |
404| Promise&lt;void&gt; | Promise that returns no value.|
405
406**Error codes**
407
408For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
409
410| ID| Error Message|
411| ------- | -------------------------------- |
412| 201      | The application does not have permission to call the interface. |
413| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
414
415**Example**
416
417```ts
418// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
419import { UIExtensionContentSession, ShareExtensionAbility, Want } from '@kit.AbilityKit';
420import { BusinessError } from '@kit.BasicServicesKit';
421
422export default class ShareExtAbility extends ShareExtensionAbility {
423  // ...
424
425  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
426    let isPrivacyMode: boolean = true;
427    try {
428      session.setWindowPrivacyMode(isPrivacyMode)
429        .then(() => {
430          console.info(`Succeeded in setting window to privacy mode.`);
431        })
432        .catch((err: BusinessError) => {
433          console.error(`Failed to set window to privacy mode, code: ${err.code}, msg: ${err.message}`);
434        });
435    } catch (e) {
436      let code = (e as BusinessError).code;
437      let msg = (e as BusinessError).message;
438      console.error(`Failed to set window to privacy mode, code: ${code}, msg: ${msg}`);
439    }
440  }
441
442  // ...
443}
444```
445
446### setWindowPrivacyMode
447
448setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
449
450Sets whether the window is in privacy mode. A window in privacy mode cannot be captured or recorded. This API uses an asynchronous callback to return the result.
451
452**System capability**: SystemCapability.Ability.AbilityRuntime.Core
453
454**Required permissions**: ohos.permission.PRIVACY_WINDOW
455
456**Parameters**
457
458| Name| Type| Mandatory| Description|
459| ------------- | ------------------------- | -- | ------------------------------------------------------ |
460| isPrivacyMode | boolean                   | Yes| Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise. |
461| callback      | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
462
463**Error codes**
464
465For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
466
467| ID| Error Message|
468| ------- | -------------------------------- |
469| 201      | The application does not have permission to call the interface. |
470| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
471
472**Example**
473
474```ts
475// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
476import { UIExtensionContentSession, ShareExtensionAbility, Want } from '@kit.AbilityKit';
477import { BusinessError } from '@kit.BasicServicesKit';
478
479export default class ShareExtAbility extends ShareExtensionAbility {
480  // ...
481
482  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
483    let isPrivacyMode: boolean = true;
484    try {
485      session.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
486        if (err) {
487          console.error(`Failed to set window to privacy mode, code: ${err.code}, msg: ${err.message}`);
488          return;
489        }
490        console.info(`Succeeded in setting window to privacy mode.`);
491      });
492    } catch (e) {
493      let code = (e as BusinessError).code;
494      let msg = (e as BusinessError).message;
495      console.error(`Failed to set window to privacy mode, code: ${code}, msg: ${msg}`);
496    }
497  }
498
499  // ...
500}
501```
502
503### startAbilityByType<sup>11+</sup>
504
505startAbilityByType(type: string, wantParam: Record<string, Object>,
506    abilityStartCallback: AbilityStartCallback, callback: AsyncCallback\<void>): void
507
508Implicitly starts a given type of UIExtensionAbility. This API uses an asynchronous callback to return the result. It can be called only by applications running in the foreground.
509
510**System capability**: SystemCapability.Ability.AbilityRuntime.Core
511
512**Parameters**
513
514| Name| Type| Mandatory| Description|
515| -------- | -------- | -------- | -------- |
516| type | string | Yes| Type of the UIExtensionAbility to start.<!--Del--> For details, see [Starting an Application of the Specified Type](../../application-models/start-intent-panel.md#matching-rules).<!--DelEnd-->|
517| wantParam | Record<string, Object> | Yes| Extended parameter.|
518| abilityStartCallback | [AbilityStartCallback](js-apis-inner-application-abilityStartCallback.md) | Yes| Callback used to return the detailed error information if the startup fails.|
519| callback | AsyncCallback\<void> | Yes|Callback used to return the result. If the ability is started, **err** is **undefined**; otherwise, **err** is an error object.|
520
521**Error codes**
522
523For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
524
525| ID| Error Message|
526| ------- | -------------------------------- |
527| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
528| 16000050 | Internal error. |
529
530**Example**
531
532```ts
533// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
534import { UIExtensionContentSession, ShareExtensionAbility, Want, common } from '@kit.AbilityKit';
535import { BusinessError } from '@kit.BasicServicesKit';
536
537export default class ShareExtAbility extends ShareExtensionAbility {
538  // ...
539
540  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
541    let wantParams: Record<string, Object> = {
542      'sceneType': 1
543    };
544    let abilityStartCallback: common.AbilityStartCallback = {
545      onError: (code: number, name: string, message: string) => {
546        console.error(`onError, code: ${code}, name: ${name}, msg: ${message}`);
547      },
548      onResult: (result: common.AbilityResult) => {
549        console.info(`onResult, result: ${JSON.stringify(result)}`);
550      }
551    };
552
553    session.startAbilityByType('test', wantParams, abilityStartCallback, (err: BusinessError) => {
554      if (err) {
555        console.error(`Failed to startAbilityByType, code: ${err.code}, msg: ${err.message}`);
556        return;
557      }
558      console.info(`Succeeded in startAbilityByType`);
559    });
560  }
561
562  // ...
563}
564```
565
566### startAbilityByType<sup>11+</sup>
567
568startAbilityByType(type: string, wantParam: Record<string, Object>,
569    abilityStartCallback: AbilityStartCallback): Promise\<void>
570
571Implicitly starts a given type of UIExtensionAbility. This API uses a promise to return the result. It can be called only by applications running in the foreground.
572
573**System capability**: SystemCapability.Ability.AbilityRuntime.Core
574
575**Parameters**
576
577| Name| Type| Mandatory| Description|
578| -------- | -------- | -------- | -------- |
579| type | string | Yes| Type of the UIExtensionAbility to start.<!--Del--> For details, see [Starting an Application of the Specified Type](../../application-models/start-intent-panel.md#matching-rules).<!--DelEnd-->|
580| wantParam | Record<string, Object> | Yes| Extended parameter.|
581| abilityStartCallback | [AbilityStartCallback](js-apis-inner-application-abilityStartCallback.md) | Yes| Callback used to return the detailed error information if the startup fails.|
582
583**Return value**
584
585| Type| Description|
586| -------- | -------- |
587| Promise\<void> | Promise that returns no value.|
588
589**Error codes**
590
591For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
592
593| ID| Error Message|
594| ------- | -------------------------------- |
595| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
596| 16000050 | Internal error. |
597
598**Example**
599
600```ts
601// The UIExtensionAbility class does not allow direct inheritance by third-party applications. The child class ShareExtensionAbility is used here as an example.
602import { UIExtensionContentSession, ShareExtensionAbility, Want, common } from '@kit.AbilityKit';
603import { BusinessError } from '@kit.BasicServicesKit';
604
605export default class ShareExtAbility extends ShareExtensionAbility {
606  // ...
607
608  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
609    let wantParams: Record<string, Object> = {
610      'sceneType': 1
611    };
612    let abilityStartCallback: common.AbilityStartCallback = {
613      onError: (code: number, name: string, message: string) => {
614        console.error(`onError, code: ${code}, name: ${name}, msg: ${message}`);
615      },
616      onResult: (result: common.AbilityResult) => {
617        console.info(`onResult, result: ${JSON.stringify(result)}`);
618      }
619    };
620
621    session.startAbilityByType('test', wantParams, abilityStartCallback)
622      .then(() => {
623        console.info(`Succeeded in startAbilityByType`);
624      })
625      .catch((err: BusinessError) => {
626        console.error(`Failed to startAbilityByType, code: ${err.code}, msg: ${err.message}`);
627      });
628  }
629
630  // ...
631}
632```
633
634### getUIExtensionWindowProxy<sup>12+</sup>
635
636getUIExtensionWindowProxy(): uiExtension.WindowProxy
637
638Obtains the window proxy of this UIExtensionAbility.
639
640**System capability**: SystemCapability.Ability.AbilityRuntime.Core
641
642**Return value**
643
644| Type| Description|
645| -------- | -------- |
646| uiExtension.WindowProxy | Window proxy.|
647
648**Error codes**
649
650For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
651
652| ID| Error Message|
653| ------- | -------------------------------- |
654| 16000050 | Internal error. |
655
656**Example**
657
658```ts
659// Index.ets
660import { UIExtensionContentSession } from '@kit.AbilityKit';
661import uiExtension from '@ohos.arkui.uiExtension';
662
663@Entry()
664@Component
665struct Extension {
666  storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage();
667  @State message: string = 'EmbeddedUIExtensionAbility Index';
668  private session: UIExtensionContentSession | undefined = this.storage?.get<UIExtensionContentSession>('session');
669  private extensionWindow: uiExtension.WindowProxy | undefined = this.session?.getUIExtensionWindowProxy();
670
671  aboutToAppear(): void {
672    this.extensionWindow?.on('windowSizeChange', (size) => {
673      console.info(`size = ${JSON.stringify(size)}`);
674    });
675    this.extensionWindow?.on('avoidAreaChange', (info) => {
676      console.info(`type = ${JSON.stringify(info.type)}, area = ${JSON.stringify(info.area)}`);
677    });
678  }
679
680  aboutToDisappear(): void {
681    this.extensionWindow?.off('windowSizeChange');
682    this.extensionWindow?.off('avoidAreaChange');
683  }
684
685  build() {
686    Column() {
687      Text(this.message)
688        .fontSize(20)
689        .fontWeight(FontWeight.Bold)
690    }
691    .width('100%')
692  }
693}
694```
695