1# @ohos.app.ability.UIExtensionContentSession (UI Operation Class for ExtensionAbilities with UI) 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> The APIs of this module can be used only in the stage model. 9 10## Modules to Import 11 12```ts 13import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 14``` 15 16## UIExtensionContentSession.sendData 17 18sendData(data: Record\<string, Object>): void 19 20Sends data to the UIExtensionComponent. 21 22**System capability**: SystemCapability.Ability.AbilityRuntime.Core 23 24**System API**: This is a system API and cannot be called by third-party applications. 25 26**Parameters** 27 28| Name| Type| Mandatory| Description| 29| -------- | -------- | -------- | -------- | 30| data | Record\<string, Object> | Yes| Data to send.| 31 32**Error codes** 33 34| ID| Error Message| 35| ------- | -------------------------------- | 36| 16000050 | Internal error. | 37 38For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 39 40## UIExtensionContentSession.setReceiveDataCallback 41 42setReceiveDataCallback(callback: (data: Record\<string, Object>) => void): void 43 44Sets a callback to receive data from the UIExtensionComponent. 45 46**System capability**: SystemCapability.Ability.AbilityRuntime.Core 47 48**System API**: This is a system API and cannot be called by third-party applications. 49 50**Parameters** 51 52| Name| Type| Mandatory| Description| 53| -------- | -------- | -------- | -------- | 54| callback | (data: Record\<string, Object>) => void | Yes| Callback used to receive data.| 55 56**Error codes** 57 58| ID| Error Message| 59| ------- | -------------------------------- | 60| 16000050 | Internal error. | 61 62For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 63 64## UIExtensionContentSession.setReceiveDataForResultCallback<sup>11+</sup> 65 66setReceiveDataForResultCallback(callback: (data: { [key: string]: Object }) => { [key: string]: Object }): void 67 68Sets a callback with a return value to receive data from the UIExtensionComponent. 69 70**System API**: This is a system API. 71 72**System capability**: SystemCapability.Ability.AbilityRuntime.Core 73 74 75**Parameters** 76 77| Name| Type| Mandatory| Description | 78| -------- | -------- | -------- |----------------| 79| callback | (data: { [key: string]: Object }) => { [key: string]: Object } | Yes| Callback with a return value used to receive data.| 80 81**Error codes** 82 83| ID| Error Message| 84| ------- | -------------------------------- | 85| 16000050 | Internal error. | 86 87For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 88 89## UIExtensionContentSession.loadContent 90 91loadContent(path: string, storage?: LocalStorage): void; 92 93Loads content from a page associated with a local storage to the window corresponding to the current UIExtensionComponent. 94 95**System capability**: SystemCapability.Ability.AbilityRuntime.Core 96 97**Parameters** 98 99| Name | Type | Mandatory| Description | 100| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 101| path | string | Yes | Path of the page from which the content will be loaded. | 102| storage | [LocalStorage](../../quick-start/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.| 103 104**Error codes** 105 106| ID| Error Message| 107| ------- | -------------------------------- | 108| 16000050 | Internal error. | 109 110For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 111 112## UIExtensionContentSession.startAbility 113 114startAbility(want: Want, callback: AsyncCallback<void>): void; 115 116Starts an ability. This API uses an asynchronous callback to return the result. 117 118Observe the following when using this API: 119 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 120 - 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. 121 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 122 - 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). 123 124**System capability**: SystemCapability.Ability.AbilityRuntime.Core 125 126**System API**: This is a system API and cannot be called by third-party applications. 127 128**Parameters** 129 130| Name| Type| Mandatory| Description| 131| -------- | -------- | -------- | -------- | 132| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 133| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 134 135**Error codes** 136 137| ID| Error Message| 138| ------- | -------------------------------- | 139| 16000001 | The specified ability does not exist. | 140| 16000002 | Incorrect ability type. | 141| 16000004 | Can not start invisible component. | 142| 16000005 | The specified process does not have the permission. | 143| 16000006 | Cross-user operations are not allowed. | 144| 16000008 | The crowdtesting application expires. | 145| 16000009 | An ability cannot be started or stopped in Wukong mode. | 146| 16000010 | The call with the continuation flag is forbidden. | 147| 16000011 | The context does not exist. | 148| 16000012 | The application is controlled. | 149| 16000013 | The application is controlled by EDM. | 150| 16000050 | Internal error. | 151| 16000053 | The ability is not on the top of the UI. | 152| 16000055 | Installation-free timed out. | 153| 16200001 | The caller has been released. | 154 155For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 156 157## UIExtensionContentSession.startAbility 158 159startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void; 160 161Starts an ability with **options** specified. This API uses an asynchronous callback to return the result. 162 163Observe the following when using this API: 164 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 165 - 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. 166 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 167 - 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). 168 169**System capability**: SystemCapability.Ability.AbilityRuntime.Core 170 171**System API**: This is a system API and cannot be called by third-party applications. 172 173**Parameters** 174 175| Name| Type| Mandatory| Description| 176| -------- | -------- | -------- | -------- | 177| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 178| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 179| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 180 181**Error codes** 182 183| ID| Error Message| 184| ------- | -------------------------------- | 185| 16000001 | The specified ability does not exist. | 186| 16000004 | Can not start invisible component. | 187| 16000005 | The specified process does not have the permission. | 188| 16000006 | Cross-user operations are not allowed. | 189| 16000008 | The crowdtesting application expires. | 190| 16000009 | An ability cannot be started or stopped in Wukong mode. | 191| 16000011 | The context does not exist. | 192| 16000012 | The application is controlled. | 193| 16000013 | The application is controlled by EDM. | 194| 16000050 | Internal error. | 195| 16000053 | The ability is not on the top of the UI. | 196| 16000055 | Installation-free timed out. | 197| 16200001 | The caller has been released. | 198 199For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 200 201## UIExtensionContentSession.startAbility 202 203startAbility(want: Want, options?: StartOptions): Promise<void>; 204 205Starts an ability. This API uses a promise to return the result. 206 207Observe the following when using this API: 208 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 209 - 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. 210 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 211 - 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). 212 213**System capability**: SystemCapability.Ability.AbilityRuntime.Core 214 215**System API**: This is a system API and cannot be called by third-party applications. 216 217**Parameters** 218 219| Name| Type| Mandatory| Description| 220| -------- | -------- | -------- | -------- | 221| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 222| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 223 224**Return value** 225 226| Type| Description| 227| -------- | -------- | 228| Promise<void> | Promise used to return the result.| 229 230**Error codes** 231 232| ID| Error Message| 233| ------- | -------------------------------- | 234| 16000001 | The specified ability does not exist. | 235| 16000002 | Incorrect ability type. | 236| 16000004 | Can not start invisible component. | 237| 16000005 | The specified process does not have the permission. | 238| 16000006 | Cross-user operations are not allowed. | 239| 16000008 | The crowdtesting application expires. | 240| 16000009 | An ability cannot be started or stopped in Wukong mode. | 241| 16000010 | The call with the continuation flag is forbidden. | 242| 16000011 | The context does not exist. | 243| 16000012 | The application is controlled. | 244| 16000013 | The application is controlled by EDM. | 245| 16000050 | Internal error. | 246| 16000053 | The ability is not on the top of the UI. | 247| 16000055 | Installation-free timed out. | 248| 16200001 | The caller has been released. | 249 250For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 251 252## UIExtensionContentSession.startAbilityForResult 253 254startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void; 255 256Starts an ability. This API uses an asynchronous callback to return the result to the caller after the ability is terminated. An ability can be terminated in the following ways: 257 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 258 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 259 - 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. 260 261Observe the following when using this API: 262 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 263 - 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. 264 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 265 - 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). 266 267**System capability**: SystemCapability.Ability.AbilityRuntime.Core 268 269**System API**: This is a system API and cannot be called by third-party applications. 270 271**Parameters** 272 273| Name| Type| Mandatory| Description| 274| -------- | -------- | -------- | -------- | 275| want |[Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 276| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes| Callback used to return the result.| 277 278**Error codes** 279 280| ID| Error Message| 281| ------- | -------------------------------- | 282| 16000001 | The specified ability does not exist. | 283| 16000002 | Incorrect ability type. | 284| 16000004 | Can not start invisible component. | 285| 16000005 | The specified process does not have the permission. | 286| 16000006 | Cross-user operations are not allowed. | 287| 16000008 | The crowdtesting application expires. | 288| 16000009 | An ability cannot be started or stopped in Wukong mode. | 289| 16000010 | The call with the continuation flag is forbidden. | 290| 16000011 | The context does not exist. | 291| 16000012 | The application is controlled. | 292| 16000013 | The application is controlled by EDM. | 293| 16000050 | Internal error. | 294| 16000053 | The ability is not on the top of the UI. | 295| 16000055 | Installation-free timed out. | 296| 16200001 | The caller has been released. | 297 298For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 299 300## UIExtensionContentSession.startAbilityForResult 301 302startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void; 303 304Starts an ability with **options** specified. This API uses an asynchronous callback to return the result to the caller after the ability is terminated. An ability can be terminated in the following ways: 305 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 306 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 307 - 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. 308 309Observe the following when using this API: 310 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 311 - 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. 312 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 313 - 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). 314 315**System capability**: SystemCapability.Ability.AbilityRuntime.Core 316 317**System API**: This is a system API and cannot be called by third-party applications. 318 319**Parameters** 320 321| Name| Type| Mandatory| Description| 322| -------- | -------- | -------- | -------- | 323| want |[Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 324| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 325| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes| Callback used to return the result.| 326 327**Error codes** 328 329| ID| Error Message| 330| ------- | -------------------------------- | 331| 16000001 | The specified ability does not exist. | 332| 16000004 | Can not start invisible component. | 333| 16000005 | The specified process does not have the permission. | 334| 16000006 | Cross-user operations are not allowed. | 335| 16000008 | The crowdtesting application expires. | 336| 16000009 | An ability cannot be started or stopped in Wukong mode. | 337| 16000011 | The context does not exist. | 338| 16000012 | The application is controlled. | 339| 16000013 | The application is controlled by EDM. | 340| 16000050 | Internal error. | 341| 16000053 | The ability is not on the top of the UI. | 342| 16000055 | Installation-free timed out. | 343| 16200001 | The caller has been released. | 344 345For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 346 347## UIExtensionContentSession.startAbilityForResult 348 349startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>; 350 351Starts an ability. This API uses a promise to return the result to the caller after the ability is terminated. An ability can be terminated in the following ways: 352 - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 353 - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 354 - 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. 355 356Observe the following when using this API: 357 - The application where the UIExtensionComponent is located must be running in the foreground and gain focus. 358 - 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. 359 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 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 362**System capability**: SystemCapability.Ability.AbilityRuntime.Core 363 364**System API**: This is a system API and cannot be called by third-party applications. 365 366**Parameters** 367 368| Name| Type| Mandatory| Description| 369| -------- | -------- | -------- | -------- | 370| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 371| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 372 373 374**Return value** 375 376| Type| Description| 377| -------- | -------- | 378| Promise<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.| 379 380**Error codes** 381 382| ID| Error Message| 383| ------- | -------------------------------- | 384| 16000001 | The specified ability does not exist. | 385| 16000002 | Incorrect ability type. | 386| 16000004 | Can not start invisible component. | 387| 16000005 | The specified process does not have the permission. | 388| 16000006 | Cross-user operations are not allowed. | 389| 16000008 | The crowdtesting application expires. | 390| 16000009 | An ability cannot be started or stopped in Wukong mode. | 391| 16000010 | The call with the continuation flag is forbidden. | 392| 16000011 | The context does not exist. | 393| 16000012 | The application is controlled. | 394| 16000013 | The application is controlled by EDM. | 395| 16000050 | Internal error. | 396| 16000053 | The ability is not on the top of the UI. | 397| 16000055 | Installation-free timed out. | 398| 16200001 | The caller has been released. | 399 400For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 401 402## UIExtensionContentSession.terminateSelf 403 404terminateSelf(callback: AsyncCallback<void>): void; 405 406Stops the window object corresponding to this **UIExtensionContentSession** instance. This API uses an asynchronous callback to return the result. 407 408**System capability**: SystemCapability.Ability.AbilityRuntime.Core 409 410**Parameters** 411 412| Name| Type| Mandatory| Description| 413| -------- | -------- | -------- | -------- | 414| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 415 416## UIExtensionContentSession.terminateSelf 417 418terminateSelf(): Promise<void>; 419 420Stops the window object corresponding to this **UIExtensionContentSession** instance. This API uses a promise to return the result. 421 422**System capability**: SystemCapability.Ability.AbilityRuntime.Core 423 424**Return value** 425 426| Type| Description| 427| -------- | -------- | 428| Promise<void> | Promise used to return the result.| 429 430## UIExtensionContentSession.terminateSelfWithResult 431 432terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; 433 434Stops 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. 435 436**System capability**: SystemCapability.Ability.AbilityRuntime.Core 437 438**Parameters** 439 440| Name| Type| Mandatory| Description| 441| -------- | -------- | -------- | -------- | 442| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.| 443| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 444 445## UIExtensionContentSession.terminateSelfWithResult 446 447terminateSelfWithResult(parameter: AbilityResult): Promise<void>; 448 449Stops the window object corresponding to this **UIExtensionContentSession** instance and returns the result to the UIExtensionComponent. This API uses a promise to return the result. 450 451**System capability**: SystemCapability.Ability.AbilityRuntime.Core 452 453**Parameters** 454 455| Name| Type| Mandatory| Description| 456| -------- | -------- | -------- | -------- | 457| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.| 458 459**Return value** 460 461| Type| Description| 462| -------- | -------- | 463| Promise<void> | Promise used to return the result.| 464 465## UIExtensionContentSession.setWindowBackgroundColor 466 467setWindowBackgroundColor(color: string): void 468 469Sets the background color for the loading page of the UIExtensionAbility. This API must be used after [loadContent()](#uiextensioncontentsessionloadcontent) takes effect. 470 471**System capability**: SystemCapability.Ability.AbilityRuntime.Core 472 473**System API**: This is a system API and cannot be called by third-party applications. 474 475**Parameters** 476 477| Name| Type| Mandatory| Description| 478| -------- | -------- | -------- | -------- | 479| 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**.| 480 481**Error codes** 482 483| ID| Error Message| 484| ------- | -------------------------------- | 485| 16000050 | Internal error. | 486 487For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 488 489## UIExtensionContentSession.setWindowPrivacyMode 490 491setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 492 493Sets whether the window is in privacy mode. This API uses a promise to return the result. A window in privacy mode cannot be captured or recorded. 494 495**System capability**: SystemCapability.Ability.AbilityRuntime.Core 496 497**Required permissions**: ohos.permission.PRIVACY_WINDOW 498 499**Parameters** 500 501| Name| Type| Mandatory| Description| 502| ------------- | ------- | -- | ----------------------------------------------------- | 503| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite.| 504 505**Return value** 506 507| Type| Description| 508| ------------------- | ------------------------ | 509| Promise<void> | Promise that returns no value.| 510 511## UIExtensionContentSession.setWindowPrivacyMode 512 513setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 514 515Sets whether the window is in privacy mode. This API uses an asynchronous callback to return the result. A window in privacy mode cannot be captured or recorded. 516 517**System capability**: SystemCapability.Ability.AbilityRuntime.Core 518 519**Required permissions**: ohos.permission.PRIVACY_WINDOW 520 521**Parameters** 522 523| Name| Type| Mandatory| Description| 524| ------------- | ------------------------- | -- | ------------------------------------------------------ | 525| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite. | 526| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 527 528## UIExtensionContentSession.startAbilityByType<sup>11+</sup> 529 530startAbilityByType(type: string, wantParam: Record<string, Object>, 531 abilityStartCallback: AbilityStartCallback, callback: AsyncCallback\<void>): void; 532 533Implicitly starts a given type of UIExtensionAbility. This API uses an asynchronous callback to return the result. 534 535**System capability**: SystemCapability.Ability.AbilityRuntime.Core 536 537**Parameters** 538 539| Name| Type| Mandatory| Description| 540| -------- | -------- | -------- | -------- | 541| type | string | Yes| Type of the UIExtensionAbility to start.| 542| wantParam | {[key: string]: any} | Yes| Extended parameter.| 543| abilityStartCallback | [AbilityStartCallback](js-apis-inner-application-abilityStartCallback.md) | Yes| Callback to be invoked when the startup fails.| 544| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 545 546**Error codes** 547 548| ID| Error Message| 549| ------- | -------------------------------- | 550| 16000001 | The specified ability does not exist. | 551| 16000002 | Incorrect ability type. | 552| 16000004 | Can not start invisible component. | 553| 16000050 | Internal error. | 554| 16200001 | The caller has been released. | 555 556For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 557 558## UIExtensionContentSession.startAbilityByType<sup>11+</sup> 559 560startAbilityByType(type: string, wantParam: Record<string, Object>, 561 abilityStartCallback: AbilityStartCallback): Promise\<void>; 562 563Implicitly starts a given type of UIExtensionAbility. This API uses a promise to return the result. 564 565**System capability**: SystemCapability.Ability.AbilityRuntime.Core 566 567**Parameters** 568 569| Name| Type| Mandatory| Description| 570| -------- | -------- | -------- | -------- | 571| type | string | Yes| Type of the UIExtensionAbility to start.| 572| wantParam | {[key: string]: Object} | Yes| Extended parameter.| 573| abilityStartCallback | [AbilityStartCallback](js-apis-inner-application-abilityStartCallback.md) | Yes| Callback to be invoked when the startup fails.| 574 575**Return value** 576 577| Type| Description| 578| -------- | -------- | 579| Promise\<void> | Promise that returns no value.| 580 581**Error codes** 582 583| ID| Error Message| 584| ------- | -------------------------------- | 585| 16000001 | The specified ability does not exist. | 586| 16000002 | Incorrect ability type. | 587| 16000004 | Can not start invisible component. | 588| 16000050 | Internal error. | 589| 16200001 | The caller has been released. | 590 591For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 592 593## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 594 595startAbilityAsCaller(want: Want, callback: AsyncCallback\<void>): void 596 597Starts an ability as the caller. This API uses an asynchronous callback to return the result. 598 599The 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. 600 601**System API**: This is a system API. 602 603**System capability**: SystemCapability.Ability.AbilityRuntime.Core 604 605**Parameters** 606 607| Name| Type| Mandatory| Description| 608| -------- | -------- | -------- | -------- | 609| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 610| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 611 612 613**Error codes** 614 615| ID| Error Message| 616| ------- | -------------------------------- | 617| 16000001 | The specified ability does not exist. | 618| 16000002 | Incorrect ability type. | 619| 16000004 | Can not start invisible component. | 620| 16000005 | The specified process does not have the permission. | 621| 16000006 | Cross-user operations are not allowed. | 622| 16000008 | The crowdtesting application expires. | 623| 16000009 | An ability cannot be started or stopped in Wukong mode. | 624| 16000010 | The call with the continuation flag is forbidden. | 625| 16000011 | The context does not exist. | 626| 16000012 | The application is controlled. | 627| 16000013 | The application is controlled by EDM. | 628| 16000050 | Internal error. | 629| 16000053 | The ability is not on the top of the UI. | 630| 16000055 | Installation-free timed out. | 631| 16200001 | The caller has been released. | 632 633For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 634 635## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 636 637startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void 638 639Starts an ability as the caller, with **options** specified. This API uses an asynchronous callback to return the result. 640 641The 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. 642 643**System API**: This is a system API. 644 645**System capability**: SystemCapability.Ability.AbilityRuntime.Core 646 647**Parameters** 648 649| Name| Type| Mandatory| Description| 650| -------- | -------- | -------- | -------- | 651| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 652| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 653| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 654 655 656**Error codes** 657 658| ID| Error Message| 659| ------- | -------------------------------- | 660| 16000001 | The specified ability does not exist. | 661| 16000004 | Can not start invisible component. | 662| 16000005 | The specified process does not have the permission. | 663| 16000006 | Cross-user operations are not allowed. | 664| 16000008 | The crowdtesting application expires. | 665| 16000009 | An ability cannot be started or stopped in Wukong mode. | 666| 16000011 | The context does not exist. | 667| 16000012 | The application is controlled. | 668| 16000013 | The application is controlled by EDM. | 669| 16000050 | Internal error. | 670| 16000053 | The ability is not on the top of the UI. | 671| 16000055 | Installation-free timed out. | 672| 16200001 | The caller has been released. | 673 674For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 675 676## UIExtensionContentSession.startAbilityAsCaller<sup>11+</sup> 677 678startAbilityAsCaller(want: Want, options?: StartOptions): Promise\<void> 679 680Starts an ability as the caller. This API uses a promise to return the result. 681 682The 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. 683 684**System API**: This is a system API. 685 686**System capability**: SystemCapability.Ability.AbilityRuntime.Core 687 688**Parameters** 689 690| Name| Type| Mandatory| Description| 691| -------- | -------- | -------- | -------- | 692| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 693| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 694 695**Return value** 696 697| Type| Description| 698| -------- | -------- | 699| Promise\<void> | Promise that returns no value.| 700 701**Error codes** 702 703| ID| Error Message| 704| ------- | -------------------------------- | 705| 16000001 | The specified ability does not exist. | 706| 16000002 | Incorrect ability type. | 707| 16000004 | Can not start invisible component. | 708| 16000005 | The specified process does not have the permission. | 709| 16000006 | Cross-user operations are not allowed. | 710| 16000008 | The crowdtesting application expires. | 711| 16000009 | An ability cannot be started or stopped in Wukong mode. | 712| 16000010 | The call with the continuation flag is forbidden. | 713| 16000011 | The context does not exist. | 714| 16000012 | The application is controlled. | 715| 16000013 | The application is controlled by EDM. | 716| 16000050 | Internal error. | 717| 16000053 | The ability is not on the top of the UI. | 718| 16000055 | Installation-free timed out. | 719| 16200001 | The caller has been released. | 720 721For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 722