From df05df202ccd6df4bec710fceffaec46b891fa55 Mon Sep 17 00:00:00 2001 From: Gloria Date: Tue, 4 Jul 2023 08:59:34 +0800 Subject: [PATCH] Update docs against 19911+19916+19922+19830+19791+19921 Signed-off-by: wusongqing --- .../explicit-implicit-want-mappings.md | 13 +- .../serviceextensionability.md | 7 +- .../apis/js-apis-bundleManager-bundleInfo.md | 1 + .../reference/errorcodes/errorcode-bundle.md | 26 +- .../windowmanager/application-window-stage.md | 550 +++++++++--------- 5 files changed, 295 insertions(+), 302 deletions(-) diff --git a/en/application-dev/application-models/explicit-implicit-want-mappings.md b/en/application-dev/application-models/explicit-implicit-want-mappings.md index 454fc89d71..32482e090b 100644 --- a/en/application-dev/application-models/explicit-implicit-want-mappings.md +++ b/en/application-dev/application-models/explicit-implicit-want-mappings.md @@ -63,8 +63,7 @@ The system matches the **action** attribute in the **want** parameter passed by - If **action** in the passed **want** parameter is specified, and **actions** under **skills** of an application component is specified but does not contain **action** in the passed **want** parameter, the matching fails. **Figure 1** Matching rules of action in the want parameter - - ![want-action](figures/want-action.png) +![want-action](figures/want-action.png) ### Matching Rules of entities in the want Parameter @@ -82,8 +81,7 @@ The system matches the **entities** attribute in the **want** parameter passed b - If **entities** in the passed **want** parameter is specified, and **entities** under **skills** of an application component is specified but does not contain **entities** in the passed **want** parameter, the matching fails. **Figure 2** Matching rules of entities in the want parameter - - ![want-entities](figures/want-entities.png) +![want-entities](figures/want-entities.png) ### Matching Rules of uri and type in the want Parameter @@ -100,6 +98,7 @@ There are four combinations of **uri** and **type** settings. The matching rules - Only **uri** is specified in the **want** parameter. - If the **uris** array under **skills** of an application component is unspecified, the matching fails. - If the **uris** array under **skills** of an application component contains an element whose [uri is matched](#matching-rules-of-uri) and **type** is unspecified, the matching is successful. Otherwise, the matching fails. + - If the matching fails for the preceding two scenarios and the input URI is a file path URI, the system obtains the MIME type of the file based on the file name extension. If the MIME type matches **type** configured under **skills**, the matching is successful. - Only **type** is specified in the **want** parameter. - If the **uris** array under **skills** of an application component is unspecified, the matching fails. @@ -112,8 +111,7 @@ There are four combinations of **uri** and **type** settings. The matching rules Leftmost URI matching: When only **scheme**, a combination of **scheme** and **host**, or a combination of **scheme**, **host**, and **port** is configured in the **uris** array under **skills** of the application component, the matching is successful only if the leftmost URI in the passed **want** parameter matches **scheme**, the combination of **scheme** and **host**, or the combination of **scheme**, **host**, and **port**. **Figure 3** Matching rules when uri and type are specified in the want parameter - -![want-uri-type1](figures/want-uri-type1.png) +![want-uri-type1](figures/want-uri-type1.png) To simplify the description: @@ -121,8 +119,7 @@ To simplify the description: - **type** in the **want** parameter passed in by the caller is called **w_type**; the type in the **uris** array under **skills** of the application component to match is called **s_type**. **Figure 4** Matching rules of uri and type in the want parameter - -![want-uri-type2](figures/want-uri-type2.png) +![want-uri-type2](figures/want-uri-type2.png) ### Matching Rules of uri diff --git a/en/application-dev/application-models/serviceextensionability.md b/en/application-dev/application-models/serviceextensionability.md index 08ce2d0a04..b55c7830b5 100644 --- a/en/application-dev/application-models/serviceextensionability.md +++ b/en/application-dev/application-models/serviceextensionability.md @@ -2,7 +2,7 @@ ## Overview -[ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) is an ExtensionAbility component of the service type that provides capabilities related to background services. It holds an internal [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md), which provides a variety of APIs are provided for external systems. +[ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) is an ExtensionAbility component of the service type that provides capabilities related to background services. It holds an internal [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md), which provides a variety of APIs for external systems. In this document, the started ServiceExtensionAbility is called the server, and the component that starts the ServiceExtensionAbility is called the client. @@ -28,7 +28,7 @@ Note the following: ## Lifecycle -The [ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) class provides the lifecycle callbacks **onCreate()**, **onRequest()**, **onConnect()**, **onDisconnect()**, and **onDestory()**. Override them as required. The following figure shows the ServiceExtensionAbility lifecycle. +The [ServiceExtensionAbility](../reference/apis/js-apis-app-ability-serviceExtensionAbility.md) class provides the lifecycle callbacks **onCreate()**, **onRequest()**, **onConnect()**, **onDisconnect()**, and **onDestroy()**. Override them as required. The following figure shows the ServiceExtensionAbility lifecycle. **Figure 1** ServiceExtensionAbility lifecycle ![ServiceExtensionAbility-lifecycle](figures/ServiceExtensionAbility-lifecycle.png) @@ -249,7 +249,6 @@ A system application uses the [startServiceExtensionAbility()](../reference/apis > > - The background service calls the [terminateSelf()](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextterminateself) method to automatically stop itself. > - Another component calls the [stopServiceExtensionAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstopserviceextensionability) method to stop the background service. -> ## Connecting to a Background Service @@ -382,7 +381,7 @@ When a ServiceExtensionAbility is used to provide sensitive services, the client - **Verifying the client identity based on callerUid** - Call the [getCallingUid()](../reference/apis/js-apis-rpc.md#getcallinguid) method to obtain the UID of the client, and then call the [getBundleNameByUid()](../reference/apis/js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) method to obtain the corresponding bundle name. In this way, the client identify is verified. Note that [getBundleNameByUid()](../reference/apis/js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) is asynchronous, and therefore the server cannot return the verification result to the client. This verification mode applies when the client sends an asynchronous task request to the server. The sample code is as follows: + Call the [getCallingUid()](../reference/apis/js-apis-rpc.md#getcallinguid) method to obtain the UID of the client, and then call the [getBundleNameByUid()](../reference/apis/js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) method to obtain the corresponding bundle name. In this way, the client identity is verified. Note that [getBundleNameByUid()](../reference/apis/js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) is asynchronous, and therefore the server cannot return the verification result to the client. This verification mode applies when the client sends an asynchronous task request to the server. The sample code is as follows: ```ts import rpc from '@ohos.rpc'; diff --git a/en/application-dev/reference/apis/js-apis-bundleManager-bundleInfo.md b/en/application-dev/reference/apis/js-apis-bundleManager-bundleInfo.md index 5ac1f36f06..229d7cd7b7 100644 --- a/en/application-dev/reference/apis/js-apis-bundleManager-bundleInfo.md +++ b/en/application-dev/reference/apis/js-apis-bundleManager-bundleInfo.md @@ -36,6 +36,7 @@ Provides the detailed information of the permissions to request from the system. | Name | Type | Readable| Writable| Description | | --------------------- | ----------------------- | ---- | ---- | ---------------------| | name | string | Yes | Yes | Name of the permission to request. | +| moduleName10+ | string | Yes | Yes | Name of the module that requests the permission. | | reason | string | Yes | Yes | Reason for requesting the permission. | | reasonId | number | Yes | Yes | ID of the reason for requesting the permission.| | usedScene | [UsedScene](#usedscene) | Yes | Yes | Application scenario and timing for using the permission.| diff --git a/en/application-dev/reference/errorcodes/errorcode-bundle.md b/en/application-dev/reference/errorcodes/errorcode-bundle.md index 8f7f78de3c..e247f85658 100644 --- a/en/application-dev/reference/errorcodes/errorcode-bundle.md +++ b/en/application-dev/reference/errorcodes/errorcode-bundle.md @@ -719,9 +719,8 @@ Failed to install the HAP because the isolationMode configured is not supported. During application installation, the value of **isolationMode** in the HAP conflicts with the isolation mode of the device. **Possible Causes** - -1. The device supports the isolation mode (the value of **supportIsolationMode** is **true**), whereas the value of **isolationMode** in the HAP is **nonisolationOnly**. -2. The device does not support the isolation mode (the value of **supportIsolationMode** is **false**), whereas the value of **isolationMode** in the HAP is **isolationOnly**. +1. The device supports the isolation mode (the value of **persist.bms.supportIsolationMode** is **true**), whereas the value of **isolationMode** in the HAP is **nonisolationOnly**. +2. The device does not support the isolation mode (the value of **persist.bms.supportIsolationMode** is **false**), whereas the value of **isolationMode** in the HAP is **isolationOnly**. **Solution** @@ -764,3 +763,24 @@ The version of the application to be updated is not later than the current versi 1. Set the version number of the application to be later than the current version number. 2. If you want to update the application without changing the version number, set **installFlag** to **REPLACE_EXISTING**. + +## 17700048 Code Signature Verification Failure +**Error Message** + +Failed to install the HAP because the code signature verification is failed. + +**Description** + +During application installation, the code signature file of the installation package fails to be verified. + +**Possible Causes** + +1. The module corresponding to the code signature file does not exist in the installation package. +2. The path of the code signature file is invalid. +3. The code signature file does not match the installation package. + +**Solution** + +1. Ensure that the module corresponding to the code signature file is contained in the installation package. +2. Provide a valid path of the code signature file. +3. Use the code signature file that matches the installation package. diff --git a/en/application-dev/windowmanager/application-window-stage.md b/en/application-dev/windowmanager/application-window-stage.md index e5155946df..28fe50294f 100644 --- a/en/application-dev/windowmanager/application-window-stage.md +++ b/en/application-dev/windowmanager/application-window-stage.md @@ -20,44 +20,42 @@ In the stage model, you can perform the following operations during application - Experiencing the immersive window feature -- Setting a floating window - +- Setting a floating window ## Available APIs The table below lists the common APIs used for application window development. For details about more APIs, see [Window](../reference/apis/js-apis-window.md). -| Instance| API| Description| -| -------- | -------- | -------- | -| WindowStage | getMainWindow(callback: AsyncCallback<Window>): void | Obtains the main window of this window stage.
This API can be used only in the stage model.| -| WindowStage | loadContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to the main window in this window stage.
This API can be used only in the stage model.| -| WindowStage | createSubWindow(name: string, callback: AsyncCallback<Window>): void | Creates a subwindow.
This API can be used only in the stage model.| -| Window static method| createWindow(config: Configuration, callback: AsyncCallback\): void | Creates a system window.
**config** specifies the parameters used for creating the window.| -| Window | setUIContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.| -| Window | setWindowBackgroundColor(color: string, callback: AsyncCallback<void>): void | Sets the background color for this window.| -| Window | setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void | Sets the brightness for this window.| -| Window | setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void | Sets whether this window is touchable.| -| Window | moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void | Moves this window.| -| Window | resize(width: number, height: number, callback: AsyncCallback<void>): void | Changes the window size.| -| Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. | -| Window | setWindowSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window.| -| Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.
**systemBarProperties**: properties of the status bar and navigation bar.| -| Window | showWindow(callback: AsyncCallback\): void | Shows this window.| -| Window | on(type: 'touchOutside', callback: Callback<void>): void | Enables listening for click events outside this window.| -| Window | destroyWindow(callback: AsyncCallback<void>): void | Destroys this window.| +| Instance | API | Description | +| -------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| WindowStage | getMainWindow(callback: AsyncCallback<Window>): void | Obtains the main window of this window stage.
This API can be used only in the stage model.| +| WindowStage | loadContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to the main window in this window stage.
This API can be used only in the stage model.| +| WindowStage | createSubWindow(name: string, callback: AsyncCallback<Window>): void | Creates a subwindow.
This API can be used only in the stage model. | +| Window static method| createWindow(config: Configuration, callback: AsyncCallback\): void | Creates a system window.
**config** specifies the parameters used for creating the window. | +| Window | setUIContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window. | +| Window | setWindowBackgroundColor(color: string, callback: AsyncCallback<void>): void | Sets the background color for this window. | +| Window | setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void | Sets the brightness for this window. | +| Window | setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void | Sets whether this window is touchable. | +| Window | moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void | Moves this window. | +| Window | resize(width: number, height: number, callback: AsyncCallback<void>): void | Changes the window size. | +| Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. | +| Window | setWindowSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window. | +| Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.
**systemBarProperties**: properties of the status bar and navigation bar.| +| Window | showWindow(callback: AsyncCallback\): void | Shows this window. | +| Window | on(type: 'touchOutside', callback: Callback<void>): void | Enables listening for click events outside this window. | +| Window | destroyWindow(callback: AsyncCallback<void>): void | Destroys this window. | ## Setting the Main Window of an Application In the stage model, the main window of an application is created and maintained by a **UIAbility** instance. In the **onWindowStageCreate** callback of the **UIAbility** instance, use **WindowStage** to obtain the main window of the application and set its properties. You can also set the properties (for example, **maxWindowWidth**) in the [module.json5 file](../quick-start/module-configuration-file.md#abilities). - ### How to Develop 1. Obtain the main window. - + Call **getMainWindow** to obtain the main window of the application. - + 2. Set the properties of the main window. You can set multiple properties of the main window, such as the background color, brightness, and whether the main window is touchable. The code snippet below uses the **touchable** property as an example. @@ -66,54 +64,52 @@ In the stage model, the main window of an application is created and maintained Call **loadContent** to load the page content to the main window. - ```ts - import UIAbility from '@ohos.app.ability.UIAbility'; - - export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage) { - // 1. Obtain the main window of the application. - let windowClass = null; - windowStage.getMainWindow((err, data) => { - if (err.code) { - console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - return; - } - windowClass = data; - console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - // 2. Set the touchable property of the main window. - let isTouchable = true; - windowClass.setWindowTouchable(isTouchable, (err) => { - if (err.code) { - console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to be touchable.'); - }) - }) - // 3. Load the page content to the main window. - windowStage.loadContent("pages/page2", (err) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content.'); - }); - } - }; - ``` - +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage) { + // 1. Obtain the main window of the application. + let windowClass = null; + windowStage.getMainWindow((err, data) => { + if (err.code) { + console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + // 2. Set the touchable property of the main window. + let isTouchable = true; + windowClass.setWindowTouchable(isTouchable, (err) => { + if (err.code) { + console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the window to be touchable.'); + }) + }) + // 3. Load the page content to the main window. + windowStage.loadContent("pages/page2", (err) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content.'); + }); + } +}; +``` ## Setting a Subwindow of an Application You can create an application subwindow, such as a dialog box, and set its properties. - ### How to Develop 1. Create a subwindow. - + Call **createSubWindow** to create a subwindow. - + 2. Set the properties of the subwindow. After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness. @@ -126,159 +122,160 @@ You can create an application subwindow, such as a dialog box, and set its prope When the subwindow is no longer needed, you can call **destroyWindow** to destroy it. - ```ts - import UIAbility from '@ohos.app.ability.UIAbility'; - - let windowStage_ = null; - let sub_windowClass = null; - export default class EntryAbility extends UIAbility { - showSubWindow() { - // 1. Create a subwindow. - windowStage_.createSubWindow("mySubWindow", (err, data) => { - if (err.code) { - console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); - return; - } - sub_windowClass = data; - console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); - // 2. Set the position, size, and other properties of the subwindow. - sub_windowClass.moveWindowTo(300, 300, (err) => { - if (err.code) { - console.error('Failed to move the window. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in moving the window.'); - }); - sub_windowClass.resize(500, 500, (err) => { - if (err.code) { - console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in changing the window size.'); - }); - // 3. Load the page content to the subwindow. - sub_windowClass.setUIContent("pages/page3", (err) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content.'); - // 3. Show the subwindow. - sub_windowClass.showWindow((err) => { - if (err.code) { - console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in showing the window.'); - }); - }); - }) - } - - destroySubWindow() { - // 4. Destroy the subwindow when it is no longer needed (depending on the service logic). - sub_windowClass.destroyWindow((err) => { - if (err.code) { - console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in destroying the window.'); - }); - } - - onWindowStageCreate(windowStage) { - windowStage_ = windowStage; - // Create a subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only. - this.showSubWindow(); - } - - onWindowStageDestroy() { - // Destroy the subwindow when it is no longer needed, for example, when the Close button in the subwindow is clicked. Calling onWindowStageDestroy is not always necessary. The code here is for reference only. - this.destroySubWindow(); - } - }; - ``` - +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +let windowStage_ = null; +let sub_windowClass = null; + +export default class EntryAbility extends UIAbility { + showSubWindow() { + // 1. Create a subwindow. + windowStage_.createSubWindow("mySubWindow", (err, data) => { + if (err.code) { + console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); + return; + } + sub_windowClass = data; + console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); + // 2. Set the position, size, and other properties of the subwindow. + sub_windowClass.moveWindowTo(300, 300, (err) => { + if (err.code) { + console.error('Failed to move the window. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in moving the window.'); + }); + sub_windowClass.resize(500, 500, (err) => { + if (err.code) { + console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in changing the window size.'); + }); + // 3. Load the page content to the subwindow. + sub_windowClass.setUIContent("pages/page3", (err) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content.'); + // 3. Show the subwindow. + sub_windowClass.showWindow((err) => { + if (err.code) { + console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in showing the window.'); + }); + }); + }) + } + + destroySubWindow() { + // 4. Destroy the subwindow when it is no longer needed (depending on the service logic). + sub_windowClass.destroyWindow((err) => { + if (err.code) { + console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in destroying the window.'); + }); + } + + onWindowStageCreate(windowStage) { + windowStage_ = windowStage; + // Create a subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only. + this.showSubWindow(); + } + + onWindowStageDestroy() { + // Destroy the subwindow when it is no longer needed, for example, when the Close button in the subwindow is clicked. Calling onWindowStageDestroy is not always necessary. The code here is for reference only. + this.destroySubWindow(); + } +}; +``` ## Experiencing the Immersive Window Feature -To create a better video watching and gaming experience, you can use the immersive window feature to hide the system windows, including the status bar and navigation bar. Tis feature is available only for the main window of an application. Since API version 10, the immersive window has the same size as the full screen by default; its layout is controlled by the component module; the background color of its status bar and navigation bar is transparent, and the text color is black. When an application window calls **setWindowLayoutFullScreen**, with **true** passed in, the component module controls the immersive full-screen layout of the status bar and navigation bar. If **false** is passed in, the component module controls the non-immersive full-screen layout of the status bar and navigation bar. +To create a better video watching and gaming experience, you can use the immersive window feature to hide the system windows, including the status bar and navigation bar. This feature is available only for the main window of an application. Since API version 10, the immersive window has the same size as the full screen by default; its layout is controlled by the component module; the background color of its status bar and navigation bar is transparent, and the text color is black. When an application window calls **setWindowLayoutFullScreen**, with **true** passed in, the component module controls the immersive full-screen layout of the status bar and navigation bar. If **false** is passed in, the component module controls the non-immersive full-screen layout of the status bar and navigation bar. ### How to Develop 1. Obtain the main window. - + Call **getMainWindow** to obtain the main window of the application. - + 2. Implement the immersive effect. You can use either of the following methods: + - Method 1: When the main window of the application is a full-screen window, call **setWindowSystemBarEnable** to hide the status bar and navigation bar. + - Method 2: Call **setWindowLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setWindowSystemBarProperties** to set the opacity, background color, text color, and highlighted icon of the status bar and navigation bar to ensure that their display effect is consistent with that of the main window. 3. Load content for the immersive window and show it. Call **loadContent** to load the content to the immersive window. - ```ts - import UIAbility from '@ohos.app.ability.UIAbility'; - - export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage) { - // 1. Obtain the main window of the application. - let windowClass = null; - windowStage.getMainWindow((err, data) => { - if (err.code) { - console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - return; - } - windowClass = data; - console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - - // 2. Use method 1 to implement the immersive effect. - let names = []; - windowClass.setWindowSystemBarEnable(names, (err) => { - if (err.code) { - console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar to be visible.'); - }); - // 2. Use method 2 to implement the immersive effect. - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { - if (err.code) { - console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window layout to full-screen mode.'); - }); - let sysBarProps = { - statusBarColor: '#ff00ff', - navigationBarColor: '#00ff00', - // The following properties are supported since API version 8. - statusBarContentColor: '#ffffff', - navigationBarContentColor: '#ffffff' - }; - windowClass.setWindowSystemBarProperties(sysBarProps, (err) => { - if (err.code) { - console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar properties.'); - }); - }) - // 3. Load the page content to the immersive window. - windowStage.loadContent("pages/page2", (err) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content.'); - }); - } - }; - ``` - +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage) { + // 1. Obtain the main window of the application. + let windowClass = null; + windowStage.getMainWindow((err, data) => { + if (err.code) { + console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + + // 2. Use method 1 to implement the immersive effect. + let names = []; + windowClass.setWindowSystemBarEnable(names, (err) => { + if (err.code) { + console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the system bar to be visible.'); + }); + // 2. Use method 2 to implement the immersive effect. + let isLayoutFullScreen = true; + windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { + if (err.code) { + console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the window layout to full-screen mode.'); + }); + let sysBarProps = { + statusBarColor: '#ff00ff', + navigationBarColor: '#00ff00', + // The following properties are supported since API version 8. + statusBarContentColor: '#ffffff', + navigationBarContentColor: '#ffffff' + }; + windowClass.setWindowSystemBarProperties(sysBarProps, (err) => { + if (err.code) { + console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting the system bar properties.'); + }); + }) + // 3. Load the page content to the immersive window. + windowStage.loadContent("pages/page2", (err) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content.'); + }); + } +}; +``` ## Setting a Floating Window @@ -287,104 +284,83 @@ A floating window is created based on an existing task. It is always displayed i ### How to Develop -1. Apply for permissions. - - To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For more configuration information, see [module.json5 Configuration File](../quick-start/module-configuration-file.md). - - > **NOTE** - > - > If the task for creating the floating window is reclaimed by the system, the floating window will no longer be displayed. If you want the floating window to be displayed in such a case, apply for a [continuous task](../task-management/continuous-task-dev-guide.md). - - ```json - { - "module": { - "requestPermissions":[ - { - "name" : "ohos.permission.SYSTEM_FLOAT_WINDOW", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when":"inuse" - } - } - ] - } - } - ``` - -2. Create a floating window. +**Prerequisites**: To create a floating window (a window of the type **WindowType.TYPE_FLOAT**), you must request the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission. For details, see [Declaring Permissions in the Configuration File](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file). + +1. Create a floating window. Call **window.createWindow** to create a floating window. -3. Set properties for the floating window. +2. Set properties for the floating window. After the floating window is created, you can set its properties, such as the size, position, background color, and brightness. -4. Load content for the floating window and show it. +3. Load content for the floating window and show it. Call **setUIContent** and **showWindow** to load and display the content in the floating window. -5. Destroy the floating window. +4. Destroy the floating window. When the floating window is no longer needed, you can call **destroyWindow** to destroy it. - ```ts - import UIAbility from '@ohos.app.ability.UIAbility'; - import window from '@ohos.window'; - - export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage) { - // 2. Create a floating window. - let windowClass = null; - let config = {name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context}; - window.createWindow(config, (err, data) => { - if (err.code) { - console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); - windowClass = data; - // 3. Set the position, size, and properties of the floating window. - windowClass.moveWindowTo(300, 300, (err) => { - if (err.code) { - console.error('Failed to move the window. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in moving the window.'); - }); - windowClass.resize(500, 500, (err) => { - if (err.code) { - console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in changing the window size.'); - }); - // 4. Load the page content to the floating window. - windowClass.setUIContent("pages/page4", (err) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content.'); - // 4. Show the floating window. - windowClass.showWindow((err) => { - if (err.code) { - console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in showing the window.'); - }); - }); - // 5. Destroy the floating window when it is no longer needed (depending on the service logic). - windowClass.destroyWindow((err) => { - if (err.code) { - console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in destroying the window.'); - }); - }); - } - }; - ``` +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage) { + // 1. Create a floating window. + let windowClass = null; + let config = { + name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context + }; + window.createWindow(config, (err, data) => { + if (err.code) { + console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); + windowClass = data; + // 2. Set the position, size, and properties of the floating window. + windowClass.moveWindowTo(300, 300, (err) => { + if (err.code) { + console.error('Failed to move the window. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in moving the window.'); + }); + windowClass.resize(500, 500, (err) => { + if (err.code) { + console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in changing the window size.'); + }); + // 3. Load the page content to the floating window. + windowClass.setUIContent("pages/page4", (err) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content.'); + // 3. Show the floating window. + windowClass.showWindow((err) => { + if (err.code) { + console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in showing the window.'); + }); + }); + // 4. Destroy the floating window when it is no longer needed (depending on the service logic). + windowClass.destroyWindow((err) => { + if (err.code) { + console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in destroying the window.'); + }); + }); + } +}; +``` + -- GitLab