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