# @ohos.app.ability.UIExtensionContentSession (UI Operation Class for ExtensionAbilities with UI) **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. > **NOTE** > > 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. > The APIs of this module can be used only in the stage model. ## Modules to Import ```ts import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; ``` ## UIExtensionContentSession.sendData sendData(data: { [key: string]: Object }): void Sends data to the UIExtensionComponent. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System API**: This is a system API and cannot be called by third-party applications. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | data | {[key: string]: Object} | Yes| Data to send.| **Error codes** | ID| Error Message| | ------- | -------------------------------- | | 16000050 | Internal error. | For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). ## UIExtensionContentSession.setReceiveDataCallback setReceiveDataCallback(callback: (data: { [key: string]: Object }) => void): void Sets the callback used to receive data from the UIExtensionComponent. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System API**: This is a system API and cannot be called by third-party applications. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | (data: { [key: string]: Object }) => void | Yes| Callback used to receive data.| **Error codes** | ID| Error Message| | ------- | -------------------------------- | | 16000050 | Internal error. | For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). ## UIExtensionContentSession.loadContent loadContent(path: string, storage?: LocalStorage): Promise<void> Loads content from a page associated with a local storage to the window corresponding to the current UIExtensionComponent. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **Parameters** | Name | Type | Mandatory| Description | | ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Path of the page from which the content will be loaded. | | 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.| **Error codes** | ID| Error Message| | ------- | -------------------------------- | | 16000050 | Internal error. | For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). ## UIExtensionContentSession.terminateSelf terminateSelf(callback: AsyncCallback<void>): void; Stops the window object corresponding to this **UIExtensionContentSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | Yes| Callback used to return the result.| ## UIExtensionContentSession.terminateSelf terminateSelf(): Promise<void>; Stops the window object corresponding to this **UIExtensionContentSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| ## UIExtensionContentSession.terminateSelfWithResult terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; Stops 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. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.| ## UIExtensionContentSession.terminateSelfWithResult terminateSelfWithResult(parameter: AbilityResult): Promise<void>; Stops the window object corresponding to this **UIExtensionContentSession** instance and returns the result to the UIExtensionComponent. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes| Result returned to the UIExtensionComponent.| **Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| ## UIExtensionContentSession.setWindowBackgroundColor setWindowBackgroundColor(color: string): void Sets the background color for the loading page of the UIExtensionAbility. This API must be used after [loadContent()](#uiextensioncontentsessionloadcontent) takes effect. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System API**: This is a system API and cannot be called by third-party applications. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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**.| **Error codes** | ID| Error Message| | ------- | -------------------------------- | | 16000050 | Internal error. | For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). ## UIExtensionContentSession.setWindowPrivacyMode setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> Sets 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. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **Required permissions**: ohos.permission.PRIVACY_WINDOW **Parameters** | Name| Type| Mandatory| Description| | ------------- | ------- | -- | ----------------------------------------------------- | | 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.| **Return value** | Type| Description| | ------------------- | ------------------------ | | Promise<void> | Promise that returns no value.| ## UIExtensionContentSession.setWindowPrivacyMode setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void Sets 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. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **Required permissions**: ohos.permission.PRIVACY_WINDOW **Parameters** | Name| Type| Mandatory| Description| | ------------- | ------------------------- | -- | ------------------------------------------------------ | | 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. | | callback | AsyncCallback<void> | Yes| Callback used to return the result. |