1# @ohos.app.ability.UIExtensionContentSession (UI Operation Class for ExtensionAbilities with UI) (System API) 2 3**UIExtensionContentSession** 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#uiextensionabilityonsessioncreate) 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> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.ability.UIExtensionContentSession (UI Operation Class for ExtensionAbilities with UI)](js-apis-app-ability-uiExtensionContentSession.md). 12 13## Modules to Import 14 15```ts 16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17``` 18 19## UIExtensionContentSession.sendData 20 21sendData(data: Record\<string, Object>): void 22 23Sends data to the UIExtensionComponent. 24 25**System capability**: SystemCapability.Ability.AbilityRuntime.Core 26 27**System API**: This is a system API. 28 29**Parameters** 30 31| Name| Type| Mandatory| Description| 32| -------- | -------- | -------- | -------- | 33| data | Record\<string, Object> | Yes| Data to send.| 34 35**Error codes** 36 37| ID| Error Message| 38| ------- | -------------------------------- | 39| 16000050 | Internal error. | 40 41For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 42 43## UIExtensionContentSession.setReceiveDataCallback 44 45setReceiveDataCallback(callback: (data: Record\<string, Object>) => void): void 46 47Sets a callback to receive data from the UIExtensionComponent. This API uses an asynchronous callback to return the result. 48 49**System capability**: SystemCapability.Ability.AbilityRuntime.Core 50 51**System API**: This is a system API. 52 53**Parameters** 54 55| Name| Type| Mandatory| Description| 56| -------- | -------- | -------- | -------- | 57| callback | (data: Record\<string, Object>) => void | Yes| Callback used to return the received data.| 58 59**Error codes** 60 61| ID| Error Message| 62| ------- | -------------------------------- | 63| 16000050 | Internal error. | 64 65For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 66 67## UIExtensionContentSession.setReceiveDataForResultCallback<sup>11+</sup> 68 69setReceiveDataForResultCallback(callback: (data: Record<string, Object>) => Record<string, Object>): void 70 71Sets a callback with a return value to receive data from the UIExtensionComponent. This API uses an asynchronous callback to return the result. 72 73**System API**: This is a system API. 74 75**System capability**: SystemCapability.Ability.AbilityRuntime.Core 76 77 78**Parameters** 79 80| Name| Type| Mandatory| Description | 81| -------- | -------- | -------- |----------------| 82| callback | (data: { [key: string]: Object }) => { [key: string]: Object } | Yes| Callback used to return the received data with a return value.| 83 84**Error codes** 85 86| ID| Error Message| 87| ------- | -------------------------------- | 88| 16000050 | Internal error. | 89 90For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 91 92## UIExtensionContentSession.startAbility 93 94startAbility(want: Want, callback: AsyncCallback<void>): void 95 96Starts an ability. This API uses an asynchronous callback to return the result. 97 98Observe the following when using this API: 99 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 100 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 101 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 102 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 103 104**System capability**: SystemCapability.Ability.AbilityRuntime.Core 105 106**System API**: This is a system API. 107 108**Parameters** 109 110| Name| Type| Mandatory| Description| 111| -------- | -------- | -------- | -------- | 112| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 113| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**; otherwise, **err** is an error object.| 114 115**Error codes** 116 117| ID| Error Message| 118| ------- | -------------------------------- | 119| 16000001 | The specified ability does not exist. | 120| 16000002 | Incorrect ability type. | 121| 16000004 | Can not start invisible component. | 122| 16000005 | The specified process does not have the permission. | 123| 16000006 | Cross-user operations are not allowed. | 124| 16000008 | The crowdtesting application expires. | 125| 16000009 | An ability cannot be started or stopped in Wukong mode. | 126| 16000010 | The call with the continuation flag is forbidden. | 127| 16000011 | The context does not exist. | 128| 16000012 | The application is controlled. | 129| 16000013 | The application is controlled by EDM. | 130| 16000050 | Internal error. | 131| 16000053 | The ability is not on the top of the UI. | 132| 16000055 | Installation-free timed out. | 133| 16200001 | The caller has been released. | 134 135For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 136 137## UIExtensionContentSession.startAbility 138 139startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void 140 141Starts an ability with **options** specified. This API uses an asynchronous callback to return the result. 142 143Observe the following when using this API: 144 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 145 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 146 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 147 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 148 149**System capability**: SystemCapability.Ability.AbilityRuntime.Core 150 151**System API**: This is a system API. 152 153**Parameters** 154 155| Name| Type| Mandatory| Description| 156| -------- | -------- | -------- | -------- | 157| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 158| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 159| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**; otherwise, **err** is an error object.| 160 161**Error codes** 162 163| ID| Error Message| 164| ------- | -------------------------------- | 165| 16000001 | The specified ability does not exist. | 166| 16000004 | Can not start invisible component. | 167| 16000005 | The specified process does not have the permission. | 168| 16000006 | Cross-user operations are not allowed. | 169| 16000008 | The crowdtesting application expires. | 170| 16000009 | An ability cannot be started or stopped in Wukong mode. | 171| 16000011 | The context does not exist. | 172| 16000012 | The application is controlled. | 173| 16000013 | The application is controlled by EDM. | 174| 16000050 | Internal error. | 175| 16000053 | The ability is not on the top of the UI. | 176| 16000055 | Installation-free timed out. | 177| 16200001 | The caller has been released. | 178 179For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 180 181## UIExtensionContentSession.startAbility 182 183startAbility(want: Want, options?: StartOptions): Promise<void> 184 185Starts an ability. This API uses a promise to return the result. 186 187Observe the following when using this API: 188 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 189 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 190 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 191 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 192 193**System capability**: SystemCapability.Ability.AbilityRuntime.Core 194 195**System API**: This is a system API. 196 197**Parameters** 198 199| Name| Type| Mandatory| Description| 200| -------- | -------- | -------- | -------- | 201| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 202| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 203 204**Return value** 205 206| Type| Description| 207| -------- | -------- | 208| Promise<void> | Promise that returns no value.| 209 210**Error codes** 211 212| ID| Error Message| 213| ------- | -------------------------------- | 214| 16000001 | The specified ability does not exist. | 215| 16000002 | Incorrect ability type. | 216| 16000004 | Can not start invisible component. | 217| 16000005 | The specified process does not have the permission. | 218| 16000006 | Cross-user operations are not allowed. | 219| 16000008 | The crowdtesting application expires. | 220| 16000009 | An ability cannot be started or stopped in Wukong mode. | 221| 16000010 | The call with the continuation flag is forbidden. | 222| 16000011 | The context does not exist. | 223| 16000012 | The application is controlled. | 224| 16000013 | The application is controlled by EDM. | 225| 16000050 | Internal error. | 226| 16000053 | The ability is not on the top of the UI. | 227| 16000055 | Installation-free timed out. | 228| 16200001 | The caller has been released. | 229 230For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 231 232## UIExtensionContentSession.startAbilityForResult 233 234startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void 235 236Starts an ability and returns the result to the caller after the ability is terminated. This API uses an asynchronous callback to return the result. 237 238An ability can be terminated in the following ways: 239 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 240 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 241 - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others. 242 243Observe the following when using this API: 244 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 245 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 246 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 247 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 248 249**System capability**: SystemCapability.Ability.AbilityRuntime.Core 250 251**System API**: This is a system API. 252 253**Parameters** 254 255| Name| Type| Mandatory| Description| 256| -------- | -------- | -------- | -------- | 257| want |[Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 258| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes| Callback used to return the result. If the ability is started and terminated, **err** is **undefined** and **data** is the obtained result code and data; otherwise, **err** is an error object.| 259 260**Error codes** 261 262| ID| Error Message| 263| ------- | -------------------------------- | 264| 16000001 | The specified ability does not exist. | 265| 16000002 | Incorrect ability type. | 266| 16000004 | Can not start invisible component. | 267| 16000005 | The specified process does not have the permission. | 268| 16000006 | Cross-user operations are not allowed. | 269| 16000008 | The crowdtesting application expires. | 270| 16000009 | An ability cannot be started or stopped in Wukong mode. | 271| 16000010 | The call with the continuation flag is forbidden. | 272| 16000011 | The context does not exist. | 273| 16000012 | The application is controlled. | 274| 16000013 | The application is controlled by EDM. | 275| 16000050 | Internal error. | 276| 16000053 | The ability is not on the top of the UI. | 277| 16000055 | Installation-free timed out. | 278| 16200001 | The caller has been released. | 279 280For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 281 282## UIExtensionContentSession.startAbilityForResult 283 284startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void 285 286Starts an ability with **options** specified and returns the result to the caller after the ability is terminated. This API uses an asynchronous callback to return the result. 287 288An ability can be terminated in the following ways: 289 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 290 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 291 - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others. 292 293Observe the following when using this API: 294 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 295 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 296 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 297 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 298 299**System capability**: SystemCapability.Ability.AbilityRuntime.Core 300 301**System API**: This is a system API. 302 303**Parameters** 304 305| Name| Type| Mandatory| Description| 306| -------- | -------- | -------- | -------- | 307| want |[Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 308| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 309| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes| Callback used to return the result. If the ability is started and terminated, **err** is **undefined** and **data** is the obtained result code and data; otherwise, **err** is an error object.| 310 311**Error codes** 312 313| ID| Error Message| 314| ------- | -------------------------------- | 315| 16000001 | The specified ability does not exist. | 316| 16000004 | Can not start invisible component. | 317| 16000005 | The specified process does not have the permission. | 318| 16000006 | Cross-user operations are not allowed. | 319| 16000008 | The crowdtesting application expires. | 320| 16000009 | An ability cannot be started or stopped in Wukong mode. | 321| 16000011 | The context does not exist. | 322| 16000012 | The application is controlled. | 323| 16000013 | The application is controlled by EDM. | 324| 16000050 | Internal error. | 325| 16000053 | The ability is not on the top of the UI. | 326| 16000055 | Installation-free timed out. | 327| 16200001 | The caller has been released. | 328 329For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 330 331## UIExtensionContentSession.startAbilityForResult 332 333startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult> 334 335Starts an ability and returns the result to the caller after the ability is terminated. This API uses a promise to return the result. 336 337An ability can be terminated in the following ways: 338 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 339 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 340 - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others. 341 342Observe the following when using this API: 343 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 344 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 345 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 346 - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 347 348**System capability**: SystemCapability.Ability.AbilityRuntime.Core 349 350**System API**: This is a system API. 351 352**Parameters** 353 354| Name| Type| Mandatory| Description| 355| -------- | -------- | -------- | -------- | 356| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 357| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 358 359 360**Return value** 361 362| Type| Description| 363| -------- | -------- | 364| Promise<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result code and data.| 365 366**Error codes** 367 368| ID| Error Message| 369| ------- | -------------------------------- | 370| 16000001 | The specified ability does not exist. | 371| 16000002 | Incorrect ability type. | 372| 16000004 | Can not start invisible component. | 373| 16000005 | The specified process does not have the permission. | 374| 16000006 | Cross-user operations are not allowed. | 375| 16000008 | The crowdtesting application expires. | 376| 16000009 | An ability cannot be started or stopped in Wukong mode. | 377| 16000010 | The call with the continuation flag is forbidden. | 378| 16000011 | The context does not exist. | 379| 16000012 | The application is controlled. | 380| 16000013 | The application is controlled by EDM. | 381| 16000050 | Internal error. | 382| 16000053 | The ability is not on the top of the UI. | 383| 16000055 | Installation-free timed out. | 384| 16200001 | The caller has been released. | 385 386For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 387 388## UIExtensionContentSession.setWindowBackgroundColor 389 390setWindowBackgroundColor(color: string): void 391 392Sets the background color for the loading page of the UIExtensionAbility. This API can be used only after [loadContent()](js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent) is called and takes effect. 393 394**System capability**: SystemCapability.Ability.AbilityRuntime.Core 395 396**System API**: This is a system API. 397 398**Parameters** 399 400| Name| Type| Mandatory| Description| 401| -------- | -------- | -------- | -------- | 402| color | string | Yes| Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**.| 403 404**Error codes** 405 406| ID| Error Message| 407| ------- | -------------------------------- | 408| 16000050 | Internal error. | 409 410For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 411 412## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 413 414startAbilityAsCaller(want: Want, callback: AsyncCallback\<void>): void 415 416Starts an ability as the caller. The initial ability places its caller information (such as the bundle name and ability name) in the **want** parameter and transfers the information to an **ExtensionAbility** at the middle layer. When the ExtensionAbility starts another ability by calling this API, the started ability can obtain the caller information of the initial ability from the **onCreate** lifecycle. This API uses an asynchronous callback to return the result. 417 418**System API**: This is a system API. 419 420**System capability**: SystemCapability.Ability.AbilityRuntime.Core 421 422**Parameters** 423 424| Name| Type| Mandatory| Description| 425| -------- | -------- | -------- | -------- | 426| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 427| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 428 429 430**Error codes** 431 432| ID| Error Message| 433| ------- | -------------------------------- | 434| 16000001 | The specified ability does not exist. | 435| 16000002 | Incorrect ability type. | 436| 16000004 | Can not start invisible component. | 437| 16000005 | The specified process does not have the permission. | 438| 16000006 | Cross-user operations are not allowed. | 439| 16000008 | The crowdtesting application expires. | 440| 16000009 | An ability cannot be started or stopped in Wukong mode. | 441| 16000010 | The call with the continuation flag is forbidden. | 442| 16000011 | The context does not exist. | 443| 16000012 | The application is controlled. | 444| 16000013 | The application is controlled by EDM. | 445| 16000050 | Internal error. | 446| 16000053 | The ability is not on the top of the UI. | 447| 16000055 | Installation-free timed out. | 448| 16200001 | The caller has been released. | 449 450For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 451 452## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 453 454startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void 455 456Starts an ability as the caller, with **options** specified. The initial ability places its caller information (such as the bundle name and ability name) in the **want** parameter and transfers the information to an **ExtensionAbility** at the middle layer. When the ExtensionAbility starts another ability by calling this API, the started ability can obtain the caller information of the initial ability from the **onCreate** lifecycle. This API uses an asynchronous callback to return the result. 457 458**System API**: This is a system API. 459 460**System capability**: SystemCapability.Ability.AbilityRuntime.Core 461 462**Parameters** 463 464| Name| Type| Mandatory| Description| 465| -------- | -------- | -------- | -------- | 466| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 467| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 468| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 469 470 471**Error codes** 472 473| ID| Error Message| 474| ------- | -------------------------------- | 475| 16000001 | The specified ability does not exist. | 476| 16000004 | Can not start invisible component. | 477| 16000005 | The specified process does not have the permission. | 478| 16000006 | Cross-user operations are not allowed. | 479| 16000008 | The crowdtesting application expires. | 480| 16000009 | An ability cannot be started or stopped in Wukong mode. | 481| 16000011 | The context does not exist. | 482| 16000012 | The application is controlled. | 483| 16000013 | The application is controlled by EDM. | 484| 16000050 | Internal error. | 485| 16000053 | The ability is not on the top of the UI. | 486| 16000055 | Installation-free timed out. | 487| 16200001 | The caller has been released. | 488 489For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 490 491## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 492 493startAbilityAsCaller(want: Want, options?: StartOptions): Promise\<void> 494 495Starts an ability as the caller. The initial ability places its caller information (such as the bundle name and ability name) in the **want** parameter and transfers the information to an **ExtensionAbility** at the middle layer. When the ExtensionAbility starts another ability by calling this API, the started ability can obtain the caller information of the initial ability from the **onCreate** lifecycle. This API uses a promise to return the result. 496 497**System API**: This is a system API. 498 499**System capability**: SystemCapability.Ability.AbilityRuntime.Core 500 501**Parameters** 502 503| Name| Type| Mandatory| Description| 504| -------- | -------- | -------- | -------- | 505| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 506| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 507 508**Return value** 509 510| Type| Description| 511| -------- | -------- | 512| Promise\<void> | Promise that returns no value.| 513 514**Error codes** 515 516| ID| Error Message| 517| ------- | -------------------------------- | 518| 16000001 | The specified ability does not exist. | 519| 16000002 | Incorrect ability type. | 520| 16000004 | Can not start invisible component. | 521| 16000005 | The specified process does not have the permission. | 522| 16000006 | Cross-user operations are not allowed. | 523| 16000008 | The crowdtesting application expires. | 524| 16000009 | An ability cannot be started or stopped in Wukong mode. | 525| 16000010 | The call with the continuation flag is forbidden. | 526| 16000011 | The context does not exist. | 527| 16000012 | The application is controlled. | 528| 16000013 | The application is controlled by EDM. | 529| 16000050 | Internal error. | 530| 16000053 | The ability is not on the top of the UI. | 531| 16000055 | Installation-free timed out. | 532| 16200001 | The caller has been released. | 533 534For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 535 536## UIExtensionContentSession.getUIExtensionHostWindowProxy<sup>11+</sup> 537 538getUIExtensionHostWindowProxy(): uiExtensionHost.UIExtensionHostWindowProxy 539 540Obtains the window object corresponding to the current UIExtension to notify the width, height, position, and avoided area. 541 542**System API**: This is a system API. 543 544**System capability**: SystemCapability.Ability.AbilityRuntime.Core 545 546**Return value** 547 548| Type| Description| 549| -------- | -------- | 550| uiExtensionHost.UIExtensionHostWindowProxy | Window object.| 551 552**Error codes** 553 554| ID| Error Message| 555| ------- | -------------------------------- | 556| 16000050 | Internal error. | 557 558**Example** 559 560```ts 561import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility' 562import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession' 563import Want from '@ohos.app.ability.Want'; 564import uiExtensionHost from '@ohos.uiExtensionHost'; 565 566const TAG: string = '[UIExtAbility]' 567export default class UIExtAbility extends UIExtensionAbility { 568 569 onCreate() { 570 console.log(TAG, `UIExtAbility onCreate`) 571 } 572 573 onForeground() { 574 console.log(TAG, `UIExtAbility onForeground`) 575 } 576 577 onBackground() { 578 console.log(TAG, `UIExtAbility onBackground`) 579 } 580 581 onDestroy() { 582 console.log(TAG, `UIExtAbility onDestroy`) 583 } 584 585 onSessionCreate(want: Want, session: UIExtensionContentSession) { 586 let extensionHostWindow = session.getUIExtensionHostWindowProxy(); 587 let data: Record<string, UIExtensionContentSession | uiExtensionHost.UIExtensionHostWindowProxy> = { 588 'session': session, 589 'extensionHostWindow': extensionHostWindow 590 } 591 let storage: LocalStorage = new LocalStorage(data); 592 session.loadContent('pages/extension', storage); 593 } 594 595 onSessionDestroy(session: UIExtensionContentSession) { 596 console.log(TAG, `UIExtAbility onSessionDestroy`) 597 } 598} 599``` 600For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 601