1# @ohos.window (Window) 2 3The Window module provides basic window management capabilities, such as creating and destroying the current window, setting properties for the current window, and managing and scheduling windows. 4 5This module provides the following common window-related functionalities: 6 7- [Window](#window): window instance, which is the basic unit managed by the window manager. 8- [WindowStage](#windowstage9): window manager that manages windows. 9 10> **NOTE** 11> 12> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 13 14## Modules to Import 15 16```ts 17import { window } from '@kit.ArkUI'; 18``` 19 20## WindowType<sup>7+</sup> 21 22Enumerates the window types. 23 24**System capability**: SystemCapability.WindowManager.WindowManager.Core 25 26| Name | Value| Description | 27|-------------------------------------| ------ |----------------------------------------------------------------------------------------| 28| TYPE_APP | 0 | Application child window.<br>**Model restriction**: This API can be used only in the FA model. | 29| TYPE_SYSTEM_ALERT | 1 | System alert window.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 11. | 30| TYPE_FLOAT<sup>9+</sup> | 8 | Floating window.<br>**Model restriction**: This API can be used only in the stage model.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 31| TYPE_DIALOG<sup>10+</sup> | 16 | Modal window.<br>**Model restriction**: This API can be used only in the stage model.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 32 33## Configuration<sup>9+</sup> 34 35Defines the parameters for creating a child window or system window. 36 37**Atomic service API**: This API can be used in atomic services since API version 12. 38 39**System capability**: SystemCapability.WindowManager.WindowManager.Core 40 41| Name| Type| Mandatory| Description | 42| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 43| name | string | Yes| Name of the window. | 44| windowType | [WindowType](#windowtype7) | Yes| Window type. | 45| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | No| Current application context. If no value is passed, no context is used.<br>In the FA model, do not pass in this parameter when creating a child window. Otherwise, an error is reported.<br>In the stage model, you must pass in this parameter when creating a floating window, modal window, or system window.| 46| displayId | number | No| ID of the current physical screen. If no value is passed, the default value **-1** is used. The value must be an integer. | 47| parentId | number | No| ID of the parent window. If no value is passed, the default value **-1** is used. The value must be an integer. | 48| decorEnabled<sup>12+</sup> | boolean | No| Whether the window decoration is enabled. This parameter is valid only when **windowType** is set to **TYPE_DIALOG**. The value **true** means that the window decoration is enabled, and **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.Window.SessionManager| 49| title<sup>12+</sup> | string| No| Title of the window when **decorEnabled** is set to **true**. If this parameter is not set, an empty string is used by default.<br>**System capability**: SystemCapability.Window.SessionManager| 50 51## AvoidAreaType<sup>7+</sup> 52 53Enumerates the types of the area where the window cannot be displayed. 54 55**System capability**: SystemCapability.WindowManager.WindowManager.Core 56 57**Atomic service API**: This API can be used in atomic services since API version 11. 58 59| Name | Value | Description | 60| -------------------------------- | ---- | ------------------------------------------------------------ | 61| TYPE_SYSTEM | 0 | Default area of the system. Generally, the status bar and navigation bar are included. The default area may vary according to the device in use.| 62| TYPE_CUTOUT | 1 | Notch. | 63| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | Gesture area. | 64| TYPE_KEYBOARD<sup>9+</sup> | 3 | Soft keyboard area. | 65| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4 | Navigation bar area. | 66 67 68## SystemBarProperties 69 70Describes the properties of the status bar and navigation bar. These properties are valid for the window-level status bar and navigation bar. 71 72**Atomic service API**: This API can be used in atomic services since API version 12. 73 74| Name | Type| Mandatory| Description | 75| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 76| statusBarColor | string | No | Background color of the status bar. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**. The default value is **'#66000000'**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 77| isStatusBarLightIcon<sup>7+</sup> | boolean | No | Whether any icon on the status bar is highlighted. The value **true** means that the icon is highlighted, and **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 78| statusBarContentColor<sup>8+</sup> | string | No | Color of the text on the status bar. After this property is set, the setting of **isStatusBarLightIcon** is invalid. The default value is **'#E5FFFFFF'**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 79| navigationBarColor | string | No | Background color of the navigation bar. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**. The default value is **'#66000000'**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 80| isNavigationBarLightIcon<sup>7+</sup> | boolean | No | Whether any icon on the navigation bar is highlighted. The value **true** means that the icon is highlighted, and **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 81| navigationBarContentColor<sup>8+</sup> | string | No | Color of the text on the navigation bar. After this property is set, the setting of **isNavigationBarLightIcon** is invalid. The default value is **'#E5FFFFFF'**.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 82| enableStatusBarAnimation<sup>12+</sup> | boolean | No | Whether to enable animation for a status bar property change. The value **true** means to enable animation, and **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.Window.SessionManager| 83| enableNavigationBarAnimation<sup>12+</sup> | boolean | No | Whether to enable animation for a navigation bar property change. The value **true** means to enable animation, and **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.Window.SessionManager| 84 85## StatusBarProperty<sup>16+</sup> 86 87Describes the properties of the status bar. These properties are returned when you query the status bar's configuration details. 88 89**Atomic service API**: This API can be used in atomic services since API version 16. 90 91| Name | Type| Mandatory| Description| 92| ------------------------------------- | -------- | ---- |------- | 93| contentColor | string | Yes | Color of the text on the status bar. The value is in ARGB format, for example, **#E5FFFFFF**.<br>**System capability**: SystemCapability.Window.SessionManager| 94 95## SystemBarStyle<sup>12+</sup> 96 97Describes the properties of the status bar. These properties are valid for the page-level status bar. 98 99**Atomic service API**: This API can be used in atomic services since API version 12. 100 101**System capability**: SystemCapability.WindowManager.WindowManager.Core 102 103| Name | Type| Read-Only| Optional| Description | 104| ------ | -------- | ---- | ---- | ------------------ | 105| statusBarContentColor | string | Yes | Yes | Color of the text on the status bar. The default value is **'#E5FFFFFF'**.| 106 107## Orientation<sup>9+</sup> 108 109Enumerates the window orientations. 110 111| Name | Value | Description | 112| ------------------------------------- | ---- | ----------------------------- | 113| UNSPECIFIED | 0 | Unspecified. The orientation is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 114| PORTRAIT | 1 | Portrait.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 115| LANDSCAPE | 2 | Landscape.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 116| PORTRAIT_INVERTED | 3 | Reverse portrait.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 117| LANDSCAPE_INVERTED | 4 | Reverse landscape.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 118| AUTO_ROTATION | 5 | Automatically rotates with the sensor. The orientation can be portrait, landscape, reverse portrait, or reverse landscape.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 119| AUTO_ROTATION_PORTRAIT | 6 | Automatically rotates with the sensor in the vertical direction. The orientation can be portrait or reverse portrait.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 120| AUTO_ROTATION_LANDSCAPE | 7 | Automatically rotates with the sensor in the horizontal direction. The orientation can be landscape or reverse landscape.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 121| AUTO_ROTATION_RESTRICTED | 8 | Automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation can be portrait, landscape, reverse portrait, or reverse landscape.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 122| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | Automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation can be portrait or reverse portrait.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 123| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | Automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation can be landscape or reverse landscape.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 124| LOCKED | 11 | Locked.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 125| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> | 12 | Automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation that can be rotated to is determined by the system. For example, the window can rotate to portrait, landscape, or reverse landscape, but not reverse portrait, on a certain device.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 126| USER_ROTATION_PORTRAIT<sup>12+</sup> | 13 | Temporarily rotates to portrait mode, and then automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation that can be rotated to is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 127| USER_ROTATION_LANDSCAPE<sup>12+</sup> | 14 | Temporarily rotates to landscape mode, and then automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation that can be rotated to is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 128| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup> | 15 | Temporarily rotates to reverse portrait mode, and then automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation that can be rotated to is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 129| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16 | Temporarily rotates to reverse landscape mode, and then automatically rotates with the sensor, under the restriction of the rotation switch in the Control Panel. The orientation that can be rotated to is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 130| FOLLOW_DESKTOP<sup>12+</sup> | 17 | Follows the orientation of the home screen.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Window.SessionManager| 131 132## Rect<sup>7+</sup> 133 134Describes the rectangular area of the window. 135 136**System capability**: SystemCapability.WindowManager.WindowManager.Core 137 138**Atomic service API**: This API can be used in atomic services since API version 11. 139 140| Name | Type| Readable| Writable| Description | 141| ------ | -------- | ---- | ---- | ------------------ | 142| left | number | Yes | Yes | Left boundary of the rectangle, in px. The value must be an integer.| 143| top | number | Yes | Yes | Top boundary of the rectangle, in px. The value must be an integer.| 144| width | number | Yes | Yes | Width of the rectangle, in px. The value must be an integer.| 145| height | number | Yes | Yes | Height of the rectangle, in px. The value must be an integer.| 146 147## AvoidArea<sup>7+</sup> 148 149Describes the area where the window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. Touch events will not be responded in this area. 150 151Pay attention to the following restrictions on this area: 152 153- The non-navigation bar area in the gesture area at the bottom supports transparent transmission of touch events, touch and hold events, but not drag events. 154 155- The gesture area on the left and right sides supports transparent transmission of touch events, touch and hold events, and swipe up and down events, but not drag events. 156 157- The navigation bar area supports responding to touch events, touch and hold events, and drag events. However, it does not support transparent transmission of events. 158 159**System capability**: SystemCapability.WindowManager.WindowManager.Core 160 161**Atomic service API**: This API can be used in atomic services since API version 11. 162 163| Name | Type | Readable| Writable| Description | 164| ---------- | ------------- | ---- | ---- | ------------------ | 165| visible<sup>9+</sup> | boolean | Yes | Yes | Whether the window can be displayed in the area. The value **true** means that the window can be displayed in the area, and **false** means the opposite.| 166| leftRect | [Rect](#rect7) | Yes | Yes | Rectangle on the left of the screen.| 167| topRect | [Rect](#rect7) | Yes | Yes | Rectangle at the top of the screen.| 168| rightRect | [Rect](#rect7) | Yes | Yes | Rectangle on the right of the screen.| 169| bottomRect | [Rect](#rect7) | Yes | Yes | Rectangle at the bottom of the screen.| 170 171## Size<sup>7+</sup> 172 173Describes the window size. 174 175**System capability**: SystemCapability.WindowManager.WindowManager.Core 176 177**Atomic service API**: This API can be used in atomic services since API version 11. 178 179| Name | Type| Readable| Writable| Description | 180| ------ | -------- | ---- | ---- | ---------- | 181| width | number | Yes | Yes | Window width, in px. The value must be an integer.| 182| height | number | Yes | Yes | Window height, in px. The value must be an integer.| 183 184## RectChangeReason<sup>12+</sup> 185 186Enumerates the reasons for window rectangle (position and size) changes. 187 188**System capability**: SystemCapability.Window.SessionManager 189 190**Atomic service API**: This API can be used in atomic services since API version 12. 191 192| Name | Value | Description | 193| --------------------- | ---- | ------------------------------------------------------------ | 194| UNDEFINED | 0 | Default value. | 195| MAXIMIZE | 1 | The window is maximized. | 196| RECOVER | 2 | The window is restored to the previous state. | 197| MOVE | 3 | The window is moved.| 198| DRAG | 4 | The window is zoomed in or out by dragging.| 199| DRAG_START | 5 | The window starts zooming in or out.| 200| DRAG_END | 6 | The window finishes zooming in or out.| 201 202## RectChangeOptions<sup>12+</sup> 203 204Describes the value and reason returned upon a window rectangle (position and size) change. 205 206**System capability**: SystemCapability.Window.SessionManager 207 208**Atomic service API**: This API can be used in atomic services since API version 12. 209 210| Name | Type | Readable| Writable| Description | 211| ---------- | ------------- | ---- | ---- | ------------------ | 212| rect | [Rect](#rect7) | Yes | Yes | New value of the window rectangle.| 213| reason | [RectChangeReason](#rectchangereason12) | Yes | Yes | Reason for the window rectangle change.| 214 215## AvoidAreaOptions<sup>12+</sup> 216 217Describes the new area where the window cannot be displayed. The new area is returned when the corresponding event is triggered. 218 219**System capability**: SystemCapability.WindowManager.WindowManager.Core 220 221**Atomic service API**: This API can be used in atomic services since API version 12. 222 223| Name | Type | Readable| Writable| Description | 224| ---------- | ------------- | ---- | ---- | ------------------ | 225| type | [AvoidAreaType](#avoidareatype7) | Yes | Yes | Type of the new area returned.| 226| area | [AvoidArea](#avoidarea7) | Yes | Yes | New area returned.| 227 228## WindowProperties 229 230Describes the window properties. 231 232**System capability**: SystemCapability.WindowManager.WindowManager.Core 233 234| Name | Type | Read-Only| Optional| Description | 235| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 236| windowRect<sup>7+</sup> | [Rect](#rect7) | No | No | Window size, which can be obtained from the page lifecycle [onPageShow](./arkui-ts/ts-custom-component-lifecycle.md#onpageshow) or the application lifecycle [onForeground](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonforeground).<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 237| drawableRect<sup>11+</sup> | [Rect](#rect7) | No | No | Size of the rectangle that can be drawn in the window. The upper boundary and left boundary are calculated relative to the window.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 238| type<sup>7+</sup> | [WindowType](#windowtype7) | No | No | Window type.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 239| isFullScreen | boolean | No | No | Whether the window is displayed in full-screen mode. The default value is **false**. The value **true** means that the window is displayed in full-screen mode, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 240| isLayoutFullScreen<sup>7+</sup> | boolean | No | No | Whether the window layout is in full-screen mode (whether the window is immersive). The default value is **false**. The value **true** means that the window is immersive, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 241| focusable<sup>7+</sup> | boolean | Yes | No | Whether the window can gain focus. The default value is **true**. The value **true** means that the window can gain focus, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 242| touchable<sup>7+</sup> | boolean | Yes | No | Whether the window is touchable. The default value is **true**. The value **true** means that the window is touchable, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 243| brightness | number | No | No | Screen brightness. The value is a floating point number in the range [0.0, 1.0], and the value **1.0** means the brightest. If no value is passed, the brightness follows the system. In this case, the obtained brightness value is **-1**.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 244| dimBehindValue<sup>(deprecated)</sup> | number | No | No | Dimness of the window that is not on top. The value is a floating point number in the range [0.0, 1.0], and the value **1.0** means the dimmest.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 9. | 245| isKeepScreenOn | boolean | No | No | Whether the screen is always on. The default value is **false**. The value **true** means that the screen is always on, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 246| isPrivacyMode<sup>7+</sup> | boolean | No | No | Whether the window is in privacy mode. The default value is **false**. The value **true** means that the window is in privacy mode, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 247| isRoundCorner<sup>(deprecated)</sup> | boolean | No | No | Whether the window has rounded corners. The default value is **false**. The value **true** means that the window has rounded corners, and **false** means the opposite.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 9. | 248| isTransparent<sup>7+</sup> | boolean | No | No | Whether the window is transparent. The default value is **false**. The value **true** means that the window is transparent, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 249| id<sup>9+</sup> | number | Yes | No | Window ID. The default value is **0**. The value must be an integer.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 250| displayId<sup>12+</sup> | number | Yes | Yes | ID of the screen where the window is located. By default, the ID of the main screen is returned. The value must be an integer.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 251| name<sup>18+</sup> | string | Yes | Yes | Window name. The default value is an empty string.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 252 253## DecorButtonStyle<sup>14+</sup> 254 255Describes the button style of the system decoration bar. 256 257**System capability**: SystemCapability.Window.SessionManager 258 259**Atomic service API**: This API can be used in atomic services since API version 14. 260 261| Name | Type | Readable| Writable| Description | 262| ---------- | ------------- | ---- | ---- | ------------------ | 263| colorMode | [ConfigurationConstant.ColorMode](../apis-ability-kit/js-apis-app-ability-configurationConstant.md#colormode) | Yes | Yes | Color mode. Buttons automatically adapt to light colors in dark mode and to dark colors in light mode. If this parameter is not set, they will automatically match the system color mode.| 264| buttonBackgroundSize | number | Yes | Yes | Size of the button when it is highlighted. The value ranges from 20 vp to 40 vp. The default value is 28 vp.| 265| spacingBetweenButtons | number | Yes | Yes | Spacing between buttons. The value ranges from 12 vp to 24 vp. The default value is 12 vp.| 266| closeButtonRightMargin | number | Yes | Yes | Margin between the rightmost edge of the close button and the window. The value ranges from 8 vp to 22 vp. The default value is 20 vp.| 267 268## ColorSpace<sup>8+</sup> 269 270Enumerates the color spaces. 271 272**Atomic service API**: This API can be used in atomic services since API version 12. 273 274**System capability**: SystemCapability.WindowManager.WindowManager.Core 275 276| Name | Value| Description | 277| ---------- | ------ | -------------- | 278| DEFAULT | 0 | Default SRGB gamut.| 279| WIDE_GAMUT | 1 | Wide-gamut. | 280 281## WindowEventType<sup>10+</sup> 282 283Enumerates the window lifecycle states. 284 285**Atomic service API**: This API can be used in atomic services since API version 11. 286 287| Name | Value| Description | 288| ---------- | ------ | ---------- | 289| WINDOW_SHOWN | 1 | The window is running in the foreground.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 290| WINDOW_ACTIVE | 2 | The window gains focus.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 291| WINDOW_INACTIVE | 3 | The window loses focus.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 292| WINDOW_HIDDEN | 4 | The window is running in the background.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 293| WINDOW_DESTROYED<sup>11+</sup> | 7 | The window is destroyed.<br>**System capability**: SystemCapability.Window.SessionManager| 294 295## WindowLimits<sup>11+</sup> 296 297Defines the window size limits. You can call [setWindowLimits](#setwindowlimits11) to set the window size limits and call [getWindowLimits](#getwindowlimits11) to obtain the current window size limits. 298 299**Atomic service API**: This API can be used in atomic services since API version 12. 300 301**System capability**: SystemCapability.Window.SessionManager 302 303| Name | Type | Readable| Writable| Description | 304| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- | 305| maxWidth | number | Yes | Yes | Maximum window width, in px. The value must be an integer. The default value is **0**, indicating that the property does not change. The lower limit is **0**, and the upper limit is the maximum width specified by the system. | 306| maxHeight | number | Yes | Yes | Maximum window height, in px. The value must be an integer. The default value is **0**, indicating that the property does not change. The lower limit is **0**, and the upper limit is the maximum height specified by the system. | 307| minWidth | number | Yes | Yes | Minimum window width, in px. The value must be an integer. The default value is **0**, indicating that the property does not change. The lower limit is **0**, and the upper limit is the minimum width specified by the system. | 308| minHeight | number | Yes | Yes | Minimum window height, in px. The value must be an integer. The default value is **0**, indicating that the property does not change. The lower limit is **0**, and the upper limit is the minimum height specified by the system. | 309 310## WindowStatusType<sup>11+</sup> 311 312Enumerates the window modes. 313 314**Atomic service API**: This API can be used in atomic services since API version 12. 315 316**System capability**: SystemCapability.Window.SessionManager 317 318| Name | Value | Description | 319| ---------- | ---- | ----------------------------- | 320| UNDEFINED | 0 | The window mode is not defined by the application. | 321| FULL_SCREEN | 1 | The application is displayed in full screen. | 322| MAXIMIZE | 2 | The application window is maximized. | 323| MINIMIZE | 3 | The application window is minimized. | 324| FLOATING | 4 | The application is displayed in a floating window. | 325| SPLIT_SCREEN | 5 | The application is displayed in split-screen mode. | 326 327## TitleButtonRect<sup>11+</sup> 328 329Defines the rectangle used to hold the minimize, maximize, and close buttons on the title bar. This rectangle is located in the upper right corner of the window. 330 331**Atomic service API**: This API can be used in atomic services since API version 12. 332 333**System capability**: SystemCapability.Window.SessionManager 334 335| Name | Type | Readable| Writable| Description | 336| ------ | ------ | ---- | ---- | ------------------------------------------ | 337| right | number | Yes | Yes | Right boundary of the rectangle, in vp. The value must be an integer.| 338| top | number | Yes | Yes | Top boundary of the rectangle, in vp. The value must be an integer.| 339| width | number | Yes | Yes | Width of the rectangle, in vp. The value must be an integer. | 340| height | number | Yes | Yes | Height of the rectangle, in vp. The value must be an integer. | 341 342## MaximizePresentation<sup>12+</sup> 343 344Enumerates the layout when the window is maximized. 345 346**System capability**: SystemCapability.Window.SessionManager 347 348| Name | Value | Description | 349| ---------- | ---- | ----------------------------- | 350| FOLLOW_APP_IMMERSIVE_SETTING | 0 | The window, when maximized, follows the immersive layout of the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 351| EXIT_IMMERSIVE | 1 | The window, when maximized, exits the immersive layout.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 352| ENTER_IMMERSIVE | 2 | The window, when maximized, transitions into the immersive layout, and the window title bar and dock bar are displayed when the cursor hovers over the hot zone.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 353| ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER<sup>14+</sup> | 3 | The window, when maximized, transitions into the immersive layout, and the window title bar and dock bar are not displayed when you hover the cursor over the hot zone.<br>**Atomic service API**: This API can be used in atomic services since API version 14. | 354 355## MoveConfiguration<sup>15+</sup> 356 357Describes the window movement configuration. 358 359**Atomic service API**: This API can be used in atomic services since API version 15. 360 361**System capability**: SystemCapability.Window.SessionManager 362 363| Name | Type | Mandatory| Description | 364| ------ | ------ | ---- | ------------------------------------------ | 365| displayId | number | No| Target display ID. The value must be an integer. If a non-integer is passed in, the value is rounded down. If this parameter is not set or the target displayed ID does not exist, the current display is used by default.| 366 367## WindowDensityInfo<sup>15+</sup> 368 369Describes the information about the display density of the screen where the window is located and the window's custom display density. It is a scale factor independent of pixel units, that is, a factor for scaling display size. 370 371**Atomic service API**: This API can be used in atomic services since API version 15. 372 373**System capability**: SystemCapability.Window.SessionManager 374 375| Name | Type| Readable| Writable| Description | 376| ------ | -------- | ---- | ---- | ---------- | 377| systemDensity | number | Yes | No | System's display size scale factor for the screen where the window is located. The value ranges from 0.5 to 4.0 and varies according to user settings.| 378| defaultDensity | number | Yes | No | Default display size scale factor for the screen where the window is located. The value ranges from 0.5 to 4.0 and varies with the screen.| 379| customDensity | number | Yes | No | Custom display size scale factor of the window. The value ranges from 0.5 to 4.0. If this parameter is left unspecified, the system's display size scale factor is used.| 380 381## WindowLayoutInfo<sup>15+</sup> 382 383Describes the information about the window layout. 384 385**Atomic service API**: This API can be used in atomic services since API version 15. 386 387**System capability**: SystemCapability.Window.SessionManager 388 389| Name | Type | Mandatory| Description | 390| ------ | ------ | ---- | ------------------------------------------ | 391| windowRect<sup>15+</sup> | [Rect](#rect7) | Yes| Window rectangle, that is, the position and size of the window on the display.| 392 393## window.createWindow<sup>9+</sup> 394 395createWindow(config: Configuration, callback: AsyncCallback<Window>): void 396 397Creates a child window or system window. This API uses an asynchronous callback to return the result. 398 399**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW (required when the window type is **window.WindowType.TYPE_FLOAT**) 400 401**Atomic service API**: This API can be used in atomic services since API version 12. 402 403**System capability**: SystemCapability.WindowManager.WindowManager.Core 404 405**Parameters** 406 407| Name| Type| Mandatory| Description| 408| -------- | -------------------------------------- | -- | --------------------------------- | 409| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window. | 410| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the window created.| 411 412**Error codes** 413 414For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 415 416| ID| Error Message| 417| ------- | -------------------------------- | 418| 201 | Permission verification failed. The application does not have the permission required to call the API. | 419| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 420| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 421| 1300001 | Repeated operation. | 422| 1300002 | This window state is abnormal. | 423| 1300004 | Unauthorized operation. | 424| 1300006 | This window context is abnormal. | 425| 1300008 | The display device is abnormal. | 426| 1300009 | The parent window is invalid. | 427 428**Example** 429 430```ts 431import { BusinessError } from '@kit.BasicServicesKit'; 432 433let windowClass: window.Window | undefined = undefined; 434let config: window.Configuration = { 435 name: "test", 436 windowType: window.WindowType.TYPE_DIALOG, 437 ctx: this.context 438}; 439try { 440 window.createWindow(config, (err: BusinessError, data) => { 441 const errCode: number = err.code; 442 if (errCode) { 443 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 444 return; 445 } 446 windowClass = data; 447 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 448 windowClass.resize(500, 1000); 449 }); 450} catch (exception) { 451 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 452} 453``` 454 455## window.createWindow<sup>9+</sup> 456 457createWindow(config: Configuration): Promise<Window> 458 459Creates a child window or system window. This API uses a promise to return the result. 460 461**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW (required when the window type is **window.WindowType.TYPE_FLOAT**) 462 463**Atomic service API**: This API can be used in atomic services since API version 12. 464 465**System capability**: SystemCapability.WindowManager.WindowManager.Core 466 467**Parameters** 468 469| Name| Type| Mandatory| Description| 470| ------ | -------------------------------- | -- | ------------------ | 471| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window.| 472 473**Return value** 474 475| Type| Description| 476| -------------------------------- | ------------------------------------ | 477| Promise<[Window](#window)> | Promise used to return the window created.| 478 479**Error codes** 480 481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 482 483| ID| Error Message| 484| ------- | -------------------------------- | 485| 201 | Permission verification failed. The application does not have the permission required to call the API. | 486| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 487| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 488| 1300001 | Repeated operation. | 489| 1300002 | This window state is abnormal. | 490| 1300004 | Unauthorized operation. | 491| 1300006 | This window context is abnormal. | 492| 1300008 | The display device is abnormal. | 493| 1300009 | The parent window is invalid. | 494 495**Example** 496 497```ts 498import { BusinessError } from '@kit.BasicServicesKit'; 499 500let windowClass: window.Window | undefined = undefined; 501let config: window.Configuration = { 502 name: "test", 503 windowType: window.WindowType.TYPE_DIALOG, 504 ctx: this.context 505}; 506try { 507 let promise = window.createWindow(config); 508 promise.then((data) => { 509 windowClass = data; 510 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 511 }).catch((err: BusinessError) => { 512 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 513 }); 514} catch (exception) { 515 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 516} 517``` 518 519## window.findWindow<sup>9+</sup> 520 521findWindow(name: string): Window 522 523Finds a window based on the name. 524 525**System capability**: SystemCapability.WindowManager.WindowManager.Core 526 527**Atomic service API**: This API can be used in atomic services since API version 11. 528 529**Parameters** 530 531| Name| Type | Mandatory| Description | 532| ------ | ------ | ---- | -------- | 533| name | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9).| 534 535**Return value** 536 537| Type| Description| 538| ----------------- | ------------------- | 539| [Window](#window) | Window found.| 540 541**Error codes** 542 543For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 544 545| ID| Error Message| 546| ------- | -------------------------------- | 547| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 548| 1300002 | This window state is abnormal. | 549 550**Example** 551 552```ts 553let windowClass: window.Window | undefined = undefined; 554try { 555 windowClass = window.findWindow('test'); 556} catch (exception) { 557 console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`); 558} 559``` 560 561## window.getLastWindow<sup>9+</sup> 562 563getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 564 565Obtains the top window of the current application. This API uses an asynchronous callback to return the result. If no child window is available, the main window of the application is returned. 566 567**Atomic service API**: This API can be used in atomic services since API version 12. 568 569**System capability**: SystemCapability.WindowManager.WindowManager.Core 570 571**Parameters** 572 573| Name| Type| Mandatory| Description| 574| -------- | -------------------------------------- | -- | ---------------------------------------- | 575| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Current application context.| 576| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the top window obtained.| 577 578**Error codes** 579 580For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 581 582| ID| Error Message| 583| ------- | -------------------------------- | 584| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 585| 1300002 | This window state is abnormal. | 586| 1300006 | This window context is abnormal. | 587 588**Example** 589 590```ts 591// EntryAbility.ets 592import { UIAbility } from '@kit.AbilityKit'; 593import { BusinessError } from '@kit.BasicServicesKit'; 594 595export default class EntryAbility extends UIAbility { 596 // ... 597 onWindowStageCreate(windowStage: window.WindowStage) { 598 console.info('onWindowStageCreate'); 599 let windowClass: window.Window | undefined = undefined; 600 try { 601 window.getLastWindow(this.context, (err: BusinessError, data) => { 602 const errCode: number = err.code; 603 if (errCode) { 604 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 605 return; 606 } 607 windowClass = data; 608 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 609 }); 610 } catch (exception) { 611 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 612 } 613 } 614} 615``` 616 617## window.getLastWindow<sup>9+</sup> 618 619getLastWindow(ctx: BaseContext): Promise<Window> 620 621Obtains the top window of the current application. This API uses a promise to return the result. If no child window is available, the main window of the application is returned. 622 623**Atomic service API**: This API can be used in atomic services since API version 12. 624 625**System capability**: SystemCapability.WindowManager.WindowManager.Core 626 627**Parameters** 628 629| Name| Type| Mandatory| Description| 630| ------ | ----------- | ---- | ------------------------------------------------------------ | 631| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 632 633**Return value** 634 635| Type| Description| 636| -------------------------------- | ------------------------------------------- | 637| Promise<[Window](#window)> | Promise used to return the top window obtained.| 638 639**Error codes** 640 641For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 642 643| ID| Error Message| 644| ------- | -------------------------------- | 645| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 646| 1300002 | This window state is abnormal. | 647| 1300006 | This window context is abnormal. | 648 649**Example** 650 651```ts 652// EntryAbility.ets 653import { UIAbility } from '@kit.AbilityKit'; 654import { BusinessError } from '@kit.BasicServicesKit'; 655 656export default class EntryAbility extends UIAbility { 657 // ... 658 onWindowStageCreate(windowStage: window.WindowStage) { 659 console.info('onWindowStageCreate'); 660 let windowClass: window.Window | undefined = undefined; 661 try { 662 let promise = window.getLastWindow(this.context); 663 promise.then((data) => { 664 windowClass = data; 665 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 666 }).catch((err: BusinessError) => { 667 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 668 }); 669 } catch (exception) { 670 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 671 } 672 } 673} 674``` 675 676## window.shiftAppWindowFocus<sup>11+</sup> 677shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise<void> 678 679Shifts the window focus from the source window to the target window in the same application. The window focus can be shifted between the main window and a child window. 680 681**Atomic service API**: This API can be used in atomic services since API version 12. 682 683**System capability**: SystemCapability.Window.SessionManager 684 685**Parameters** 686 687| Name | Type | Mandatory | Description | 688| -------------- | ------ | ----- | ----------------------- | 689| sourceWindowId | number | Yes | ID of the source window, which is having the focus.| 690| targetWindowId | number | Yes | ID of the target window. | 691 692**Return value** 693 694| Type | Description | 695| ------------------- | ------------------------- | 696| Promise<void> | Promise that returns no value.| 697 698**Error codes** 699 700For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 701 702| ID| Error Message | 703| ------- | --------------------------------------------- | 704| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 705| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 706| 1300002 | This window state is abnormal. | 707| 1300003 | This window manager service works abnormally. | 708| 1300004 | Unauthorized operation. | 709 710**Example** 711 712```ts 713// EntryAbility.ets 714import { UIAbility } from '@kit.AbilityKit'; 715import { BusinessError } from '@kit.BasicServicesKit'; 716 717export default class EntryAbility extends UIAbility { 718 onWindowStageCreate(windowStage: window.WindowStage) { 719 // ... 720 console.info('onWindowStageCreate'); 721 let windowClass: window.Window | undefined = undefined; 722 let subWindowClass: window.Window | undefined = undefined; 723 let windowClassId: number = -1; 724 let subWindowClassId: number = -1; 725 726 try { 727 // Obtain the main window and ID of the application. 728 let promise = windowStage.getMainWindow(); 729 promise.then((data) => { 730 if (data == null) { 731 console.error("Failed to obtaining the window. Cause: The data is empty"); 732 return; 733 } 734 windowClass = data; 735 windowClass.setUIContent("pages/Index"); 736 windowClassId = windowClass.getWindowProperties().id; 737 console.info('Succeeded in obtaining the window') 738 }).catch((err: BusinessError) => { 739 console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`); 740 }); 741 742 // Create or obtain a child window and its ID. In this case, the child window has focus. 743 let promiseSub = windowStage.createSubWindow("testSubWindow"); 744 promiseSub.then((data) => { 745 if (data == null) { 746 console.error("Failed to obtaining the window. Cause: The data is empty"); 747 return; 748 } 749 subWindowClass = data; 750 subWindowClassId = subWindowClass.getWindowProperties().id; 751 subWindowClass.resize(500, 500); 752 subWindowClass.setUIContent("pages/Index2"); 753 subWindowClass.showWindow(); 754 755 // Listen for the window status and ensure that the window is ready. 756 subWindowClass.on("windowEvent", (windowEvent) => { 757 if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) { 758 // Switch the focus. 759 let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId); 760 promise.then(() => { 761 console.info('Succeeded in shifting app window focus'); 762 }).catch((err: BusinessError) => { 763 console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`); 764 }); 765 } 766 }); 767 }); 768 } catch (exception) { 769 console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`); 770 } 771 } 772} 773``` 774 775## window.shiftAppWindowPointerEvent<sup>15+</sup> 776shiftAppWindowPointerEvent(sourceWindowId: number, targetWindowId: number): Promise<void> 777 778Transfers an input event from one window to another within the same application, particularly in split-window scenarios. This API uses a promise to return the result. It takes effect only for the main window and its child windows on 2-in-1 devices. 779 780On 2-in-1 devices, the source window must be in a mouse-down state for this API to work; otherwise, the call does not take effect. After the input event is transferred, a mouse-up event is sent to the source window, and a mouse-down event is sent to the target window. 781 782**Atomic service API**: This API can be used in atomic services since API version 15. 783 784**System capability**: SystemCapability.Window.SessionManager 785 786**Parameters** 787 788| Name | Type | Mandatory | Description | 789| -------------- | ------ | ----- | ----------------------- | 790| sourceWindowId | number | Yes | ID of the source window. You are advised to call [getWindowProperties()](#getwindowproperties9) to obtain the window ID. | 791| targetWindowId | number | Yes | ID of the target window. You are advised to call [getWindowProperties()](#getwindowproperties9) to obtain the window ID. | 792 793**Return value** 794 795| Type | Description | 796| ------------------- | ------------------------- | 797| Promise<void> | Promise that returns no value.| 798 799**Error codes** 800 801For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 802 803| ID| Error Message | 804| ------- | --------------------------------------------- | 805| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 806| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 807| 1300002 | This window state is abnormal. | 808| 1300003 | This window manager service works abnormally. | 809| 1300004 | Unauthorized operation. | 810 811**Example** 812 813```ts 814// ets/pages/Index.ets 815import { window } from '@kit.ArkUI'; 816import { BusinessError } from '@kit.BasicServicesKit'; 817 818@Entry 819struct Index { 820 build() { 821 Row() { 822 Column() { 823 Blank('160') 824 .color(Color.Blue) 825 .onTouch((event: TouchEvent) => { 826 if (event.type === TouchType.Down) { 827 try { 828 let sourceWindowId = 1; 829 let targetWindowId = 2; 830 let promise = window.shiftAppWindowPointerEvent(sourceWindowId, targetWindowId); 831 promise.then(() => { 832 console.info('Succeeded in shifting app window pointer event'); 833 }).catch((err: BusinessError) => { 834 console.error(`Failed to shift app window pointer event. Cause code: ${err.code}, message: ${err.message}`); 835 }); 836 } catch (exception) { 837 console.error(`Failed to shift app pointer event. Cause code: ${exception.code}, message: ${exception.message}`); 838 } 839 } 840 }) 841 }.width('100%') 842 }.height('100%').width('100%') 843 } 844} 845``` 846 847## window.getWindowsByCoordinate<sup>14+</sup> 848 849getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise<Array<Window>> 850 851Obtains visible windows at the specified coordinates of the application. This API uses a promise to return the result. 852 853**Atomic service API**: This API can be used in atomic services since API version 14. 854 855**System capability**: SystemCapability.Window.SessionManager 856 857**Parameters** 858 859| Name| Type | Mandatory| Description | 860| ------ | ---------- |----|---------------------------------------------------------------------------| 861| displayId | number| Yes | ID of the display where the windows are located. The value must be an integer and can be obtained from [WindowProperties](#windowproperties).| 862| windowNumber | number| No | Number of windows to obtain. The value must be an integer greater than 0. If this parameter is not set or is less than or equal to 0, all windows that meet the conditions are returned. | 863| x | number | No | X coordinate. The value must be a non-negative integer. If this parameter is not set or is less than 0, all visible windows are returned. | 864| y | number| No | Y coordinate. The value must be a non-negative integer. If this parameter is not set or is less than 0, all visible windows are returned. | 865 866**Return value** 867 868| Type | Description | 869| -------------------------------- |-------------------------| 870| Promise<Array<[Window](#window)>> | Promise used to return an array of window objects.| 871 872**Error codes** 873 874For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 875 876| ID | Error Message| 877|----------| ------------------------------ | 878| 401 | Parameter error. Possible cause: Incorrect parameter types. | 879| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 880| 1300003 | This window manager service works abnormally. | 881 882```ts 883import { UIAbility } from '@kit.AbilityKit'; 884import { window } from '@kit.ArkUI'; 885import { BusinessError } from '@kit.BasicServicesKit'; 886 887export default class EntryAbility extends UIAbility { 888 889 onWindowStageCreate(windowStage: window.WindowStage): void { 890 let windowClass = windowStage.getMainWindowSync(); 891 try { 892 let properties = windowClass.getWindowProperties(); 893 window.getWindowsByCoordinate(properties.displayId).then((data) => { 894 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 895 for (let window of data) { 896 // do something with window 897 } 898 }).catch((err: BusinessError) => { 899 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 900 }); 901 window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => { 902 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 903 for (let window of data) { 904 // do something with window 905 } 906 }).catch((err: BusinessError) => { 907 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 908 }); 909 } catch (exception) { 910 console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`); 911 } 912 } 913} 914``` 915 916## window.getAllWindowLayoutInfo<sup>15+</sup> 917 918getAllWindowLayoutInfo(displayId: number): Promise<Array<WindowLayoutInfo>> 919 920Obtains the layout information array of all windows visible on a display. The layout information is arranged based on the current window stacking order, and the topmost window in the hierarchy is at index 0 of the array. This API uses a promise to return the result. 921 922**Atomic service API**: This API can be used in atomic services since API version 15. 923 924**System capability**: SystemCapability.Window.SessionManager 925 926**Parameters** 927 928| Name| Type | Mandatory| Description | 929| ------ | ---------- |----|---------------------------------------------------------------------------| 930| displayId | number| Yes | ID of the display where the windows are located. The value must be an integer and can be obtained from [WindowProperties](#windowproperties).| 931 932**Return value** 933 934| Type | Description | 935| -------------------------------- |-------------------------| 936| Promise<Array<[WindowLayoutInfo](#windowlayoutinfo15)>> | Promise used to return an array of window layout information objects.| 937 938**Error codes** 939 940For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 941 942| ID | Error Message| 943|----------| ------------------------------ | 944| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 945| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 946| 1300002 | This window state is abnormal. | 947| 1300003 | This window manager service works abnormally. | 948 949```ts 950import { window } from '@kit.ArkUI'; 951import { BusinessError } from '@kit.BasicServicesKit'; 952 953try { 954 let displayId = 0; 955 let promise = window.getAllWindowLayoutInfo(displayId) 956 promise.then((data) => { 957 console.info('Succeeded in obtaining all window layout info. Data: ' + JSON.stringify(data)); 958 }).catch((err: BusinessError) => { 959 console.error(`Failed to obtain all window layout info. Cause code: ${err.code}, message: ${err.message}`); 960 }); 961} catch (exception) { 962 console.error(`Failed to obtain all window layout info. Cause code: ${exception.code}, message: ${exception.message}`); 963} 964``` 965 966## window.create<sup>(deprecated)</sup> 967 968create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 969 970Creates a child window. This API uses an asynchronous callback to return the result. 971 972> **NOTE** 973> 974> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 975 976**Model restriction**: This API can be used only in the FA model. 977 978**System capability**: SystemCapability.WindowManager.WindowManager.Core 979 980**Parameters** 981 982| Name | Type | Mandatory| Description | 983| -------- | -------------------------------------- | ---- | ------------------------------------ | 984| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9).| 985| type | [WindowType](#windowtype7) | Yes | Window type. | 986| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the child window created.| 987 988 989**Example** 990 991```ts 992import { BusinessError } from '@kit.BasicServicesKit'; 993 994let windowClass: window.Window | undefined = undefined; 995window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 996 const errCode: number = err.code; 997 if (errCode) { 998 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 999 return; 1000 } 1001 windowClass = data; 1002 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1003}); 1004``` 1005 1006## window.create<sup>(deprecated)</sup> 1007 1008create(id: string, type: WindowType): Promise<Window> 1009 1010Creates a child window. This API uses a promise to return the result. 1011 1012> **NOTE** 1013> 1014> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 1015 1016**Model restriction**: This API can be used only in the FA model. 1017 1018**System capability**: SystemCapability.WindowManager.WindowManager.Core 1019 1020**Parameters** 1021 1022| Name| Type | Mandatory| Description | 1023| ------ | ------------------------- | ---- | ---------- | 1024| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9). | 1025| type | [WindowType](#windowtype7) | Yes | Window type.| 1026 1027**Return value** 1028 1029| Type | Description | 1030| -------------------------------- | --------------------------------------- | 1031| Promise<[Window](#window)> | Promise used to return the child window created.| 1032 1033 1034**Example** 1035 1036```ts 1037import { BusinessError } from '@kit.BasicServicesKit'; 1038 1039let windowClass: window.Window | undefined = undefined; 1040let promise = window.create('test', window.WindowType.TYPE_APP); 1041promise.then((data) => { 1042 windowClass = data; 1043 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1044}).catch((err: BusinessError) => { 1045 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 1046}); 1047``` 1048 1049## window.create<sup>(deprecated)</sup> 1050 1051create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 1052 1053Creates a system window. This API uses an asynchronous callback to return the result. 1054 1055> **NOTE** 1056> 1057> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 1058 1059**System capability**: SystemCapability.WindowManager.WindowManager.Core 1060 1061**Parameters** 1062 1063| Name | Type | Mandatory| Description | 1064| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 1065| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context. | 1066| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9). | 1067| type | [WindowType](#windowtype7) | Yes | Window type. | 1068| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the child window created.| 1069 1070 1071**Example** 1072 1073```ts 1074import { BusinessError } from '@kit.BasicServicesKit'; 1075 1076let windowClass: window.Window | undefined = undefined; 1077window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 1078 const errCode: number = err.code; 1079 if (errCode) { 1080 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1081 return; 1082 } 1083 windowClass = data; 1084 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 1085 windowClass.resetSize(500, 1000); 1086}); 1087``` 1088 1089## window.create<sup>(deprecated)</sup> 1090 1091create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 1092 1093Creates a system window. This API uses a promise to return the result. 1094 1095> **NOTE** 1096> 1097> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 1098 1099**System capability**: SystemCapability.WindowManager.WindowManager.Core 1100 1101**Parameters** 1102 1103| Name| Type | Mandatory| Description | 1104| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 1105| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1106| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9).| 1107| type | [WindowType](#windowtype7) | Yes | Window type. | 1108 1109**Return value** 1110 1111| Type | Description | 1112| -------------------------------- | --------------------------------------- | 1113| Promise<[Window](#window)> | Promise used to return the child window created.| 1114 1115 1116**Example** 1117 1118```ts 1119import { BusinessError } from '@kit.BasicServicesKit'; 1120 1121let windowClass: window.Window | undefined = undefined; 1122let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 1123promise.then((data) => { 1124 windowClass = data; 1125 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 1126}).catch((err: BusinessError) => { 1127 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 1128}); 1129``` 1130 1131## window.find<sup>(deprecated)</sup> 1132 1133find(id: string, callback: AsyncCallback<Window>): void 1134 1135Finds a window based on the ID. This API uses an asynchronous callback to return the result. 1136 1137> **NOTE** 1138> 1139> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 1140 1141**System capability**: SystemCapability.WindowManager.WindowManager.Core 1142 1143**Parameters** 1144 1145| Name | Type | Mandatory| Description | 1146| -------- | -------------------------------------- | ---- | ------------------------------------ | 1147| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9).| 1148| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the window found.| 1149 1150**Example** 1151 1152```ts 1153import { BusinessError } from '@kit.BasicServicesKit'; 1154 1155let windowClass: window.Window | undefined = undefined; 1156window.find('test', (err: BusinessError, data) => { 1157 const errCode: number = err.code; 1158 if (errCode) { 1159 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1160 return; 1161 } 1162 windowClass = data; 1163 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1164}); 1165``` 1166 1167## window.find<sup>(deprecated)</sup> 1168 1169find(id: string): Promise<Window> 1170 1171Finds a window based on the ID. This API uses a promise to return the result. 1172 1173> **NOTE** 1174> 1175> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 1176 1177**System capability**: SystemCapability.WindowManager.WindowManager.Core 1178 1179**Parameters** 1180 1181| Name| Type | Mandatory| Description | 1182| ------ | ------ | ---- | -------- | 1183| id | string | Yes | Window name, that is, the value of **name** in [Configuration](#configuration9).| 1184 1185**Return value** 1186 1187| Type | Description | 1188| -------------------------------- | ------------------------------------- | 1189| Promise<[Window](#window)> | Promise used to return the window found.| 1190 1191**Example** 1192 1193```ts 1194import { BusinessError } from '@kit.BasicServicesKit'; 1195 1196let windowClass: window.Window | undefined = undefined; 1197let promise = window.find('test'); 1198promise.then((data) => { 1199 windowClass = data; 1200 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1201}).catch((err: BusinessError) => { 1202 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1203}); 1204``` 1205 1206## window.getTopWindow<sup>(deprecated)</sup> 1207 1208getTopWindow(callback: AsyncCallback<Window>): void 1209 1210Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 1211 1212> **NOTE** 1213> 1214> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 1215 1216**Model restriction**: This API can be used only in the FA model. 1217 1218**System capability**: SystemCapability.WindowManager.WindowManager.Core 1219 1220**Parameters** 1221 1222| Name | Type | Mandatory| Description | 1223| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1224| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained.| 1225 1226**Example** 1227 1228```ts 1229import { BusinessError } from '@kit.BasicServicesKit'; 1230 1231let windowClass: window.Window | undefined = undefined; 1232window.getTopWindow((err: BusinessError, data) => { 1233 const errCode: number = err.code; 1234 if (errCode) { 1235 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1236 return; 1237 } 1238 windowClass = data; 1239 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1240}); 1241``` 1242 1243## window.getTopWindow<sup>(deprecated)</sup> 1244 1245getTopWindow(): Promise<Window> 1246 1247Obtains the top window of the current application. This API uses a promise to return the result. 1248 1249> **NOTE** 1250> 1251> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 1252 1253**Model restriction**: This API can be used only in the FA model. 1254 1255**System capability**: SystemCapability.WindowManager.WindowManager.Core 1256 1257**Return value** 1258 1259| Type | Description | 1260| -------------------------------- | ----------------------------------------------- | 1261| Promise<[Window](#window)> | Promise used to return the top window obtained.| 1262 1263**Example** 1264 1265```ts 1266import { BusinessError } from '@kit.BasicServicesKit'; 1267 1268let windowClass: window.Window | undefined = undefined; 1269let promise = window.getTopWindow(); 1270promise.then((data)=> { 1271 windowClass = data; 1272 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1273}).catch((err: BusinessError)=>{ 1274 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1275}); 1276``` 1277 1278## window.getTopWindow<sup>(deprecated)</sup> 1279 1280getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1281 1282Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 1283 1284> **NOTE** 1285> 1286> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 1287 1288**System capability**: SystemCapability.WindowManager.WindowManager.Core 1289 1290**Parameters** 1291 1292| Name | Type | Mandatory| Description | 1293| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1294| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1295| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained. | 1296 1297**Example** 1298 1299```ts 1300// EntryAbility.ets 1301import { UIAbility } from '@kit.AbilityKit'; 1302import { BusinessError } from '@kit.BasicServicesKit'; 1303 1304export default class EntryAbility extends UIAbility { 1305 onWindowStageCreate(windowStage:window.WindowStage){ 1306 console.info('onWindowStageCreate'); 1307 let windowClass: window.Window | undefined = undefined; 1308 try { 1309 window.getTopWindow(this.context, (err: BusinessError, data) => { 1310 const errCode: number = err.code; 1311 if(errCode){ 1312 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1313 return ; 1314 } 1315 windowClass = data; 1316 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1317 }); 1318 } catch(error){ 1319 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1320 } 1321 } 1322} 1323``` 1324 1325## window.getTopWindow<sup>(deprecated)</sup> 1326 1327getTopWindow(ctx: BaseContext): Promise<Window> 1328 1329Obtains the top window of the current application. This API uses a promise to return the result. 1330 1331> **NOTE** 1332> 1333> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 1334 1335**System capability**: SystemCapability.WindowManager.WindowManager.Core 1336 1337**Parameters** 1338 1339| Name| Type | Mandatory| Description | 1340| ------ | ----------- | ---- | ------------------------------------------------------------ | 1341| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1342 1343**Return value** 1344 1345| Type | Description | 1346| -------------------------------- | ----------------------------------------------- | 1347| Promise<[Window](#window)> | Promise used to return the top window obtained.| 1348 1349**Example** 1350 1351```ts 1352// EntryAbility.ets 1353import { UIAbility } from '@kit.AbilityKit'; 1354import { BusinessError } from '@kit.BasicServicesKit'; 1355 1356export default class EntryAbility extends UIAbility { 1357 onWindowStageCreate(windowStage:window.WindowStage) { 1358 console.info('onWindowStageCreate'); 1359 let windowClass: window.Window | undefined = undefined; 1360 let promise = window.getTopWindow(this.context); 1361 promise.then((data) => { 1362 windowClass = data; 1363 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1364 }).catch((error: BusinessError) => { 1365 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1366 }); 1367 } 1368} 1369``` 1370 1371## SpecificSystemBar<sup>11+</sup> 1372 1373type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator' 1374 1375Enumerates the types of system bars that can be displayed or hidden. 1376 1377**System capability**: SystemCapability.Window.SessionManager 1378 1379**Atomic service API**: This API can be used in atomic services since API version 11. 1380 1381| Type | Description | 1382|------------|--------| 1383| 'status' | Status bar. | 1384| 'navigation' | Three-button navigation bar. | 1385| 'navigationIndicator' | Bottom navigation bar.| 1386 1387## Window 1388 1389Represents a window instance, which is the basic unit managed by the window manager. 1390 1391In the following API examples, you must use [getLastWindow()](#windowgetlastwindow9), [createWindow()](#windowcreatewindow9), or [findWindow()](#windowfindwindow9) to obtain a **Window** instance (named windowClass in this example) and then call a method in this instance. 1392 1393### showWindow<sup>9+</sup> 1394 1395showWindow(callback: AsyncCallback<void>): void 1396 1397Shows this window. This API uses an asynchronous callback to return the result. This API takes effect only for a system window or an application child window. For the main window of an application, this API moves it at the top when the main window is already displayed. 1398 1399**System capability**: SystemCapability.WindowManager.WindowManager.Core 1400 1401**Atomic service API**: This API can be used in atomic services since API version 11. 1402 1403**Parameters** 1404 1405| Name| Type| Mandatory| Description| 1406| -------- | ------------------------- | -- | --------- | 1407| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1408 1409**Error codes** 1410 1411For details about the error codes, see [Window Error Codes](errorcode-window.md). 1412 1413| ID| Error Message| 1414| ------- | ------------------------------ | 1415| 1300002 | This window state is abnormal. | 1416 1417**Example** 1418 1419```ts 1420import { BusinessError } from '@kit.BasicServicesKit'; 1421 1422windowClass.showWindow((err: BusinessError) => { 1423 const errCode: number = err.code; 1424 if (errCode) { 1425 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1426 return; 1427 } 1428 console.info('Succeeded in showing the window.'); 1429}); 1430``` 1431 1432### showWindow<sup>9+</sup> 1433 1434showWindow(): Promise<void> 1435 1436Shows this window. This API uses a promise to return the result. This API takes effect only for a system window or an application child window. For the main window of an application, this API moves it at the top when the main window is already displayed. 1437 1438**System capability**: SystemCapability.WindowManager.WindowManager.Core 1439 1440**Atomic service API**: This API can be used in atomic services since API version 11. 1441 1442**Return value** 1443 1444| Type| Description| 1445| ------------------- | ----------------------- | 1446| Promise<void> | Promise that returns no value.| 1447 1448**Error codes** 1449 1450For details about the error codes, see [Window Error Codes](errorcode-window.md). 1451 1452| ID| Error Message| 1453| ------- | ------------------------------ | 1454| 1300002 | This window state is abnormal. | 1455 1456**Example** 1457 1458```ts 1459import { BusinessError } from '@kit.BasicServicesKit'; 1460 1461let promise = windowClass.showWindow(); 1462promise.then(() => { 1463 console.info('Succeeded in showing the window.'); 1464}).catch((err: BusinessError) => { 1465 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1466}); 1467``` 1468 1469### destroyWindow<sup>9+</sup> 1470 1471destroyWindow(callback: AsyncCallback<void>): void 1472 1473Destroys this window. This API uses an asynchronous callback to return the result. This API takes effect only for a system window or an application child window. 1474 1475**System capability**: SystemCapability.WindowManager.WindowManager.Core 1476 1477**Atomic service API**: This API can be used in atomic services since API version 11. 1478 1479**Parameters** 1480 1481| Name| Type| Mandatory| Description| 1482| -------- | ------------------------- | -- | --------- | 1483| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1484 1485**Error codes** 1486 1487For details about the error codes, see [Window Error Codes](errorcode-window.md). 1488 1489| ID| Error Message| 1490| ------- | -------------------------------------------- | 1491| 1300002 | This window state is abnormal. | 1492| 1300003 | This window manager service works abnormally. | 1493 1494**Example** 1495 1496```ts 1497import { BusinessError } from '@kit.BasicServicesKit'; 1498 1499windowClass.destroyWindow((err) => { 1500 const errCode: number = err.code; 1501 if (errCode) { 1502 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1503 return; 1504 } 1505 console.info('Succeeded in destroying the window.'); 1506}); 1507``` 1508 1509### destroyWindow<sup>9+</sup> 1510 1511destroyWindow(): Promise<void> 1512 1513Destroys this window. This API uses a promise to return the result. This API takes effect only for a system window or an application child window. 1514 1515**System capability**: SystemCapability.WindowManager.WindowManager.Core 1516 1517**Atomic service API**: This API can be used in atomic services since API version 11. 1518 1519**Return value** 1520 1521| Type| Description| 1522| ------------------- | ------------------------ | 1523| Promise<void> | Promise that returns no value.| 1524 1525**Error codes** 1526 1527For details about the error codes, see [Window Error Codes](errorcode-window.md). 1528 1529| ID| Error Message| 1530| ------- | -------------------------------------------- | 1531| 1300002 | This window state is abnormal. | 1532| 1300003 | This window manager service works abnormally. | 1533 1534**Example** 1535 1536```ts 1537import { BusinessError } from '@kit.BasicServicesKit'; 1538 1539let promise = windowClass.destroyWindow(); 1540promise.then(() => { 1541 console.info('Succeeded in destroying the window.'); 1542}).catch((err: BusinessError) => { 1543 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1544}); 1545``` 1546 1547### moveWindowTo<sup>9+</sup> 1548 1549moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1550 1551Moves this window. This API uses an asynchronous callback to return the result. 1552 1553<!--RP4--> 1554In full-screen mode, this API takes effect only on 2-in-1 devices.<!--RP4End--> 1555 1556On 2-in-1 devices, the window moves relative to the display. On other devices, the window moves relative to the parent window. 1557 1558**System capability**: SystemCapability.WindowManager.WindowManager.Core 1559 1560**Atomic service API**: This API can be used in atomic services since API version 11. 1561 1562**Parameters** 1563 1564| Name| Type| Mandatory| Description| 1565| -------- | ------------------------- | -- | --------------------------------------------- | 1566| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1567| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1568| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 1569 1570**Error codes** 1571 1572For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1573 1574| ID| Error Message| 1575| ------- | -------------------------------------------- | 1576| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1577| 1300002 | This window state is abnormal. | 1578| 1300003 | This window manager service works abnormally. | 1579 1580**Example** 1581 1582```ts 1583import { BusinessError } from '@kit.BasicServicesKit'; 1584 1585try { 1586 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 1587 const errCode: number = err.code; 1588 if (errCode) { 1589 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1590 return; 1591 } 1592 console.info('Succeeded in moving the window.'); 1593 }); 1594} catch (exception) { 1595 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1596} 1597``` 1598 1599### moveWindowTo<sup>9+</sup> 1600 1601moveWindowTo(x: number, y: number): Promise<void> 1602 1603Moves this window. This API uses a promise to return the result. A value is returned once the API is called successfully. However, the final effect cannot be obtained immediately from the return value. To obtain the final effect immediately, call [moveWindowToAsync()](#movewindowtoasync12). 1604 1605<!--RP4--> 1606In full-screen mode, this API takes effect only on 2-in-1 devices.<!--RP4End--> 1607 1608On 2-in-1 devices, the window moves relative to the display. On other devices, the window moves relative to the parent window. 1609 1610**System capability**: SystemCapability.WindowManager.WindowManager.Core 1611 1612**Atomic service API**: This API can be used in atomic services since API version 11. 1613 1614**Parameters** 1615 1616| Name| Type| Mandatory| Description| 1617| -- | ----- | -- | --------------------------------------------- | 1618| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1619| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1620 1621**Return value** 1622 1623| Type| Description| 1624| ------------------- | ------------------------ | 1625| Promise<void> | Promise that returns no value.| 1626 1627**Error codes** 1628 1629For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1630 1631| ID| Error Message| 1632| ------- | -------------------------------------------- | 1633| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1634| 1300002 | This window state is abnormal. | 1635| 1300003 | This window manager service works abnormally. | 1636 1637**Example** 1638 1639```ts 1640import { BusinessError } from '@kit.BasicServicesKit'; 1641 1642try { 1643 let promise = windowClass.moveWindowTo(300, 300); 1644 promise.then(() => { 1645 console.info('Succeeded in moving the window.'); 1646 }).catch((err: BusinessError) => { 1647 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1648 }); 1649} catch (exception) { 1650 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1651} 1652``` 1653 1654### moveWindowToAsync<sup>12+</sup> 1655 1656moveWindowToAsync(x: number, y: number): Promise<void> 1657 1658Moves this window. This API uses a promise to return the result. 1659 1660A value is returned once the call takes effect. You can use **getWindowProperties** in the callback (see the code snippet below) to obtain the final effect immediately. 1661 1662This API takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). 1663 1664On 2-in-1 devices, the window moves relative to the display. On other devices, the window moves relative to the parent window. 1665 1666**System capability**: SystemCapability.Window.SessionManager 1667 1668**Atomic service API**: This API can be used in atomic services since API version 12. 1669 1670**Parameters** 1671 1672| Name| Type| Mandatory| Description| 1673| -- | ----- | -- | --------------------------------------------- | 1674| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1675| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1676 1677**Return value** 1678 1679| Type| Description| 1680| ------------------- | ------------------------ | 1681| Promise<void> | Promise that returns no value.| 1682 1683**Error codes** 1684 1685For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1686 1687| ID| Error Message| 1688| ------- | -------------------------------------------- | 1689| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1690| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1691| 1300002 | This window state is abnormal. | 1692| 1300003 | This window manager service works abnormally. | 1693| 1300010 | The operation in the current window status is invalid. | 1694 1695**Example** 1696 1697```ts 1698import { BusinessError } from '@kit.BasicServicesKit'; 1699 1700try { 1701 let promise = windowClass.moveWindowToAsync(300, 300); 1702 promise.then(() => { 1703 console.info('Succeeded in moving the window.'); 1704 let rect = windowClass?.getWindowProperties().windowRect; 1705 console.info(`Get window rect: ` + JSON.stringify(rect)); 1706 }).catch((err: BusinessError) => { 1707 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1708 }); 1709} catch (exception) { 1710 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1711} 1712``` 1713 1714### moveWindowToAsync<sup>15+</sup> 1715 1716moveWindowToAsync(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1717 1718Moves this window to an existing display (specified by **displayId** in **moveConfiguration**). This API uses a promise to return the result. A value is returned once the call takes effect. You can use **getWindowProperties** in the callback (see the code snippet below) to obtain the final effect immediately. 1719 1720This API takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). 1721 1722On 2-in-1 devices, the window moves relative to the display. On other devices, the window moves relative to the parent window. 1723 1724**System capability**: SystemCapability.Window.SessionManager 1725 1726**Atomic service API**: This API can be used in atomic services since API version 15. 1727 1728**Parameters** 1729 1730| Name| Type| Mandatory| Description| 1731| -- | ----- | -- | --------------------------------------------- | 1732| x | number | Yes| Distance that the window moves along the x-axis, in px. A positive value indicates that the window moves to the right. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1733| y | number | Yes| Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1734| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | No| Window movement configuration. If this parameter is not set, the window will stay on the current display.| 1735 1736**Return value** 1737 1738| Type| Description| 1739| ------------------- | ------------------------ | 1740| Promise<void> | Promise that returns no value.| 1741 1742**Error codes** 1743 1744For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1745 1746| ID| Error Message| 1747| ------- | -------------------------------------------- | 1748| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1749| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1750| 1300002 | This window state is abnormal. | 1751| 1300003 | This window manager service works abnormally. | 1752| 1300010 | The operation in the current window status is invalid. | 1753 1754**Example** 1755 1756```ts 1757import { window } from '@kit.ArkUI'; 1758import { BusinessError } from '@kit.BasicServicesKit'; 1759 1760try { 1761 let moveConfiguration: window.MoveConfiguration = { 1762 displayId: 0 1763 }; 1764 let promise = windowClass.moveWindowToAsync(300, 300, moveConfiguration); 1765 promise.then(() => { 1766 console.info('Succeeded in moving the window.'); 1767 let rect = windowClass?.getWindowProperties().windowRect; 1768 console.info(`Get window rect: ` + JSON.stringify(rect)); 1769 }).catch((err: BusinessError) => { 1770 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1771 }); 1772} catch (exception) { 1773 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1774} 1775``` 1776 1777### moveWindowToGlobal<sup>13+</sup> 1778 1779moveWindowToGlobal(x: number, y: number): Promise<void> 1780 1781Moves this window based on the coordinates. This API uses a promise to return the result. A value is returned once the call takes effect. 1782 1783This operation is not supported in a window in full-screen mode. 1784 1785On non-2-in-1 devices, the child window moves along with the main window. 1786 1787**System capability**: SystemCapability.Window.SessionManager 1788 1789**Atomic service API**: This API can be used in atomic services since API version 13. 1790 1791**Parameters** 1792 1793| Name| Type| Mandatory| Description| 1794| -- | ----- | -- | --------------------------------------------- | 1795| x | number | Yes| Distance that the window moves along the x-axis, in px, with the upper left corner of the display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1796| y | number | Yes| Distance that the window moves along the y-axis, in px, with the upper left corner of the display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1797 1798**Return value** 1799 1800| Type| Description| 1801| ------------------- | ------------------------ | 1802| Promise<void> | Promise that returns no value.| 1803 1804**Error codes** 1805 1806For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1807 1808| ID| Error Message| 1809| ------- | -------------------------------------------- | 1810| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1811| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1812| 1300002 | This window state is abnormal. | 1813| 1300003 | This window manager service works abnormally. | 1814| 1300010 | The operation in the current window status is invalid. | 1815 1816**Example** 1817 1818```ts 1819import { BusinessError } from '@kit.BasicServicesKit'; 1820 1821try { 1822 let promise = windowClass.moveWindowToGlobal(300, 300); 1823 promise.then(() => { 1824 console.info('Succeeded in moving the window.'); 1825 }).catch((err: BusinessError) => { 1826 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1827 }); 1828} catch (exception) { 1829 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1830} 1831``` 1832 1833### moveWindowToGlobal<sup>15+</sup> 1834 1835moveWindowToGlobal(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1836 1837Moves this window to an existing display (specified by **displayId** in **moveConfiguration**) based on the coordinates. This API uses a promise to return the result. A value is returned once the call takes effect. 1838 1839This operation is not supported in a window in full-screen mode. 1840 1841On non-2-in-1 devices, the child window moves along with the main window. 1842 1843**System capability**: SystemCapability.Window.SessionManager 1844 1845**Atomic service API**: This API can be used in atomic services since API version 15. 1846 1847**Parameters** 1848 1849| Name| Type| Mandatory| Description| 1850| -- | ----- | -- | --------------------------------------------- | 1851| x | number | Yes| Distance that the window moves along the x-axis, in px, with the upper left corner of the target display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1852| y | number | Yes| Distance that the window moves along the y-axis, in px, with the upper left corner of the target display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. If a non-integer is passed in, the value is rounded down.| 1853| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | No| Window movement configuration. If this parameter is not set, the window will stay on the current display.| 1854 1855**Return value** 1856 1857| Type| Description| 1858| ------------------- | ------------------------ | 1859| Promise<void> | Promise that returns no value.| 1860 1861**Error codes** 1862 1863For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1864 1865| ID| Error Message| 1866| ------- | -------------------------------------------- | 1867| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1868| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1869| 1300002 | This window state is abnormal. | 1870| 1300003 | This window manager service works abnormally. | 1871| 1300010 | The operation in the current window status is invalid. | 1872 1873**Example** 1874 1875```ts 1876import { window } from '@kit.ArkUI'; 1877import { BusinessError } from '@kit.BasicServicesKit'; 1878 1879try { 1880 let moveConfiguration: window.MoveConfiguration = { 1881 displayId: 0 1882 }; 1883 let promise = windowClass.moveWindowToGlobal(300, 300, moveConfiguration); 1884 promise.then(() => { 1885 console.info('Succeeded in moving the window.'); 1886 }).catch((err: BusinessError) => { 1887 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1888 }); 1889} catch (exception) { 1890 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1891} 1892``` 1893 1894### resize<sup>9+</sup> 1895 1896resize(width: number, height: number, callback: AsyncCallback<void>): void 1897 1898Changes the size of this window. This API uses an asynchronous callback to return the result. 1899 1900The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 1901 1902The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 1903 1904The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 1905 1906The window width and height you set must meet the limits. The rules are as follows: 1907- If the window width or height you set is less than the minimum width or height limit, then the minimum width or height limit takes effect. 1908- If the window width or height you set is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 1909 1910This operation is not supported in a window in full-screen mode. 1911 1912**System capability**: SystemCapability.WindowManager.WindowManager.Core 1913 1914**Atomic service API**: This API can be used in atomic services since API version 11. 1915 1916**Parameters** 1917 1918| Name| Type| Mandatory| Description| 1919| -------- | ------------------------- | -- | ------------------------ | 1920| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 1921| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 1922| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 1923 1924**Error codes** 1925 1926For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1927 1928| ID| Error Message| 1929| ------- | -------------------------------------------- | 1930| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1931| 1300002 | This window state is abnormal. | 1932| 1300003 | This window manager service works abnormally. | 1933 1934**Example** 1935 1936```ts 1937import { BusinessError } from '@kit.BasicServicesKit'; 1938 1939try { 1940 windowClass.resize(500, 1000, (err: BusinessError) => { 1941 const errCode: number = err.code; 1942 if (errCode) { 1943 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 1944 return; 1945 } 1946 console.info('Succeeded in changing the window size.'); 1947 }); 1948} catch (exception) { 1949 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 1950} 1951``` 1952 1953### resize<sup>9+</sup> 1954 1955resize(width: number, height: number): Promise<void> 1956 1957Changes the size of this window. This API uses a promise to return the result. 1958 1959A value is returned once the API is called successfully. However, the final effect cannot be obtained immediately from the return value. To obtain the final effect immediately, call [resizeAsync()](#resizeasync12). 1960 1961The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 1962 1963The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 1964 1965The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 1966 1967The window width and height you set must meet the limits. The rules are as follows: 1968- If the window width or height you set is less than the minimum width or height limit, then the minimum width or height limit takes effect. 1969- If the window width or height you set is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 1970 1971This operation is not supported in a window in full-screen mode. 1972 1973**System capability**: SystemCapability.WindowManager.WindowManager.Core 1974 1975**Atomic service API**: This API can be used in atomic services since API version 11. 1976 1977**Parameters** 1978 1979| Name| Type| Mandatory| Description| 1980| ------ | ------ | -- | ------------------------ | 1981| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 1982| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 1983 1984**Return value** 1985 1986| Type| Description| 1987| ------------------- | ------------------------ | 1988| Promise<void> | Promise that returns no value.| 1989 1990**Error codes** 1991 1992For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1993 1994| ID| Error Message| 1995| ------- | -------------------------------------------- | 1996| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1997| 1300002 | This window state is abnormal. | 1998| 1300003 | This window manager service works abnormally. | 1999 2000**Example** 2001 2002```ts 2003import { BusinessError } from '@kit.BasicServicesKit'; 2004 2005try { 2006 let promise = windowClass.resize(500, 1000); 2007 promise.then(() => { 2008 console.info('Succeeded in changing the window size.'); 2009 }).catch((err: BusinessError) => { 2010 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2011 }); 2012} catch (exception) { 2013 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2014} 2015``` 2016 2017### resizeAsync<sup>12+</sup> 2018 2019resizeAsync(width: number, height: number): Promise<void> 2020 2021Changes the size of this window. This API uses a promise to return the result. 2022 2023A value is returned once the call takes effect. You can use **getWindowProperties** in the callback (see the code snippet below) to obtain the final effect immediately. 2024 2025The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 2026 2027The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 2028 2029The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 2030 2031The window width and height you set must meet the limits. The rules are as follows: 2032 2033- If the window width or height you set is less than the minimum width or height limit, then the minimum width or height limit takes effect. 2034- If the window width or height you set is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 2035 2036This operation is not supported in a window in full-screen mode. 2037 2038**System capability**: SystemCapability.Window.SessionManager 2039 2040**Atomic service API**: This API can be used in atomic services since API version 12. 2041 2042**Parameters** 2043 2044| Name| Type| Mandatory| Description| 2045| ------ | ------ | -- | ------------------------ | 2046| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 2047| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid.| 2048 2049**Return value** 2050 2051| Type| Description| 2052| ------------------- | ------------------------ | 2053| Promise<void> | Promise that returns no value.| 2054 2055**Error codes** 2056 2057For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2058 2059| ID| Error Message| 2060| ------- | -------------------------------------------- | 2061| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2062| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2063| 1300002 | This window state is abnormal. | 2064| 1300003 | This window manager service works abnormally. | 2065| 1300010 | The operation in the current window status is invalid. | 2066 2067**Example** 2068 2069```ts 2070import { BusinessError } from '@kit.BasicServicesKit'; 2071 2072try { 2073 let promise = windowClass.resizeAsync(500, 1000); 2074 promise.then(() => { 2075 console.info('Succeeded in changing the window size.'); 2076 let rect = windowClass?.getWindowProperties().windowRect; 2077 console.info(`Get window rect: ` + JSON.stringify(rect)); 2078 }).catch((err: BusinessError) => { 2079 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2080 }); 2081} catch (exception) { 2082 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2083} 2084``` 2085 2086### getWindowProperties<sup>9+</sup> 2087 2088getWindowProperties(): WindowProperties 2089 2090Obtains the properties of this window. 2091 2092**System capability**: SystemCapability.WindowManager.WindowManager.Core 2093 2094**Atomic service API**: This API can be used in atomic services since API version 11. 2095 2096**Return value** 2097 2098| Type| Description| 2099| ------------------------------------- | ------------- | 2100| [WindowProperties](#windowproperties) | Window properties obtained.| 2101 2102**Error codes** 2103 2104For details about the error codes, see [Window Error Codes](errorcode-window.md). 2105 2106| ID| Error Message| 2107| ------- | ------------------------------ | 2108| 1300002 | This window state is abnormal. | 2109 2110**Example** 2111 2112```ts 2113try { 2114 let properties = windowClass.getWindowProperties(); 2115} catch (exception) { 2116 console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`); 2117} 2118``` 2119 2120### getWindowDensityInfo<sup>15+</sup> 2121 2122getWindowDensityInfo(): WindowDensityInfo 2123 2124Obtains the display density information of this window. 2125 2126**System capability**: SystemCapability.Window.SessionManager 2127 2128**Atomic service API**: This API can be used in atomic services since API version 15. 2129 2130**Return value** 2131 2132| Type| Description| 2133| ------------------------------------- | ------------- | 2134| [WindowDensityInfo](#windowdensityinfo15) | Display density information of the window.| 2135 2136**Error codes** 2137 2138For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2139 2140| ID| Error Message| 2141| ------- | ------------------------------ | 2142| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2143| 1300002 | This window state is abnormal. | 2144 2145**Example** 2146 2147```ts 2148try { 2149 let densityInfo = windowClass.getWindowDensityInfo(); 2150} catch (exception) { 2151 console.error(`Failed to obtain the window densityInfo. Cause code: ${exception.code}, message: ${exception.message}`); 2152} 2153``` 2154 2155### getGlobalRect<sup>13+</sup> 2156 2157getGlobalRect(): Rect 2158 2159Obtains the actual display area of this window on the screen. This API returns the result synchronously. 2160 2161This API can determine the actual on-screen location and size of a window that has been resized on certain devices. 2162 2163**System capability**: SystemCapability.Window.SessionManager 2164 2165**Atomic service API**: This API can be used in atomic services since API version 13. 2166 2167**Return value** 2168 2169| Type| Description| 2170| ------------------- | ------------------------ | 2171| [Rect](#rect7) | A set of four values, which indicates the horizontal distance from the screen's top-left corner to the window's left edge, the vertical distance from the screen's top-left corner to the window's top edge, the width of the window after scaling, and the height of the window after scaling.| 2172 2173**Error codes** 2174 2175For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2176 2177| ID| Error Message| 2178| ------- | -------------------------------------------- | 2179| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2180| 1300002 | This window state is abnormal. | 2181| 1300003 | This window manager service works abnormally. | 2182 2183**Example** 2184 2185```ts 2186try { 2187 let rect = windowClass.getGlobalRect(); 2188 console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect)); 2189} catch (exception) { 2190 console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`); 2191} 2192``` 2193 2194### getWindowAvoidArea<sup>9+</sup> 2195 2196getWindowAvoidArea(type: AvoidAreaType): AvoidArea 2197 2198Obtains the avoid area of this application window, for example, the system bar area, notch, gesture area, and soft keyboard area. 2199 2200This API is typically used in three scenarios: 1. In the **onWindowStageCreate** callback, this API can be used to obtain the avoid area in the initial layout during application startup. 2. When a child window needs to be temporarily displayed and requires layout adjustments for the content, this API can be used. 3. After you create a floating window, modal window, or system window (**WindowType** is a system window) and call [setSystemAvoidAreaEnabled](#setsystemavoidareaenabled18) to enable the such window to access the avoid area, this API can be used. 2201 2202**System capability**: SystemCapability.WindowManager.WindowManager.Core 2203 2204**Atomic service API**: This API can be used in atomic services since API version 11. 2205 2206**Parameters** 2207 2208| Name| Type| Mandatory| Description| 2209| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2210| type | [AvoidAreaType](#avoidareatype7) | Yes| Type of the area.| 2211 2212**Return value** 2213 2214| Type| Description| 2215|--------------------------| ----------------- | 2216| [AvoidArea](#avoidarea7) | Area where the window cannot be displayed.| 2217 2218**Error codes** 2219 2220For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2221 2222| ID| Error Message| 2223| ------- | ------------------------------ | 2224| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2225| 1300002 | This window state is abnormal. | 2226 2227**Example** 2228 2229```ts 2230let type = window.AvoidAreaType.TYPE_SYSTEM; 2231try { 2232 let avoidArea = windowClass.getWindowAvoidArea(type); 2233} catch (exception) { 2234 console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`); 2235} 2236``` 2237 2238### setSystemAvoidAreaEnabled<sup>18+</sup> 2239 2240setSystemAvoidAreaEnabled(enabled: boolean): Promise<void> 2241 2242Enables the window to access the [avoid area](#avoidarea7) when you create a floating window, modal window, or system window (**WindowType** is a system window). 2243 2244This API is particularly useful in the following scenario: After creating the aforementioned types of windows, you should call this API to enable the window to access the avoid area before calling [getWindowAvoidArea()](#getwindowavoidarea9) or [on('avoidAreaChange')](#onavoidareachange9) to obtain the avoid area or listen for changes in the avoid area. 2245 2246**System capability**: SystemCapability.Window.SessionManger 2247 2248**Atomic service API**: This API can be used in atomic services since API version 18. 2249 2250**Parameters** 2251 2252| Name| Type| Mandatory| Description| 2253| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2254| enabled | boolean | Yes| Whether the window is enabled to access the avoid area.<br>The value **true** means to enable the window to access the avoid area, and **false** means the opposite. The default value is **false**.| 2255 2256**Error codes** 2257 2258For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2259 2260| ID| Error Message| 2261| ------- | ------------------------------ | 2262| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2263| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2264| 1300002 | This window state is abnormal. | 2265| 1300003 | This window manager service works abnormally. | 2266| 1300004 | Unauthorized operation. | 2267 2268**Example** 2269 2270```ts 2271import { BusinessError } from '@kit.BasicServicesKit'; 2272 2273let windowClass: window.Window | undefined = undefined; 2274let config: window.Configuration = { 2275 name: "test", 2276 windowType: window.WindowType.TYPE_DIALOG, 2277 decorEnabled: true, 2278 ctx: this.context 2279}; 2280try { 2281 window.createWindow(config, (err: BusinessError, data) => { 2282 const errCode: number = err.code; 2283 if (errCode) { 2284 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 2285 return; 2286 } 2287 windowClass = data; 2288 windowClass.setUIContent("pages/Test"); 2289 let enabled = true; 2290 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 2291 promise.then(() => { 2292 let type = window.AvoidAreaType.TYPE_SYSTEM; 2293 let avoidArea = windowClass?.getWindowAvoidArea(type); 2294 }).catch((err: BusinessError) => { 2295 console.error(`Failed to obtain the system window avoid area. Cause code: ${err.code}, message: ${err.message}`); 2296 }); 2297 }); 2298} catch (exception) { 2299 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 2300} 2301``` 2302 2303### isSystemAvoidAreaEnabled<sup>18+</sup> 2304 2305isSystemAvoidAreaEnabled(): boolean 2306 2307Checks whether a floating window, modal window, or system window (**WindowType** is a system window) is enabled to access the [avoid area](#avoidarea7). 2308 2309**System capability**: SystemCapability.Window.SessionManger 2310 2311**Atomic service API**: This API can be used in atomic services since API version 18. 2312 2313**Return value** 2314 2315| Type| Description| 2316| ------------------------------------- | ------------- | 2317| boolean | Check result.<br>The value **true** means that the window is enabled to access the avoid area, and **false** means the opposite.| 2318 2319**Error codes** 2320 2321For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2322 2323| ID| Error Message| 2324| ------- | ------------------------------ | 2325| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2326| 1300002 | This window state is abnormal. | 2327| 1300003 | This window manager service works abnormally. | 2328| 1300004 | Unauthorized operation. | 2329 2330**Example** 2331 2332```ts 2333import { BusinessError } from '@kit.BasicServicesKit'; 2334 2335let windowClass: window.Window | undefined = undefined; 2336let config: window.Configuration = { 2337 name: "test", 2338 windowType: window.WindowType.TYPE_DIALOG, 2339 decorEnabled: true, 2340 ctx: this.context 2341}; 2342try { 2343 window.createWindow(config, (err: BusinessError, data) => { 2344 const errCode: number = err.code; 2345 if (errCode) { 2346 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 2347 return; 2348 } 2349 windowClass = data; 2350 windowClass.setUIContent("pages/Test"); 2351 let enabled = true; 2352 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 2353 promise.then(() => { 2354 let enable = windowClass?.isSystemAvoidAreaEnabled(); 2355 }).catch((err: BusinessError) => { 2356 console.error(`Failed to obtain whether the system window can get avoid area. Cause code: ${err.code}, message: ${err.message}`); 2357 }); 2358 }); 2359} catch (exception) { 2360 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 2361} 2362``` 2363 2364### setTitleAndDockHoverShown<sup>14+</sup> 2365 2366setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise<void> 2367 2368Sets whether to show the window title bar and dock bar when the cursor hovers over the hot zone while the main window is in full-screen mode. This API uses a promise to return the result. It can be used only on 2-in-1 devices. 2369 2370**System capability**: SystemCapability.Window.SessionManager 2371 2372**Atomic service API**: This API can be used in atomic services since API version 14. 2373 2374**Parameters** 2375 2376| Name | Type | Mandatory| Description | 2377| ---------- | ------- | ---- | ------------------------------------------------------------ | 2378| isTitleHoverShown | boolean | No | Whether to show the window title bar.<br>The value **true** means to show the window title bar, and **false** means the opposite. The default value is **true**.| 2379| isDockHoverShown | boolean | No | Whether to show the dock bar.<br>The value **true** means to show the dock bar, and **false** means the opposite. The default value is **true**.| 2380 2381**Error codes** 2382 2383For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2384 2385| ID| Error Message| 2386| ------- | -------------------------------------------- | 2387| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2388| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2389| 1300002 | This window state is abnormal. | 2390| 1300004 | Unauthorized operation. | 2391 2392**Example** 2393 2394```ts 2395// EntryAbility.ets 2396import { UIAbility } from '@kit.AbilityKit'; 2397import { BusinessError } from '@kit.BasicServicesKit'; 2398import { window } from '@kit.ArkUI'; 2399 2400export default class EntryAbility extends UIAbility { 2401 // ... 2402 onWindowStageCreate(windowStage: window.WindowStage): void { 2403 // Load the page corresponding to the main window. 2404 windowStage.loadContent('pages/Index', (err) => { 2405 let mainWindow: window.Window | undefined = undefined; 2406 // Obtain the main window. 2407 windowStage.getMainWindow().then( 2408 data => { 2409 mainWindow = data; 2410 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2411 // Call maximize to enable the full-screen mode for the window. 2412 mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 2413 // Call setTitleAndDockHoverShown to hide the window title bar and dock bar. 2414 mainWindow.setTitleAndDockHoverShown(false, false); 2415 } 2416 ).catch((err: BusinessError) => { 2417 if(err.code){ 2418 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2419 } 2420 }); 2421 }); 2422 } 2423} 2424``` 2425 2426### setWindowLayoutFullScreen<sup>9+</sup> 2427 2428setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 2429 2430Sets whether the main window layout or the child window layout is immersive. This API uses a promise to return the result. <!--RP8-->From API version 14, this API does not take effect on 2-in-1 devices.<!--RP8End--> 2431- An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 2432- A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 2433 2434**System capability**: SystemCapability.WindowManager.WindowManager.Core 2435 2436**Atomic service API**: This API can be used in atomic services since API version 12. 2437 2438**Parameters** 2439 2440| Name| Type| Mandatory| Description| 2441| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 2442| isLayoutFullScreen | boolean | Yes| Whether the window layout is immersive. (The status bar and navigation bar of the immersive layout are still displayed.) The value **true** means that the window layout is immersive, and **false** means the opposite.| 2443 2444**Return value** 2445 2446| Type| Description| 2447| ------------------- | ------------------------ | 2448| Promise<void> | Promise that returns no value.| 2449 2450**Error codes** 2451 2452For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2453 2454| ID| Error Message| 2455| ------- | -------------------------------------------- | 2456| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2457| 1300002 | This window state is abnormal. | 2458| 1300003 | This window manager service works abnormally. | 2459 2460**Example** 2461 2462```ts 2463// EntryAbility.ets 2464import { UIAbility } from '@kit.AbilityKit'; 2465import { BusinessError } from '@kit.BasicServicesKit'; 2466 2467export default class EntryAbility extends UIAbility { 2468 // ... 2469 onWindowStageCreate(windowStage: window.WindowStage): void { 2470 console.info('onWindowStageCreate'); 2471 let windowClass: window.Window | undefined = undefined; 2472 windowStage.getMainWindow((err: BusinessError, data) => { 2473 const errCode: number = err.code; 2474 if (errCode) { 2475 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2476 return; 2477 } 2478 windowClass = data; 2479 let isLayoutFullScreen = true; 2480 try { 2481 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2482 promise.then(() => { 2483 console.info('Succeeded in setting the window layout to full-screen mode.'); 2484 }).catch((err: BusinessError) => { 2485 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 2486 }); 2487 } catch (exception) { 2488 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 2489 } 2490 }); 2491 } 2492} 2493``` 2494 2495### setImmersiveModeEnabledState<sup>12+</sup> 2496 2497setImmersiveModeEnabledState(enabled: boolean): void 2498 2499Sets whether to enable the immersive layout for the main window. This API does not change the window mode or size. <!--RP8-->From API version 14, this API does not take effect on 2-in-1 devices.<!--RP8End--> 2500 2501**System capability**: SystemCapability.WindowManager.WindowManager.Core 2502 2503**Atomic service API**: This API can be used in atomic services since API version 12. 2504 2505**Parameters** 2506 2507| Name | Type | Mandatory| Description | 2508| ---------- | ------- | ---- | ------------------------------------------------------------ | 2509| enabled | boolean | Yes | Whether to enable the immersive layout.<br>The value **true** means to enable the immersive layout, and **false** means the opposite.| 2510 2511**Error codes** 2512 2513For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2514 2515| ID| Error Message| 2516| ------- | -------------------------------------------- | 2517| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2518| 1300002 | This window state is abnormal. | 2519| 1300003 | This window manager service works abnormally. | 2520| 1300004 | Unauthorized operation. | 2521 2522**Example** 2523 2524```ts 2525try { 2526 let enabled = false; 2527 windowClass.setImmersiveModeEnabledState(enabled); 2528} catch (exception) { 2529 console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2530} 2531``` 2532 2533### getImmersiveModeEnabledState<sup>12+</sup> 2534 2535getImmersiveModeEnabledState(): boolean 2536 2537Checks whether the immersive layout is enabled for this window. 2538 2539**System capability**: SystemCapability.WindowManager.WindowManager.Core 2540 2541**Atomic service API**: This API can be used in atomic services since API version 12. 2542 2543**Return value** 2544| Type | Description | 2545| ------- | ------------------------------------------------------------------------------------ | 2546| boolean | Result indicating whether the immersive layout is enabled.<br>The value **true** means that the immersive layout is enabled, and **false** means the opposite.| 2547 2548**Error codes** 2549 2550For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2551 2552| ID| Error Message| 2553| -------- | -------------------------------------------- | 2554| 1300002 | This window state is abnormal. | 2555| 1300003 | This window manager service works abnormally. | 2556| 1300004 | Unauthorized operation. | 2557 2558**Example** 2559 2560```ts 2561try { 2562 let isEnabled = windowClass.getImmersiveModeEnabledState(); 2563} catch (exception) { 2564 console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2565} 2566``` 2567 2568### setWindowSystemBarEnable<sup>9+</sup> 2569 2570setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2571 2572Sets whether to show the three-button navigation bar, status bar, and bottom navigation bar of the main window. This API uses a promise to return the result. The display of the status bar and bottom navigation bar is controlled by **status**, and that of the three-button navigation bar is controlled by **navigation**. From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 2573 2574The return value does not indicate that the visibility changes of the three-button navigation bar, status bar, and bottom navigation bar have been fully executed. This API does not take effect when it is called by a child window. 2575 2576**Atomic service API**: This API can be used in atomic services since API version 12. 2577 2578**System capability**: SystemCapability.WindowManager.WindowManager.Core 2579 2580**Parameters** 2581 2582| Name| Type | Mandatory| Description| 2583| ----- | ---------------------------- | -- | --------------------------------- | 2584| names | Array<'status'\|'navigation'> | Yes| Whether to show the three-button navigation bar, status bar, and bottom navigation bar of the window in full-screen mode.<br>For example, to display all of them, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 2585 2586**Return value** 2587 2588| Type| Description| 2589| ------------------- | ------------------------ | 2590| Promise<void> | Promise that returns no value.| 2591 2592**Error codes** 2593 2594For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2595 2596| ID| Error Message| 2597| ------- | -------------------------------------------- | 2598| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2599| 1300002 | This window state is abnormal. | 2600| 1300003 | This window manager service works abnormally. | 2601 2602**Example** 2603 2604```ts 2605// In this example, the three-button navigation bar, status bar, and bottom navigation bar are not displayed. 2606// EntryAbility.ets 2607import { UIAbility } from '@kit.AbilityKit'; 2608import { BusinessError } from '@kit.BasicServicesKit'; 2609 2610export default class EntryAbility extends UIAbility { 2611 // ... 2612 onWindowStageCreate(windowStage: window.WindowStage): void { 2613 console.info('onWindowStageCreate'); 2614 let windowClass: window.Window | undefined = undefined; 2615 windowStage.getMainWindow((err: BusinessError, data) => { 2616 const errCode: number = err.code; 2617 if (errCode) { 2618 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2619 return; 2620 } 2621 windowClass = data; 2622 let names: Array<'status' | 'navigation'> = []; 2623 try { 2624 let promise = windowClass.setWindowSystemBarEnable(names); 2625 promise.then(() => { 2626 console.info('Succeeded in setting the system bar to be invisible.'); 2627 }).catch((err: BusinessError) => { 2628 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2629 }); 2630 } catch (exception) { 2631 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2632 } 2633 }); 2634 } 2635} 2636``` 2637 2638### setSpecificSystemBarEnabled<sup>11+</sup> 2639 2640setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise<void> 2641 2642Sets whether to show the three-button navigation bar, status bar, and bottom navigation bar of the main window. This API uses a promise to return the result. From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 2643 2644The return value does not indicate that the visibility changes of the three-button navigation bar, status bar, and bottom navigation bar have been fully executed. This API does not take effect when it is called by a child window. 2645 2646**System capability**: SystemCapability.Window.SessionManager 2647 2648**Atomic service API**: This API can be used in atomic services since API version 11. 2649 2650**Parameters** 2651 2652| Name| Type | Mandatory| Description| 2653| ----- | ---------------------------- | -- | --------------------------------- | 2654| name | [SpecificSystemBar](#specificsystembar11) | Yes| Type of the system bar to be shown or hidden.| 2655| enable | boolean | Yes| Whether to show the three-button navigation bar, status bar, and bottom navigation bar. The value **true** means to show them, and **false** means to hide them.| 2656| enableAnimation<sup>12+</sup> | boolean | No| Whether to enable animation when the three-button navigation bar, status bar, and bottom navigation bar status changes. The value **true** means to enable animation, and **false** means the opposite. The default value is **false**.| 2657 2658**Return value** 2659 2660| Type| Description| 2661| ------------------- | ------------------------ | 2662| Promise<void> | Promise that returns no value.| 2663 2664**Error codes** 2665 2666For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2667 2668| ID| Error Message| 2669| ------- | -------------------------------------------- | 2670| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2671| 1300002 | This window state is abnormal. | 2672| 1300003 | This window manager service works abnormally. | 2673 2674**Example** 2675 2676```ts 2677// Hide the bottom navigation bar. 2678// EntryAbility.ets 2679import { UIAbility } from '@kit.AbilityKit'; 2680import { BusinessError } from '@kit.BasicServicesKit'; 2681 2682export default class EntryAbility extends UIAbility { 2683 // ... 2684 onWindowStageCreate(windowStage: window.WindowStage): void { 2685 console.info('onWindowStageCreate'); 2686 let windowClass: window.Window | undefined = undefined; 2687 windowStage.getMainWindow((err: BusinessError, data) => { 2688 const errCode: number = err.code; 2689 if (errCode) { 2690 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2691 return; 2692 } 2693 windowClass = data; 2694 try { 2695 let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); 2696 promise.then(() => { 2697 console.info('Succeeded in setting the system bar to be invisible.'); 2698 }).catch((err: BusinessError) => { 2699 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2700 }); 2701 } catch (exception) { 2702 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2703 } 2704 }); 2705 } 2706} 2707``` 2708 2709### setWindowSystemBarProperties<sup>9+</sup> 2710 2711setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2712 2713Sets the properties of the three-button navigation bar and status bar of the main window. This API uses a promise to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 2714 2715This API does not take effect when it is called by a child window. 2716 2717**System capability**: SystemCapability.WindowManager.WindowManager.Core 2718 2719**Atomic service API**: This API can be used in atomic services since API version 12. 2720 2721**Parameters** 2722 2723| Name | Type | Mandatory| Description | 2724| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2725| systemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the three-button navigation bar and status bar.| 2726 2727**Return value** 2728 2729| Type | Description | 2730| ------------------- | ------------------------- | 2731| Promise<void> | Promise that returns no value.| 2732 2733**Error codes** 2734 2735For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2736 2737| ID| Error Message| 2738| ------- | -------------------------------------------- | 2739| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2740| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2741| 1300002 | This window state is abnormal. | 2742| 1300003 | This window manager service works abnormally. | 2743 2744**Example** 2745 2746```ts 2747// EntryAbility.ets 2748import { UIAbility } from '@kit.AbilityKit'; 2749import { BusinessError } from '@kit.BasicServicesKit'; 2750 2751export default class EntryAbility extends UIAbility { 2752 // ... 2753 onWindowStageCreate(windowStage: window.WindowStage): void { 2754 console.info('onWindowStageCreate'); 2755 let windowClass: window.Window | undefined = undefined; 2756 windowStage.getMainWindow((err: BusinessError, data) => { 2757 const errCode: number = err.code; 2758 if (errCode) { 2759 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2760 return; 2761 } 2762 windowClass = data; 2763 let SystemBarProperties: window.SystemBarProperties = { 2764 statusBarColor: '#ff00ff', 2765 navigationBarColor: '#00ff00', 2766 // The following properties are supported since API version 8. 2767 statusBarContentColor: '#ffffff', 2768 navigationBarContentColor: '#00ffff' 2769 }; 2770 try { 2771 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2772 promise.then(() => { 2773 console.info('Succeeded in setting the system bar properties.'); 2774 }).catch((err: BusinessError) => { 2775 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 2776 }); 2777 } catch (exception) { 2778 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 2779 } 2780 }); 2781 } 2782} 2783``` 2784 2785### getWindowSystemBarProperties<sup>12+</sup> 2786 2787getWindowSystemBarProperties(): SystemBarProperties 2788 2789Obtains the properties of the three-button navigation bar and status bar of the main window. 2790 2791**System capability**: SystemCapability.WindowManager.WindowManager.Core 2792 2793**Atomic service API**: This API can be used in atomic services since API version 12. 2794 2795**Return value** 2796 2797| Type| Description| 2798| ------------------------------------- | ------------- | 2799| [SystemBarProperties](#systembarproperties) | Properties of the three-button navigation bar and status bar.| 2800 2801**Error codes** 2802 2803For details about the error codes, see [Window Error Codes](errorcode-window.md). 2804 2805| ID| Error Message| 2806| ------- | ------------------------------ | 2807| 1300002 | This window state is abnormal. | 2808| 1300003 | This window manager service works abnormally. | 2809| 1300004 | Unauthorized operation. | 2810 2811 2812**Example** 2813 2814```ts 2815// EntryAbility.ets 2816import { UIAbility } from '@kit.AbilityKit'; 2817import { BusinessError } from '@kit.BasicServicesKit'; 2818 2819export default class EntryAbility extends UIAbility { 2820 // ... 2821 2822 onWindowStageCreate(windowStage: window.WindowStage) { 2823 let windowClass: window.Window | undefined = undefined; 2824 windowStage.getMainWindow((err: BusinessError, data) => { 2825 const errCode: number = err.code; 2826 if (errCode) { 2827 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2828 return; 2829 } 2830 windowClass = data; 2831 try { 2832 let systemBarProperty = windowClass.getWindowSystemBarProperties(); 2833 console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty)); 2834 } catch (err) { 2835 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2836 } 2837 }); 2838 } 2839}; 2840``` 2841 2842### setStatusBarColor<sup>16+</sup> 2843 2844setStatusBarColor(color: ColorMetrics): Promise<void> 2845 2846Sets the text color of the status bar in the main window. This API uses a promise to return the result. 2847 2848Setting the status bar text color is not supported for child windows. Calling this API on a child window will have no effect. 2849 2850**System capability**: SystemCapability.Window.SessionManager 2851 2852**Atomic service API**: This API can be used in atomic services since API version 16. 2853 2854**Parameters** 2855 2856| Name | Type | Mandatory| Description | 2857| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2858| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | Yes | Text color of the status bar.| 2859 2860**Return value** 2861 2862| Type | Description | 2863| ------------------- | ------------------------- | 2864| Promise<void> | Promise that returns no value.| 2865 2866**Error codes** 2867 2868For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2869 2870| ID| Error Message| 2871| ------- | -------------------------------------------- | 2872| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2873| 801 | Capability not supported on this device. | 2874| 1300002 | This window state is abnormal. | 2875| 1300003 | This window manager service works abnormally. | 2876 2877**Example** 2878 2879```ts 2880// EntryAbility.ets 2881import { UIAbility } from '@kit.AbilityKit'; 2882import { BusinessError } from '@kit.BasicServicesKit'; 2883import { ColorMetrics, window } from '@kit.ArkUI'; 2884 2885export default class EntryAbility extends UIAbility { 2886 // ... 2887 onWindowStageCreate(windowStage: window.WindowStage): void { 2888 console.info('onWindowStageCreate'); 2889 let windowClass: window.Window | undefined = undefined; 2890 windowStage.getMainWindow((err: BusinessError, data) => { 2891 const errCode: number = err.code; 2892 if (errCode) { 2893 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2894 return; 2895 } 2896 windowClass = data; 2897 try { 2898 let promise = windowClass.setStatusBarColor(ColorMetrics.numeric(0x112233)); 2899 promise.then(() => { 2900 console.info('Succeeded in setting the status bar color.'); 2901 }).catch((err: BusinessError) => { 2902 console.error(`Set the status bar color failed. Cause code: ${err.code}, message: ${err.message}`); 2903 }); 2904 } catch (exception) { 2905 console.error(`Failed to set the status bar color. Cause code: ${exception.code}, message: ${exception.message}`); 2906 } 2907 }); 2908 } 2909} 2910``` 2911 2912### getStatusBarProperty<sup>16+</sup> 2913 2914getStatusBarProperty(): StatusBarProperty 2915 2916Obtains the properties (for example, text color) of the status bar in the main window. 2917 2918Calling this API is not supported for child window and will cause error code 1300002. 2919 2920**System capability**: SystemCapability.Window.SessionManager 2921 2922**Atomic service API**: This API can be used in atomic services since API version 16. 2923 2924**Return value** 2925 2926| Type| Description| 2927| ------------------------------------- | ------------- | 2928| [StatusBarProperty](#statusbarproperty16) | Status bar properties, such as its color.| 2929 2930**Error codes** 2931 2932For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2933 2934| ID| Error Message| 2935| ------- | ------------------------------ | 2936| 801 | Capability not supported on this device. | 2937| 1300002 | This window state is abnormal. | 2938 2939**Example** 2940 2941```ts 2942// EntryAbility.ets 2943import { UIAbility } from '@kit.AbilityKit'; 2944import { BusinessError } from '@kit.BasicServicesKit'; 2945import { window } from '@kit.ArkUI'; 2946 2947export default class EntryAbility extends UIAbility { 2948 // ... 2949 onWindowStageCreate(windowStage: window.WindowStage) { 2950 let windowClass: window.Window | undefined = undefined; 2951 windowStage.getMainWindow((err: BusinessError, data) => { 2952 const errCode: number = err.code; 2953 if (errCode) { 2954 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2955 return; 2956 } 2957 windowClass = data; 2958 try { 2959 let statusBarProperty = windowClass.getStatusBarProperty(); 2960 console.info('Succeeded in obtaining system bar properties. Property: ' + JSON.stringify(statusBarProperty)); 2961 } catch (err) { 2962 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2963 } 2964 }); 2965 } 2966}; 2967``` 2968 2969### setPreferredOrientation<sup>9+</sup> 2970 2971setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2972 2973Sets the preferred orientation for the main window. This API uses an asynchronous callback to return the result. <!--RP9-->This API takes effect only on devices that support rotation with the sensor. It does not take effect on 2-in-1 devices or in the child window mode.<!--RP9End--> 2974 2975**System capability**: SystemCapability.WindowManager.WindowManager.Core 2976 2977**Atomic service API**: This API can be used in atomic services since API version 11. 2978 2979**Parameters** 2980 2981| Name | Type | Mandatory| Description | 2982| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2983| orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 2984| callback | AsyncCallback<void> | Yes | Callback used to return the result. The callback indicates the API call result. It does not mean that the application rotation animation ends.| 2985 2986**Error codes** 2987 2988For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2989 2990| ID| Error Message| 2991| ------- | ------------------------------ | 2992| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2993| 1300002 | This window state is abnormal. | 2994 2995**Example** 2996 2997```ts 2998// EntryAbility.ets 2999import { UIAbility } from '@kit.AbilityKit'; 3000import { BusinessError } from '@kit.BasicServicesKit'; 3001 3002export default class EntryAbility extends UIAbility { 3003 // ... 3004 onWindowStageCreate(windowStage: window.WindowStage): void { 3005 console.info('onWindowStageCreate'); 3006 let windowClass: window.Window | undefined = undefined; 3007 windowStage.getMainWindow((err: BusinessError, data) => { 3008 const errCode: number = err.code; 3009 if (errCode) { 3010 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3011 return; 3012 } 3013 windowClass = data; 3014 let orientation = window.Orientation.AUTO_ROTATION; 3015 try { 3016 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 3017 const errCode: number = err.code; 3018 if (errCode) { 3019 console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`); 3020 return; 3021 } 3022 console.info('Succeeded in setting window orientation.'); 3023 }); 3024 } catch (exception) { 3025 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3026 } 3027 }); 3028 } 3029} 3030``` 3031 3032### setPreferredOrientation<sup>9+</sup> 3033 3034setPreferredOrientation(orientation: Orientation): Promise<void> 3035 3036Sets the preferred orientation for the main window. This API uses a promise to return the result. <!--RP9-->This API takes effect only on devices that support rotation with the sensor. It does not take effect on 2-in-1 devices or in the child window mode.<!--RP9End--> 3037 3038**System capability**: SystemCapability.WindowManager.WindowManager.Core 3039 3040**Atomic service API**: This API can be used in atomic services since API version 11. 3041 3042**Parameters** 3043 3044| Name | Type | Mandatory| Description | 3045| ------------------- | ------------------------------------------- | ---- | ---------------------- | 3046| orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 3047 3048**Return value** 3049 3050| Type | Description | 3051| ------------------- | ------------------------- | 3052| Promise<void> | Promise that returns no value.| 3053 3054**Error codes** 3055 3056For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3057 3058| ID| Error Message| 3059| ------- | ------------------------------ | 3060| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3061| 1300002 | This window state is abnormal. | 3062 3063**Example** 3064 3065```ts 3066// EntryAbility.ets 3067import { UIAbility } from '@kit.AbilityKit'; 3068import { BusinessError } from '@kit.BasicServicesKit'; 3069 3070export default class EntryAbility extends UIAbility { 3071 // ... 3072 onWindowStageCreate(windowStage: window.WindowStage): void { 3073 console.info('onWindowStageCreate'); 3074 let windowClass: window.Window | undefined = undefined; 3075 windowStage.getMainWindow((err: BusinessError, data) => { 3076 const errCode: number = err.code; 3077 if (errCode) { 3078 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3079 return; 3080 } 3081 windowClass = data; 3082 let orientation = window.Orientation.AUTO_ROTATION; 3083 try { 3084 let promise = windowClass.setPreferredOrientation(orientation); 3085 promise.then(() => { 3086 console.info('Succeeded in setting the window orientation.'); 3087 }).catch((err: BusinessError) => { 3088 console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`); 3089 }); 3090 } catch (exception) { 3091 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3092 } 3093 }); 3094 } 3095} 3096``` 3097 3098### getPreferredOrientation<sup>12+</sup> 3099 3100getPreferredOrientation(): Orientation 3101 3102Obtains the orientation of the main window. This API can be called only by the main window. 3103 3104**System capability**: SystemCapability.WindowManager.WindowManager.Core 3105 3106**Atomic service API**: This API can be used in atomic services since API version 12. 3107 3108**Return value** 3109 3110| Type| Description| 3111|------------------------------| ------------------ | 3112| [Orientation](#orientation9) | Orientation.| 3113 3114**Error codes** 3115 3116For details about the error codes, see [Window Error Codes](errorcode-window.md). 3117 3118| ID| Error Message| 3119| ------- | ------------------------------ | 3120| 1300002 | This window state is abnormal. | 3121 3122**Example** 3123 3124```ts 3125// EntryAbility.ets 3126import { UIAbility } from '@kit.AbilityKit'; 3127import { BusinessError } from '@kit.BasicServicesKit'; 3128export default class EntryAbility extends UIAbility { 3129 // ... 3130 3131 onWindowStageCreate(windowStage: window.WindowStage) { 3132 console.info('onWindowStageCreate'); 3133 let windowClass: window.Window | undefined = undefined; 3134 windowStage.getMainWindow((err: BusinessError, data) => { 3135 const errCode: number = err.code; 3136 if (errCode) { 3137 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3138 return; 3139 } 3140 windowClass = data; 3141 try { 3142 let orientation = windowClass.getPreferredOrientation(); 3143 } catch (exception) { 3144 console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3145 } 3146 }); 3147 } 3148}; 3149``` 3150 3151### getUIContext<sup>10+</sup> 3152 3153getUIContext(): UIContext 3154 3155Obtain a **UIContext** instance. 3156 3157**Model restriction**: This API can be used only in the stage model. 3158 3159**System capability**: SystemCapability.WindowManager.WindowManager.Core 3160 3161**Atomic service API**: This API can be used in atomic services since API version 11. 3162 3163**Return value** 3164 3165| Type | Description | 3166| ---------- | ---------------------- | 3167| [UIContext](js-apis-arkui-UIContext.md#uicontext) | **UIContext** instance obtained.| 3168 3169**Error codes** 3170 3171For details about the error codes, see [Window Error Codes](errorcode-window.md). 3172 3173| ID| Error Message| 3174| ------- | ------------------------------ | 3175| 1300002 | This window state is abnormal. | 3176 3177**Example** 3178 3179```ts 3180// EntryAbility.ets 3181import { UIAbility } from '@kit.AbilityKit'; 3182import { window, UIContext } from '@kit.ArkUI'; 3183import { BusinessError } from '@kit.BasicServicesKit'; 3184 3185export default class EntryAbility extends UIAbility { 3186 onWindowStageCreate(windowStage: window.WindowStage) { 3187 // Load content for the main window. 3188 windowStage.loadContent("pages/page2", (err: BusinessError) => { 3189 let errCode: number = err.code; 3190 if (errCode) { 3191 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3192 return; 3193 } 3194 console.info('Succeeded in loading the content.'); 3195 // Obtain the main window. 3196 let windowClass: window.Window | undefined = undefined; 3197 windowStage.getMainWindow((err: BusinessError, data) => { 3198 let errCode: number = err.code; 3199 if (errCode) { 3200 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3201 return; 3202 } 3203 windowClass = data; 3204 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 3205 // Obtain a UIContext instance. 3206 let uiContext: UIContext | null = null; 3207 uiContext = windowClass.getUIContext(); 3208 }); 3209 }); 3210 } 3211}; 3212``` 3213 3214### setUIContent<sup>9+</sup> 3215 3216setUIContent(path: string, callback: AsyncCallback<void>): void 3217 3218Loads the content of a page, with its path in the current project specified, to this window. This API uses an asynchronous callback to return the result. 3219 3220**System capability**: SystemCapability.WindowManager.WindowManager.Core 3221 3222**Atomic service API**: This API can be used in atomic services since API version 11. 3223 3224**Parameters** 3225 3226| Name| Type| Mandatory| Description| 3227| -------- | ------------------------- | -- | -------------------- | 3228| path | string | Yes| Path of the page from which the content will be loaded. In the stage model, the path is configured in the **main_pages.json** file of the project. In the FA model, the path is configured in the **config.json** file of the project.| 3229| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3230 3231**Error codes** 3232 3233For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3234 3235| ID| Error Message| 3236| ------- | -------------------------------------------- | 3237| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3238| 1300002 | This window state is abnormal. | 3239| 1300003 | This window manager service works abnormally. | 3240 3241**Example** 3242 3243```ts 3244import { BusinessError } from '@kit.BasicServicesKit'; 3245 3246try { 3247 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 3248 const errCode: number = err.code; 3249 if (errCode) { 3250 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3251 return; 3252 } 3253 console.info('Succeeded in loading the content.'); 3254 }); 3255} catch (exception) { 3256 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3257} 3258``` 3259 3260### setUIContent<sup>9+</sup> 3261 3262setUIContent(path: string): Promise<void> 3263 3264Loads the content of a page, with its path in the current project specified, to this window. This API uses a promise to return the result. 3265 3266**System capability**: SystemCapability.WindowManager.WindowManager.Core 3267 3268**Atomic service API**: This API can be used in atomic services since API version 11. 3269 3270**Parameters** 3271 3272| Name| Type| Mandatory| Description| 3273| ---- | ------ | -- | ------------------ | 3274| path | string | Yes| Path of the page from which the content will be loaded. In the stage model, the path is configured in the **main_pages.json** file of the project. In the FA model, the path is configured in the **config.json** file of the project.| 3275 3276**Return value** 3277 3278| Type| Description| 3279| ------------------- | ------------------------ | 3280| Promise<void> | Promise that returns no value.| 3281 3282**Error codes** 3283 3284For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3285 3286| ID| Error Message| 3287| ------- | -------------------------------------------- | 3288| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3289| 1300002 | This window state is abnormal. | 3290| 1300003 | This window manager service works abnormally. | 3291 3292**Example** 3293 3294```ts 3295import { BusinessError } from '@kit.BasicServicesKit'; 3296 3297try { 3298 let promise = windowClass.setUIContent('pages/page2/page3'); 3299 promise.then(() => { 3300 console.info('Succeeded in loading the content.'); 3301 }).catch((err: BusinessError) => { 3302 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3303 }); 3304} catch (exception) { 3305 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3306} 3307``` 3308 3309### loadContent<sup>9+</sup> 3310 3311loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3312 3313Loads the content of a page, with its path in the current project specified, to this window, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 3314 3315**Model restriction**: This API can be used only in the stage model. 3316 3317**System capability**: SystemCapability.WindowManager.WindowManager.Core 3318 3319**Atomic service API**: This API can be used in atomic services since API version 11. 3320 3321**Parameters** 3322 3323| Name | Type | Mandatory| Description | 3324| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3325| path | string | Yes | Path of the page from which the content will be loaded. The path is configured in the **main_pages.json** file of the project.| 3326| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 3327| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 3328 3329**Error codes** 3330 3331For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3332 3333| ID| Error Message| 3334| ------- | -------------------------------------------- | 3335| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3336| 1300002 | This window state is abnormal. | 3337| 1300003 | This window manager service works abnormally. | 3338 3339**Example** 3340 3341```ts 3342import { BusinessError } from '@kit.BasicServicesKit'; 3343 3344let storage: LocalStorage = new LocalStorage(); 3345storage.setOrCreate('storageSimpleProp', 121); 3346windowClass.loadContent('pages/page2', storage, (err: BusinessError) => { 3347 const errCode: number = err.code; 3348 if (errCode) { 3349 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3350 return; 3351 } 3352 console.info('Succeeded in loading the content.'); 3353}); 3354``` 3355 3356### loadContent<sup>9+</sup> 3357 3358loadContent(path: string, storage: LocalStorage): Promise<void> 3359 3360Loads the content of a page, with its path in the current project specified, to this window, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 3361 3362**Model restriction**: This API can be used only in the stage model. 3363 3364**System capability**: SystemCapability.WindowManager.WindowManager.Core 3365 3366**Atomic service API**: This API can be used in atomic services since API version 11. 3367 3368**Parameters** 3369 3370| Name | Type | Mandatory| Description | 3371| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3372| path | string | Yes | Path of the page from which the content will be loaded. The path is configured in the **main_pages.json** file of the project.| 3373| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 3374 3375**Return value** 3376 3377| Type | Description | 3378| ------------------- | ------------------------- | 3379| Promise<void> | Promise that returns no value.| 3380 3381**Error codes** 3382 3383For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3384 3385| ID| Error Message| 3386| ------- | -------------------------------------------- | 3387| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3388| 1300002 | This window state is abnormal. | 3389| 1300003 | This window manager service works abnormally. | 3390 3391**Example** 3392 3393```ts 3394import { BusinessError } from '@kit.BasicServicesKit'; 3395 3396let storage: LocalStorage = new LocalStorage(); 3397storage.setOrCreate('storageSimpleProp', 121); 3398let promise = windowClass.loadContent('pages/page2', storage); 3399promise.then(() => { 3400 console.info('Succeeded in loading the content.'); 3401}).catch((err: BusinessError) => { 3402 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3403}); 3404``` 3405 3406### loadContentByName<sup>11+</sup> 3407 3408loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3409 3410Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 3411 3412**Model restriction**: This API can be used only in the stage model. 3413 3414**System capability**: SystemCapability.WindowManager.WindowManager.Core 3415 3416**Atomic service API**: This API can be used in atomic services since API version 11. 3417 3418**Parameters** 3419 3420| Name | Type | Mandatory| Description | 3421| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3422| name | string | Yes | Name of the named route page. | 3423| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 3424| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 3425 3426**Error codes** 3427 3428For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3429 3430| ID| Error Message | 3431| -------- | --------------------------------------------- | 3432| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3433| 1300002 | This window state is abnormal. | 3434| 1300003 | This window manager service works abnormally. | 3435 3436**Example** 3437<!--code_no_check--> 3438```ts 3439import { BusinessError } from '@kit.BasicServicesKit'; 3440import * as Index from '../pages/Index'; // Import the named route page. 3441 3442console.info('onWindowStageCreate'); 3443let storage: LocalStorage = new LocalStorage(); 3444storage.setOrCreate('storageSimpleProp', 121); 3445try { 3446 (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => { 3447 const errCode: number = err.code; 3448 if (errCode) { 3449 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3450 return; 3451 } 3452 console.info('Succeeded in loading the content.'); 3453 }); 3454} catch (exception) { 3455 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3456} 3457``` 3458<!--code_no_check--> 3459```ts 3460// ets/pages/Index.ets 3461export const entryName : string = 'Index'; 3462@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3463@Component 3464export struct Index { 3465 @State message: string = 'Hello World' 3466 build() { 3467 Row() { 3468 Column() { 3469 Text(this.message) 3470 .fontSize(50) 3471 .fontWeight(FontWeight.Bold) 3472 } 3473 .width('100%') 3474 } 3475 .height('100%') 3476 } 3477} 3478``` 3479 3480### loadContentByName<sup>11+</sup> 3481 3482loadContentByName(name: string, callback: AsyncCallback<void>): void 3483 3484Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 3485 3486**Model restriction**: This API can be used only in the stage model. 3487 3488**System capability**: SystemCapability.WindowManager.WindowManager.Core 3489 3490**Atomic service API**: This API can be used in atomic services since API version 11. 3491 3492**Parameters** 3493 3494| Name | Type | Mandatory| Description | 3495| -------- | ------------------------- | ---- | ---------------- | 3496| name | string | Yes | Name of the named route page.| 3497| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 3498 3499**Error codes** 3500 3501For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3502 3503| ID| Error Message | 3504| -------- | --------------------------------------------- | 3505| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3506| 1300002 | This window state is abnormal. | 3507| 1300003 | This window manager service works abnormally. | 3508 3509**Example** 3510<!--code_no_check--> 3511```ts 3512import { BusinessError } from '@kit.BasicServicesKit'; 3513import * as Index from '../pages/Index'; // Import the named route page. 3514 3515try { 3516 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 3517 const errCode: number = err.code; 3518 if (errCode) { 3519 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3520 return; 3521 } 3522 console.info('Succeeded in loading the content.'); 3523 }); 3524} catch (exception) { 3525 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3526} 3527``` 3528<!--code_no_check--> 3529```ts 3530// ets/pages/Index.ets 3531export const entryName : string = 'Index'; 3532@Entry({routeName: entryName}) 3533@Component 3534export struct Index { 3535 @State message: string = 'Hello World' 3536 build() { 3537 Row() { 3538 Column() { 3539 Text(this.message) 3540 .fontSize(50) 3541 .fontWeight(FontWeight.Bold) 3542 } 3543 .width('100%') 3544 } 3545 .height('100%') 3546 } 3547} 3548``` 3549 3550### loadContentByName<sup>11+</sup> 3551 3552loadContentByName(name: string, storage?: LocalStorage): Promise<void> 3553 3554Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 3555 3556**Model restriction**: This API can be used only in the stage model. 3557 3558**System capability**: SystemCapability.WindowManager.WindowManager.Core 3559 3560**Atomic service API**: This API can be used in atomic services since API version 11. 3561 3562**Parameters** 3563 3564| Name | Type | Mandatory| Description | 3565| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3566| name | string | Yes | Name of the named route page. | 3567| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | No | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 3568 3569**Return value** 3570 3571| Type | Description | 3572| ------------------- | ------------------------- | 3573| Promise<void> | Promise that returns no value.| 3574 3575**Error codes** 3576 3577For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3578 3579| ID| Error Message | 3580| -------- | --------------------------------------------- | 3581| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3582| 1300002 | This window state is abnormal. | 3583| 1300003 | This window manager service works abnormally. | 3584 3585**Example** 3586<!--code_no_check--> 3587```ts 3588import { BusinessError } from '@kit.BasicServicesKit'; 3589import * as Index from '../pages/Index'; // Import the named route page. 3590 3591let storage: LocalStorage = new LocalStorage(); 3592storage.setOrCreate('storageSimpleProp', 121); 3593try { 3594 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 3595 promise.then(() => { 3596 console.info('Succeeded in loading the content.'); 3597 }).catch((err: BusinessError) => { 3598 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3599 }); 3600} catch (exception) { 3601 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3602} 3603``` 3604<!--code_no_check--> 3605```ts 3606// ets/pages/Index.ets 3607export const entryName : string = 'Index'; 3608@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3609@Component 3610export struct Index { 3611 @State message: string = 'Hello World' 3612 build() { 3613 Row() { 3614 Column() { 3615 Text(this.message) 3616 .fontSize(50) 3617 .fontWeight(FontWeight.Bold) 3618 } 3619 .width('100%') 3620 } 3621 .height('100%') 3622 } 3623} 3624``` 3625 3626### isWindowShowing<sup>9+</sup> 3627 3628isWindowShowing(): boolean 3629 3630Checks whether this window is displayed. 3631 3632**System capability**: SystemCapability.WindowManager.WindowManager.Core 3633 3634**Atomic service API**: This API can be used in atomic services since API version 11. 3635 3636**Return value** 3637 3638| Type| Description| 3639| ------- | ------------------------------------------------------------------ | 3640| boolean | Whether the window is displayed. The value **true** means that the window is displayed, and **false** means the opposite.| 3641 3642**Error codes** 3643 3644For details about the error codes, see [Window Error Codes](errorcode-window.md). 3645 3646| ID| Error Message| 3647| ------- | ------------------------------ | 3648| 1300002 | This window state is abnormal. | 3649 3650**Example** 3651 3652```ts 3653try { 3654 let data = windowClass.isWindowShowing(); 3655 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3656} catch (exception) { 3657 console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`); 3658} 3659``` 3660 3661### on('windowSizeChange')<sup>7+</sup> 3662 3663on(type: 'windowSizeChange', callback: Callback<Size>): void 3664 3665Subscribes to the window size change event. 3666 3667**System capability**: SystemCapability.WindowManager.WindowManager.Core 3668 3669**Atomic service API**: This API can be used in atomic services since API version 11. 3670 3671**Parameters** 3672 3673| Name | Type | Mandatory| Description | 3674| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3675| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 3676| callback | Callback<[Size](#size7)> | Yes | Callback used to return the window size. | 3677 3678**Error codes** 3679 3680For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3681 3682| ID| Error Message| 3683| ------- | -------------------------------------------- | 3684| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3685 3686**Example** 3687 3688```ts 3689try { 3690 windowClass.on('windowSizeChange', (data) => { 3691 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3692 }); 3693} catch (exception) { 3694 console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3695} 3696``` 3697 3698### off('windowSizeChange')<sup>7+</sup> 3699 3700off(type: 'windowSizeChange', callback?: Callback<Size>): void 3701 3702Unsubscribes from the window size change event. 3703 3704**System capability**: SystemCapability.WindowManager.WindowManager.Core 3705 3706**Atomic service API**: This API can be used in atomic services since API version 11. 3707 3708**Parameters** 3709 3710| Name | Type | Mandatory| Description | 3711| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3712| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 3713| callback | Callback<[Size](#size7)> | No | Callback used to return the window size. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3714 3715**Error codes** 3716 3717For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3718 3719| ID| Error Message| 3720| ------- | -------------------------------------------- | 3721| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3722 3723**Example** 3724 3725```ts 3726const callback = (size: window.Size) => { 3727 // ... 3728} 3729try { 3730 // Enable listening through the on API. 3731 windowClass.on('windowSizeChange', callback); 3732 // Disable the listening of a specified callback. 3733 windowClass.off('windowSizeChange', callback); 3734 // Unregister all the callbacks that have been registered through on(). 3735 windowClass.off('windowSizeChange'); 3736} catch (exception) { 3737 console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3738} 3739``` 3740 3741### on('avoidAreaChange')<sup>9+</sup> 3742 3743on(type: 'avoidAreaChange', callback: Callback<AvoidAreaOptions>): void 3744 3745Subscribes to the event indicating changes to the area where this window cannot be displayed. 3746<!--RP7-->Common scenarios for triggering this event are as follows: transitions between full-screen mode, floating mode, and split-screen mode of the application window; rotation of the application window; transitions between folded and unfolded states of a foldable device; transfer of the application window between multiple devices.<!--RP7End--> 3747 3748**System capability**: SystemCapability.WindowManager.WindowManager.Core 3749 3750**Atomic service API**: This API can be used in atomic services since API version 11. 3751 3752**Parameters** 3753 3754| Name | Type | Mandatory| Description | 3755| -------- |----------------------------------| ---- |--------------------------------------| 3756| type | string | Yes | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed.| 3757| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | Yes | Callback used to return the area and area type.| 3758 3759**Error codes** 3760 3761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3762 3763| ID| Error Message| 3764| ------- | -------------------------------------------- | 3765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3766 3767**Example** 3768 3769```ts 3770try { 3771 windowClass.on('avoidAreaChange', (data) => { 3772 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3773 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3774 }); 3775} catch (exception) { 3776 console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3777} 3778``` 3779 3780### off('avoidAreaChange')<sup>9+</sup> 3781 3782off(type: 'avoidAreaChange', callback?: Callback<AvoidAreaOptions>): void 3783 3784Unsubscribes from the event indicating changes to the area where this window cannot be displayed. 3785 3786**System capability**: SystemCapability.WindowManager.WindowManager.Core 3787 3788**Atomic service API**: This API can be used in atomic services since API version 11. 3789 3790**Parameters** 3791 3792| Name | Type | Mandatory| Description | 3793| -------- |----------------------------------|------|------------------------------------| 3794| type | string | Yes | Event type. The value is fixed at **'avoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed.| 3795| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | No | Callback used to return the area and area type. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 3796 3797**Error codes** 3798 3799For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3800 3801| ID| Error Message| 3802| ------- | -------------------------------------------- | 3803| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 3804 3805**Example** 3806 3807```ts 3808interface Param { 3809 type: window.AvoidAreaType, 3810 area: window.AvoidArea 3811} 3812const callback = (data: Param) => { 3813 // ... 3814} 3815try { 3816 windowClass.on('avoidAreaChange', callback); 3817 3818 windowClass.off('avoidAreaChange', callback); 3819 // Unregister all the callbacks that have been registered through on(). 3820 windowClass.off('avoidAreaChange'); 3821} catch (exception) { 3822 console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3823} 3824``` 3825 3826### on('keyboardHeightChange')<sup>7+</sup> 3827 3828on(type: 'keyboardHeightChange', callback: Callback<number>): void 3829 3830Subscribes to the event indicating soft keyboard height changes in fixed state. 3831 3832The system notifies the keyboard height change when the soft keyboard is invoked by the window and overlaps with the window. 3833 3834Since API version 10, the soft keyboard can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3835 3836**Atomic service API**: This API can be used in atomic services since API version 12. 3837 3838**System capability**: SystemCapability.WindowManager.WindowManager.Core 3839 3840**Parameters** 3841 3842| Name | Type | Mandatory| Description | 3843| -------- | ------------------- | ---- |-------------------------------------------| 3844| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 3845| callback | Callback<number> | Yes | Callback used to return the current keyboard height, which is an integer, in px. | 3846 3847**Error codes** 3848 3849For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3850 3851| ID| Error Message| 3852| ------- | -------------------------------------------- | 3853| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3854 3855**Example** 3856 3857```ts 3858import { BusinessError } from '@kit.BasicServicesKit'; 3859 3860try { 3861 windowClass.on('keyboardHeightChange', (data) => { 3862 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3863 }); 3864} catch (exception) { 3865 console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3866} 3867``` 3868 3869### off('keyboardHeightChange')<sup>7+</sup> 3870 3871off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3872 3873Unsubscribes from the event indicating soft keyboard height changes in fixed state. 3874 3875Since API version 10, the soft keyboard can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3876 3877**Atomic service API**: This API can be used in atomic services since API version 12. 3878 3879**System capability**: SystemCapability.WindowManager.WindowManager.Core 3880 3881**Parameters** 3882 3883| Name | Type | Mandatory| Description | 3884| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3885| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 3886| callback | Callback<number> | No | Callback used to return the current keyboard height, which is an integer, in px. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3887 3888**Error codes** 3889 3890For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3891 3892| ID| Error Message| 3893| ------- | -------------------------------------------- | 3894| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3895 3896**Example** 3897 3898```ts 3899import { BusinessError } from '@kit.BasicServicesKit'; 3900 3901const callback = (height: number) => { 3902 // ... 3903} 3904try { 3905 windowClass.on('keyboardHeightChange', callback); 3906 3907 windowClass.off('keyboardHeightChange', callback); 3908 // Unregister all the callbacks that have been registered through on(). 3909 windowClass.off('keyboardHeightChange'); 3910} catch (exception) { 3911 console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3912} 3913``` 3914 3915### on('touchOutside')<sup>11+</sup> 3916 3917on(type: 'touchOutside', callback: Callback<void>): void 3918 3919Subscribes to the touch event outside this window. 3920 3921**System capability**: SystemCapability.WindowManager.WindowManager.Core 3922 3923**Atomic service API**: This API can be used in atomic services since API version 11. 3924 3925**Parameters** 3926 3927| Name | Type | Mandatory| Description | 3928| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3929| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the touch event outside this window.| 3930| callback | Callback<void> | Yes | Callback used to return the touch event outside this window. | 3931 3932**Error codes** 3933 3934For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3935 3936| ID| Error Message| 3937| ------- | -------------------------------------------- | 3938| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3939 3940**Example** 3941 3942```ts 3943try { 3944 windowClass.on('touchOutside', () => { 3945 console.info('touch outside'); 3946 }); 3947} catch (exception) { 3948 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3949} 3950``` 3951 3952### off('touchOutside')<sup>11+</sup> 3953 3954off(type: 'touchOutside', callback?: Callback<void>): void 3955 3956Unsubscribes from the touch event outside this window. 3957 3958**System capability**: SystemCapability.WindowManager.WindowManager.Core 3959 3960**Atomic service API**: This API can be used in atomic services since API version 11. 3961 3962**Parameters** 3963 3964| Name | Type | Mandatory| Description | 3965| -------- |----------------------| ---- |--------------------------------------| 3966| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the touch event outside this window.| 3967| callback | Callback<void> | No | Callback used to return the touch event outside this window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3968 3969**Error codes** 3970 3971For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3972 3973| ID| Error Message| 3974| ------- | -------------------------------------------- | 3975| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3976 3977**Example** 3978 3979```ts 3980const callback = () => { 3981 // ... 3982} 3983try { 3984 windowClass.on('touchOutside', callback); 3985 windowClass.off('touchOutside', callback); 3986 // Unregister all the callbacks that have been registered through on(). 3987 windowClass.off('touchOutside'); 3988} catch (exception) { 3989 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3990} 3991``` 3992 3993### on('screenshot')<sup>9+</sup> 3994 3995on(type: 'screenshot', callback: Callback<void>): void 3996 3997Subscribes to the screenshot event. 3998 3999**Atomic service API**: This API can be used in atomic services since API version 12. 4000 4001**System capability**: SystemCapability.WindowManager.WindowManager.Core 4002 4003**Parameters** 4004 4005| Name | Type | Mandatory| Description | 4006| -------- | ------------------- | ---- | ------------------------------------------------------------ | 4007| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event, which can be initiated from the Control Panel, by running hdc commands, or by calling the screenshot interfaces.| 4008| callback | Callback<void> | Yes | Callback invoked when a screenshot event occurs. | 4009 4010**Error codes** 4011 4012For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4013 4014| ID| Error Message| 4015| ------- | -------------------------------------------- | 4016| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4017 4018**Example** 4019 4020```ts 4021try { 4022 windowClass.on('screenshot', () => { 4023 console.info('screenshot happened'); 4024 }); 4025} catch (exception) { 4026 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4027} 4028``` 4029 4030### off('screenshot')<sup>9+</sup> 4031 4032off(type: 'screenshot', callback?: Callback<void>): void 4033 4034Unsubscribes from the screenshot event. 4035 4036**Atomic service API**: This API can be used in atomic services since API version 12. 4037 4038**System capability**: SystemCapability.WindowManager.WindowManager.Core 4039 4040**Parameters** 4041 4042| Name | Type | Mandatory| Description | 4043| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4044| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 4045| callback | Callback<void> | No | Callback invoked when a screenshot event occurs. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4046 4047**Error codes** 4048 4049For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4050 4051| ID| Error Message| 4052| ------- | -------------------------------------------- | 4053| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4054 4055**Example** 4056 4057```ts 4058let callback = () => { 4059 console.info('screenshot happened'); 4060}; 4061try { 4062 windowClass.on('screenshot', callback); 4063 windowClass.off('screenshot', callback); 4064 // Unregister all the callbacks that have been registered through on(). 4065 windowClass.off('screenshot'); 4066} catch (exception) { 4067 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4068} 4069``` 4070 4071### on('dialogTargetTouch')<sup>10+</sup> 4072 4073on(type: 'dialogTargetTouch', callback: Callback<void>): void 4074 4075Subscribes to click or touch events in a window covered by a modal window. This API takes effect only when it is called by a modal window. 4076 4077**Atomic service API**: This API can be used in atomic services since API version 12. 4078 4079**System capability**: SystemCapability.WindowManager.WindowManager.Core 4080 4081**Parameters** 4082 4083| Name | Type | Mandatory| Description | 4084| -------- | ------------------- | ---- | ------------------------------------------------------------ | 4085| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click or touch event in a window covered by a modal window.| 4086| callback | Callback<void>| Yes | Callback invoked when a click or touch event occurs in the window covered by the modal window.| 4087 4088**Error codes** 4089 4090For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4091 4092| ID| Error Message| 4093| ------- | -------------------------------------------- | 4094| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4095 4096**Example** 4097 4098```ts 4099try { 4100 windowClass.on('dialogTargetTouch', () => { 4101 console.info('touch dialog target'); 4102 }); 4103} catch (exception) { 4104 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4105} 4106``` 4107 4108### off('dialogTargetTouch')<sup>10+</sup> 4109 4110off(type: 'dialogTargetTouch', callback?: Callback<void>): void 4111 4112Unsubscribes from the touch event of the target window in the modal window mode. 4113 4114**Atomic service API**: This API can be used in atomic services since API version 12. 4115 4116**System capability**: SystemCapability.WindowManager.WindowManager.Core 4117 4118**Parameters** 4119 4120| Name | Type | Mandatory| Description | 4121| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4122| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the touch event of the target window in the modal window mode.| 4123| callback | Callback<void> | No | Callback invoked when the touch event occurs in the target window of the modal window mode. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4124 4125**Error codes** 4126 4127For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4128 4129| ID| Error Message| 4130| ------- | -------------------------------------------- | 4131| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4132 4133**Example** 4134 4135```ts 4136const callback = () => { 4137 // ... 4138} 4139try { 4140 windowClass.on('dialogTargetTouch', callback); 4141 windowClass.off('dialogTargetTouch', callback); 4142 // Unregister all the callbacks that have been registered through on(). 4143 windowClass.off('dialogTargetTouch'); 4144} catch (exception) { 4145 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4146} 4147``` 4148 4149### on('windowEvent')<sup>10+</sup> 4150 4151on(type: 'windowEvent', callback: Callback<WindowEventType>): void 4152 4153Subscribes to the window lifecycle change event. 4154 4155**System capability**: SystemCapability.WindowManager.WindowManager.Core 4156 4157**Atomic service API**: This API can be used in atomic services since API version 11. 4158 4159**Parameters** 4160 4161| Name | Type | Mandatory| Description | 4162| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 4163| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 4164| callback | Callback<[WindowEventType](#windoweventtype10)> | Yes | Callback used to return the window lifecycle state. | 4165 4166**Error codes** 4167 4168For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4169 4170| ID| Error Message| 4171| ------- | -------------------------------------------- | 4172| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4173 4174**Example** 4175 4176```ts 4177try { 4178 windowClass.on('windowEvent', (data) => { 4179 console.info('Window event happened. Event:' + JSON.stringify(data)); 4180 }); 4181} catch (exception) { 4182 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4183} 4184``` 4185 4186### off('windowEvent')<sup>10+</sup> 4187 4188off(type: 'windowEvent', callback?: Callback<WindowEventType>): void 4189 4190Unsubscribes from the window lifecycle change event. 4191 4192**System capability**: SystemCapability.WindowManager.WindowManager.Core 4193 4194**Atomic service API**: This API can be used in atomic services since API version 11. 4195 4196**Parameters** 4197 4198| Name | Type | Mandatory| Description | 4199| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 4200| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 4201| callback | Callback<[WindowEventType](#windoweventtype10)> | No | Callback used to return the window lifecycle state. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 4202 4203**Error codes** 4204 4205For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4206 4207| ID| Error Message| 4208| ------- | -------------------------------------------- | 4209| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4210 4211**Example** 4212 4213```ts 4214const callback = (windowEventType: window.WindowEventType) => { 4215 // ... 4216} 4217try { 4218 // Enable listening through the on API. 4219 windowClass.on('windowEvent', callback); 4220 // Disable the listening of a specified callback. 4221 windowClass.off('windowEvent', callback); 4222 // Unregister all the callbacks that have been registered through on(). 4223 windowClass.off('windowEvent'); 4224} catch (exception) { 4225 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4226} 4227``` 4228 4229### on('displayIdChange')<sup>14+</sup> 4230 4231on(type: 'displayIdChange', callback: Callback<number>): void 4232 4233Subscribes to the display change event of this window. For example, this event is triggered when the window is moved to a different display. 4234 4235**Atomic service API**: This API can be used in atomic services since API version 14. 4236 4237**System capability**: SystemCapability.Window.SessionManager 4238 4239**Parameters** 4240 4241| Name | Type | Mandatory| Description | 4242| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4243| type | string | Yes | Event type. The value is fixed at **'displayIdChange'**, indicating the display change event.| 4244| callback | Callback<number> | Yes | Callback invoked when the display where the window is located changes. The callback contains a parameter of the number type, indicating the new display ID. | 4245 4246**Error codes** 4247 4248For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4249 4250| ID| Error Message| 4251| ------- | ------------------------------ | 4252| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4253| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4254| 1300002 | This window state is abnormal. | 4255 4256**Example** 4257 4258```ts 4259try { 4260 windowClass.on('displayIdChange', (data) => { 4261 console.info('Window displayId changed, displayId=' + JSON.stringify(data)); 4262 }); 4263} catch (exception) { 4264 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4265} 4266``` 4267### off('displayIdChange')<sup>14+</sup> 4268 4269off(type: 'displayIdChange', callback?: Callback<number>): void 4270 4271Unsubscribes from the display change event of this window. 4272 4273**Atomic service API**: This API can be used in atomic services since API version 14. 4274 4275**System capability**: SystemCapability.Window.SessionManager 4276 4277**Parameters** 4278 4279| Name | Type | Mandatory| Description | 4280| -------- |----------------------------| ---- |--------------------------------------| 4281| type | string | Yes | Event type. The value is fixed at **'displayIdChange'**, indicating the display change event.| 4282| callback | Callback<number> | No | Callback invoked when the display where the window is located changes. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 4283 4284**Error codes** 4285 4286For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4287 4288| ID| Error Message| 4289| ------- | ------------------------------ | 4290| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4291| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4292| 1300002 | This window state is abnormal. | 4293 4294**Example** 4295 4296```ts 4297const callback = (displayId: number) => { 4298 // ... 4299} 4300try { 4301 // Enable listening through the on API. 4302 windowClass.on('displayIdChange', callback); 4303 // Disable the listening of a specified callback. 4304 windowClass.off('displayIdChange', callback); 4305 // Unregister all the callbacks that have been registered through on(). 4306 windowClass.off('displayIdChange'); 4307} catch (exception) { 4308 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4309} 4310``` 4311 4312### on('windowVisibilityChange')<sup>11+</sup> 4313 4314on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 4315 4316Subscribes to the visibility status change event of this window. 4317 4318**Atomic service API**: This API can be used in atomic services since API version 12. 4319 4320**System capability**: SystemCapability.Window.SessionManager 4321 4322**Parameters** 4323 4324| Name | Type | Mandatory| Description | 4325| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4326| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 4327| callback | Callback<boolean> | Yes | Callback used to return the visibility status of the window, which is a Boolean value. The value **true** means that the window is visible, and **false** means the opposite. | 4328 4329**Error codes** 4330 4331For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4332 4333| ID| Error Message| 4334| ------- | ------------------------------ | 4335| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4336| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4337| 1300002 | This window state is abnormal. | 4338| 1300003 | This window manager service works abnormally. | 4339 4340**Example** 4341 4342```ts 4343try { 4344 windowClass.on('windowVisibilityChange', (boolean) => { 4345 console.info('Window visibility changed, isVisible=' + boolean); 4346 }); 4347} catch (exception) { 4348 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4349} 4350``` 4351 4352### off('windowVisibilityChange')<sup>11+</sup> 4353 4354off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 4355 4356Unsubscribes from the visibility status change event of this window. 4357 4358**Atomic service API**: This API can be used in atomic services since API version 12. 4359 4360**System capability**: SystemCapability.Window.SessionManager 4361 4362**Parameters** 4363 4364| Name | Type | Mandatory| Description | 4365| -------- |----------------------------| ---- |--------------------------------------| 4366| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 4367| callback | Callback<boolean> | No | Callback used to return the visibility status of the window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 4368 4369**Error codes** 4370 4371For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4372 4373| ID| Error Message| 4374| ------- | ------------------------------ | 4375| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4376| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4377| 1300002 | This window state is abnormal. | 4378| 1300003 | This window manager service works abnormally. | 4379 4380**Example** 4381 4382```ts 4383const callback = (bool: boolean) => { 4384 // ... 4385} 4386try { 4387 // Enable listening through the on API. 4388 windowClass.on('windowVisibilityChange', callback); 4389 // Disable the listening of a specified callback. 4390 windowClass.off('windowVisibilityChange', callback); 4391 // Unregister all the callbacks that have been registered through on(). 4392 windowClass.off('windowVisibilityChange'); 4393} catch (exception) { 4394 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4395} 4396``` 4397 4398### on('systemDensityChange')<sup>15+</sup> 4399 4400on(type: 'systemDensityChange', callback: Callback<number>): void 4401 4402Subscribes to the system density change event, which is triggered when the system's display size scale factor changes for the screen where the window is located. 4403 4404**Atomic service API**: This API can be used in atomic services since API version 15. 4405 4406**System capability**: SystemCapability.Window.SessionManager 4407 4408**Parameters** 4409 4410| Name | Type | Mandatory| Description | 4411| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4412| type | string | Yes | Event type. The value is fixed at **'systemDensityChange'**, indicating the system density change event.| 4413| callback | Callback<number> | Yes | Callback invoked when the system's display size scale factor changes. The callback contains a parameter of the number type, indicating the new scale factor. | 4414 4415**Error codes** 4416 4417 4418For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4419 4420| ID| Error Message| 4421| ------- | ------------------------------ | 4422| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4423| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4424| 1300002 | This window state is abnormal. | 4425 4426**Example** 4427 4428```ts 4429const callback = (density: number) => { 4430 console.info('System density changed, density=' + JSON.stringify(density)); 4431} 4432try { 4433 windowClass.on('systemDensityChange', callback); 4434} catch (exception) { 4435 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4436} 4437``` 4438### off('systemDensityChange')<sup>15+</sup> 4439 4440off(type: 'systemDensityChange', callback?: Callback<number>): void 4441 4442Unsubscribes from the system density change event. 4443 4444**Atomic service API**: This API can be used in atomic services since API version 15. 4445 4446**System capability**: SystemCapability.Window.SessionManager 4447 4448**Parameters** 4449 4450| Name | Type | Mandatory| Description | 4451| -------- |----------------------------| ---- |--------------------------------------| 4452| type | string | Yes | Event type. The value is fixed at **'systemDensityChange'**, indicating the system density change event.| 4453| callback | Callback<number> | No | Callback invoked when the system's display size scale factor changes. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 4454 4455**Error codes** 4456 4457For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4458 4459| ID| Error Message| 4460| ------- | ------------------------------ | 4461| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4462| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4463| 1300002 | This window state is abnormal. | 4464 4465**Example** 4466 4467```ts 4468const callback = (density: number) => { 4469 // ... 4470} 4471try { 4472 // Enable listening through the on API. 4473 windowClass.on('systemDensityChange', callback); 4474 // Disable the listening of a specified callback. 4475 windowClass.off('systemDensityChange', callback); 4476 // Unregister all the callbacks that have been registered through on(). 4477 windowClass.off('systemDensityChange'); 4478} catch (exception) { 4479 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4480} 4481``` 4482 4483### on('noInteractionDetected')<sup>12+</sup> 4484 4485on(type: 'noInteractionDetected', timeout: number, callback: Callback<void>): void 4486 4487Subscribes to non-interaction events in a window within the specified period. 4488 4489Interaction events include physical keyboard input events and screen touch/click events, but not soft keyboard input events. 4490 4491**Atomic service API**: This API can be used in atomic services since API version 12. 4492 4493**System capability**: SystemCapability.Window.SessionManager 4494 4495**Parameters** 4496 4497| Name | Type | Mandatory| Description | 4498| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4499| type | string | Yes | Event type. The value is fixed at **'noInteractionDetected'**, indicating that there is no interaction event in the window within the specified period.| 4500| timeout | number | Yes | Period during which no interaction is performed, in seconds. The value must be an integer. Negative numbers and decimals are invalid.| 4501| callback | Callback<void> | Yes | Callback invoked when there is no interaction event in the current window within the specified period. | 4502 4503**Error codes** 4504 4505For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4506 4507| ID| Error Message| 4508| ------- | ------------------------------ | 4509| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4510| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4511| 1300002 | This window state is abnormal. | 4512| 1300003 | This window manager service works abnormally. | 4513 4514**Example** 4515 4516```ts 4517try { 4518 windowClass.on('noInteractionDetected', 60, () => { 4519 console.info('no interaction in 60s'); 4520 }); 4521} catch (exception) { 4522 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4523} 4524``` 4525 4526### off('noInteractionDetected')<sup>12+</sup> 4527 4528off(type: 'noInteractionDetected', callback?: Callback<void>): void 4529 4530Unsubscribes from non-interaction events in a window within the specified period. 4531 4532Interaction events include physical keyboard input events and screen touch/click events, but not soft keyboard input events. 4533 4534**Atomic service API**: This API can be used in atomic services since API version 12. 4535 4536**System capability**: SystemCapability.Window.SessionManager 4537 4538**Parameters** 4539 4540| Name | Type | Mandatory| Description | 4541| -------- |----------------------------| ---- |--------------------------------------| 4542| type | string | Yes | Event type. The value is fixed at **'noInteractionDetected'**, indicating that there is no interaction event in the window within the specified period.| 4543| callback | Callback<void> | No | Callback invoked when there is no interaction event in the current window within the specified period. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4544 4545**Error codes** 4546 4547For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4548 4549| ID| Error Message| 4550| ------- | ------------------------------ | 4551| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4552| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4553| 1300002 | This window state is abnormal. | 4554| 1300003 | This window manager service works abnormally. | 4555 4556**Example** 4557 4558```ts 4559const callback = () => { 4560 // ... 4561} 4562try { 4563 windowClass.on('noInteractionDetected', 60, callback); 4564 windowClass.off('noInteractionDetected', callback); 4565 // Unregister all the callbacks that have been registered through on(). 4566 windowClass.off('noInteractionDetected'); 4567} catch (exception) { 4568 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4569} 4570``` 4571 4572### on('windowStatusChange')<sup>11+</sup> 4573 4574on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 4575 4576Subscribes to the window status change event. A notification is sent when the window status changes (the window properties may not be updated). 4577 4578**Atomic service API**: This API can be used in atomic services since API version 12. 4579 4580**System capability**: SystemCapability.Window.SessionManager 4581 4582**Parameters** 4583 4584| Name | Type | Mandatory| Description | 4585| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4586| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 4587| callback | Callback<[WindowStatusType](#windowstatustype11)> | Yes | Callback used to return the window status. | 4588 4589**Error codes** 4590 4591For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4592 4593| ID| Error Message| 4594| ------- | ------------------------------ | 4595| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4596| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4597 4598**Example** 4599 4600```ts 4601try { 4602 windowClass.on('windowStatusChange', (WindowStatusType) => { 4603 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 4604 }); 4605} catch (exception) { 4606 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4607} 4608``` 4609 4610### off('windowStatusChange')<sup>11+</sup> 4611 4612off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 4613 4614Unsubscribes from the window status change event. 4615 4616**Atomic service API**: This API can be used in atomic services since API version 12. 4617 4618**System capability**: SystemCapability.Window.SessionManager 4619 4620**Parameters** 4621 4622| Name | Type | Mandatory| Description | 4623| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 4624| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 4625| callback | Callback<[WindowStatusType](#windowstatustype11)> | No | Callback used to return the window status. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 4626 4627**Error codes** 4628 4629For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4630 4631| ID| Error Message| 4632| ------- | ------------------------------ | 4633| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4634| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4635 4636**Example** 4637 4638```ts 4639const callback = (windowStatusType: window.WindowStatusType) => { 4640 // ... 4641} 4642try { 4643 windowClass.on('windowStatusChange', callback); 4644 windowClass.off('windowStatusChange', callback); 4645 // Unregister all the callbacks that have been registered through on(). 4646 windowClass.off('windowStatusChange'); 4647} catch (exception) { 4648 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4649} 4650``` 4651 4652### setWindowGrayScale<sup>12+</sup> 4653 4654setWindowGrayScale(grayScale: number): Promise<void> 4655 4656Sets the grayscale effect for this window. This API uses a promise to return the result. This API can be called only after [loadContent()](#loadcontent9) or [setUIContent()](#setuicontent9) is called. 4657 4658**Atomic service API**: This API can be used in atomic services since API version 12. 4659 4660**System capability**: SystemCapability.Window.SessionManager 4661 4662**Parameters** 4663 4664| Name| Type| Mandatory| Description | 4665| --------- | ------ | -- | ---------------------------------------- | 4666| grayScale | number | Yes| Grayscale of the window. The value is a floating point number in the range [0.0, 1.0]. The value **0.0** means that the window image does not change, and **1.0** means that the window image is completely turned into grayscale. The effect changes linearly between 0.0 and 1.0.| 4667 4668**Return value** 4669 4670| Type| Description| 4671| ------------------- | ------------------------ | 4672| Promise<void> | Promise that returns no value.| 4673 4674**Error codes** 4675 4676For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4677 4678| ID| Error Message| 4679| ------- | --------------------------------------------- | 4680| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4681| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4682| 1300002 | This window state is abnormal. | 4683| 1300003 | This window manager service works abnormally. | 4684 4685**Example** 4686 4687```ts 4688import { BusinessError } from '@kit.BasicServicesKit'; 4689 4690windowClass?.setUIContent('pages/Index', (error: BusinessError) => { 4691 if (error.code) { 4692 console.error(`Failed to set the content. Cause code: ${error.code}`); 4693 return; 4694 } 4695 console.info('Succeeded in setting the content.'); 4696 let grayScale: number = 0.5; 4697 try { 4698 if (canIUse("SystemCapability.Window.SessionManager")) { 4699 let promise = windowClass?.setWindowGrayScale(grayScale); 4700 promise?.then(() => { 4701 console.info('Succeeded in setting the grayScale.'); 4702 }).catch((err: BusinessError) => { 4703 console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`); 4704 }); 4705 } 4706 } catch (exception) { 4707 console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`); 4708 } 4709}); 4710``` 4711 4712### on('windowTitleButtonRectChange')<sup>11+</sup> 4713 4714on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 4715 4716Subscribes to the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar of the window. This API takes effect for the window that has a title bar or a three-button area. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 4717 4718<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 4719 4720**Atomic service API**: This API can be used in atomic services since API version 12. 4721 4722**System capability**: SystemCapability.Window.SessionManager 4723 4724**Parameters** 4725 4726| Name | Type | Mandatory| Description | 4727| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4728| type | string | Yes | Event type. The value is fixed at **'windowTitleButtonRectChange'**, indicating that the change event of the rectangle that holds the minimize, maximize, and close buttons.| 4729| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | Yes | Callback used to return the new rectangle.| 4730 4731**Error codes** 4732 4733For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4734 4735| ID| Error Message | 4736| -------- | ------------------------------ | 4737| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4738| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4739| 1300002 | This window state is abnormal. | 4740 4741**Example** 4742 4743```ts 4744windowClass.setUIContent('pages/WindowPage').then(() => { 4745 try { 4746 windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => { 4747 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 4748 }); 4749 } catch (exception) { 4750 console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4751 } 4752}) 4753``` 4754 4755### off('windowTitleButtonRectChange')<sup>11+</sup> 4756 4757off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 4758 4759Unsubscribes from the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar of the window. This API takes effect for the window that has a title bar or a three-button area. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 4760 4761<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 4762 4763**Atomic service API**: This API can be used in atomic services since API version 12. 4764 4765**System capability**: SystemCapability.Window.SessionManager 4766 4767**Parameters** 4768 4769| Name | Type | Mandatory| Description | 4770| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4771| type | string | Yes | Event type. The value is fixed at **'windowTitleButtonRectChange'**, indicating that the change event of the rectangle that holds the minimize, maximize, and close buttons.| 4772| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | No | Callback used to return the new rectangle. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4773 4774**Error codes** 4775 4776For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4777 4778| ID| Error Message | 4779| -------- | ------------------------------ | 4780| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4781| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4782| 1300002 | This window state is abnormal. | 4783 4784**Example** 4785 4786```ts 4787windowClass.setUIContent('pages/WindowPage').then(() => { 4788 const callback = (titleButtonRect: window.TitleButtonRect) => { 4789 // ... 4790 } 4791 try { 4792 // Enable listening through the on API. 4793 windowClass?.on('windowTitleButtonRectChange', callback); 4794 // Disable the listening of a specified callback. 4795 windowClass?.off('windowTitleButtonRectChange', callback); 4796 // Unregister all the callbacks that have been registered through on(). 4797 windowClass?.off('windowTitleButtonRectChange'); 4798 } catch (exception) { 4799 console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4800 } 4801}) 4802``` 4803 4804### on('windowRectChange')<sup>12+</sup> 4805 4806on(type: 'windowRectChange', callback: Callback<RectChangeOptions>): void 4807 4808Subscribes to window rectangle (position and size) change events. 4809 4810**System capability**: SystemCapability.Window.SessionManager 4811 4812**Atomic service API**: This API can be used in atomic services since API version 12. 4813 4814**Parameters** 4815 4816| Name | Type | Mandatory| Description | 4817| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4818| type | string | Yes | Event type. The value is fixed at **'windowRectChange'**, indicating the window rectangle change event.| 4819| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | Yes | Callback used to return the value and reason of the window rectangle change. | 4820 4821**Error codes** 4822 4823For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4824 4825| ID| Error Message| 4826| ------- | -------------------------------------------- | 4827| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4828| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4829| 1300002 | This window state is abnormal. | 4830| 1300003 | This window manager service works abnormally. | 4831 4832**Example** 4833 4834```ts 4835windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 4836 console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data)); 4837}); 4838``` 4839 4840### off('windowRectChange')<sup>12+</sup> 4841 4842off(type: 'windowRectChange', callback?: Callback<RectChangeOptions>): void 4843 4844Unsubscribes from window rectangle (position and size) change events. 4845 4846**System capability**: SystemCapability.Window.SessionManager 4847 4848**Atomic service API**: This API can be used in atomic services since API version 12. 4849 4850**Parameters** 4851 4852| Name | Type | Mandatory| Description | 4853| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4854| type | string | Yes | Event type. The value is fixed at **'windowRectChange'**, indicating the window rectangle change event. | 4855| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | No | Callback used to return the value and reason of the window rectangle change. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4856 4857**Error codes** 4858 4859For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4860 4861| ID| Error Message| 4862| ------- | -------------------------------------------- | 4863| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4864| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4865| 1300002 | This window state is abnormal. | 4866| 1300003 | This window manager service works abnormally. | 4867 4868**Example** 4869 4870```ts 4871const callback = (rectChangeOptions: window.RectChangeOptions) => { 4872 // ... 4873} 4874windowClass.on('windowRectChange', callback); 4875windowClass.off('windowRectChange', callback); 4876// Unregister all the callbacks that have been registered through on(). 4877windowClass.off('windowRectChange'); 4878``` 4879 4880### on('subWindowClose')<sup>12+</sup> 4881 4882on(type: 'subWindowClose', callback: Callback<void>): void 4883 4884Subscribes to the event indicating that the child window is closed. This event is triggered only when the user clicks the system-provided close button in the upper right corner to close the child window. It is not triggered when the child window is closed in other ways. 4885 4886If the event is subscribed to multiple times, only the most recently subscribed-to event takes effect. 4887 4888The callback function in this API is executed synchronously. For asynchronous close events of child windows, refer to [on('windowWillClose')](#onwindowwillclose15). 4889 4890If there is an existing event subscribed to by calling [on('windowWillClose')](#onwindowwillclose15), only the [on('windowWillClose')](#onwindowwillclose15) API will be responded to. 4891 4892**Atomic service API**: This API can be used in atomic services since API version 12. 4893 4894**System capability**: SystemCapability.Window.SessionManager 4895 4896**Parameters** 4897 4898| Name | Type | Mandatory| Description | 4899| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4900| type | string | Yes | Event type. The value is fixed at **'subWindowClose'**, indicating the child window close event.| 4901| callback | Callback<void> | Yes | Callback invoked when the close button in the upper right corner of the child window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Boolean type. The return value determines whether to continue to close the child window. The value **true** means not to close the child window, and **false** means to continue to close the child window. | 4902 4903**Error codes** 4904 4905For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4906 4907| ID| Error Message| 4908| ------- | -------------------------------------------- | 4909| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4910| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4911| 1300002 | This window state is abnormal. | 4912| 1300004 | Unauthorized operation. | 4913 4914**Example** 4915 4916```ts 4917const callback = () => { 4918 // ... 4919 return true; 4920} 4921try { 4922 windowClass.on('subWindowClose', callback); 4923} catch (exception) { 4924 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4925} 4926``` 4927 4928### off('subWindowClose')<sup>12+</sup> 4929 4930off(type: 'subWindowClose', callback?: Callback<void>): void 4931 4932Unsubscribes from the event indicating that the child window is closed. 4933 4934**Atomic service API**: This API can be used in atomic services since API version 12. 4935 4936**System capability**: SystemCapability.Window.SessionManager 4937 4938**Parameters** 4939 4940| Name | Type | Mandatory| Description | 4941| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4942| type | string | Yes | Event type. The value is fixed at **'subWindowClose'**, indicating the child window close event. | 4943| callback | Callback<void> | No | Callback invoked when the close button in the upper right corner of the child window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Boolean type. The return value determines whether to continue to close the child window. The value **true** means not to close the child window, and **false** means to continue to close the child window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4944 4945**Error codes** 4946 4947For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4948 4949| ID| Error Message| 4950| ------- | -------------------------------------------- | 4951| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4952| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4953| 1300002 | This window state is abnormal. | 4954| 1300004 | Unauthorized operation. | 4955 4956**Example** 4957 4958```ts 4959const callback = () => { 4960 // ... 4961 return true; 4962} 4963try { 4964 windowClass.on('subWindowClose', callback); 4965 windowClass.off('subWindowClose', callback); 4966 // Unregister all the callbacks that have been registered through on(). 4967 windowClass.off('subWindowClose'); 4968} catch (exception) { 4969 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4970} 4971``` 4972 4973### on('windowWillClose')<sup>15+</sup> 4974 4975on(type: 'windowWillClose', callback: Callback<void, Promise<boolean>>): void 4976 4977Subscribes to the event indicating that the main window or child window will be closed. This event is triggered only when the user clicks the close button in the system-provided title bar to close the window. It is not triggered when the window is closed in other ways. 4978 4979The callback function in this API is executed synchronously. For synchronous close events of child windows, refer to [on('subWindowClose')](#onsubwindowclose12). For synchronous close events of the main window, refer to [on('windowStageClose')](#onwindowstageclose14). 4980 4981<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> <br> 4982 4983**Atomic service API**: This API can be used in atomic services since API version 15. 4984 4985**System capability**: SystemCapability.Window.SessionManager 4986 4987**Parameters** 4988 4989| Name | Type | Mandatory| Description | 4990| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4991| type | string | Yes | Event type. The value is fixed at **'windowWillClose'**, indicating the window close event.| 4992| callback | Callback<void, Promise<boolean>> | Yes | Callback used to when the close button in the upper right corner of the window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Promise<boolean> type. In the returned Promise function, **resolve(true)** means not to close the window, and **resolve(false)** or **reject** means to continue to close the window.| 4993 4994**Error codes** 4995 4996For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4997 4998| ID| Error Message| 4999| ------- | -------------------------------------------- | 5000| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5001| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5002| 1300002 | This window state is abnormal. | 5003| 1300004 | Unauthorized operation. | 5004 5005**Example** 5006 5007```ts 5008// EntryAbility.ets 5009import { UIAbility } from '@kit.AbilityKit'; 5010import { window } from '@kit.ArkUI'; 5011 5012export default class EntryAbility extends UIAbility { 5013 5014 onWindowStageCreate(windowStage: window.WindowStage) { 5015 console.info('onWindowStageCreate'); 5016 const callback = () => { 5017 // ... 5018 return new Promise<boolean>((resolve, reject) => { 5019 // Whether to close the window. 5020 let result: boolean = true; 5021 resolve(result); 5022 }); 5023 } 5024 try { 5025 let windowClass = windowStage.getMainWindowSync(); 5026 windowClass.on('windowWillClose', callback); 5027 } catch (exception) { 5028 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5029 } 5030 } 5031} 5032``` 5033 5034### off('windowWillClose')<sup>15+</sup> 5035 5036off(type: 'windowWillClose', callback?: Callback<void, Promise<boolean>>): void 5037 5038Unsubscribes from the event indicating that the main window or child window will be closed. 5039 5040<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> <br> 5041 5042**Atomic service API**: This API can be used in atomic services since API version 15. 5043 5044**System capability**: SystemCapability.Window.SessionManager 5045 5046**Parameters** 5047 5048| Name | Type | Mandatory| Description | 5049| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5050| type | string | Yes | Event type. The value is fixed at **'windowWillClose'**, indicating the window close event.| 5051| callback | Callback<void, Promise<boolean>> | No | Callback used to when the close button in the upper right corner of the window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Promise<boolean> type. In the returned Promise function, **resolve(true)** means not to close the window, and **resolve(false)** or **reject** means to continue to close the window.| 5052 5053**Error codes** 5054 5055For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5056 5057| ID| Error Message| 5058| ------- | -------------------------------------------- | 5059| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5060| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5061| 1300002 | This window state is abnormal. | 5062| 1300004 | Unauthorized operation. | 5063 5064**Example** 5065 5066```ts 5067// EntryAbility.ets 5068import { UIAbility } from '@kit.AbilityKit'; 5069import { window } from '@kit.ArkUI'; 5070 5071export default class EntryAbility extends UIAbility { 5072 5073 onWindowStageCreate(windowStage: window.WindowStage) { 5074 console.info('onWindowStageCreate'); 5075 try { 5076 const callback = () => { 5077 // ... 5078 return new Promise<boolean>((resolve, reject) => { 5079 // Whether to close the window. 5080 let result: boolean = true; 5081 resolve(result); 5082 }); 5083 } 5084 let windowClass = windowStage.getMainWindowSync(); 5085 windowClass.on('windowWillClose', callback); 5086 windowClass.off('windowWillClose', callback); 5087 // Unregister all the callbacks that have been registered through on(). 5088 windowClass.off('windowWillClose'); 5089 } catch (exception) { 5090 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5091 } 5092 } 5093} 5094``` 5095 5096### on('windowHighlightChange')<sup>15+</sup> 5097 5098on(type: 'windowHighlightChange', callback: Callback<boolean>): void 5099 5100Subscribes to the highlighted state change event of the window. 5101 5102**Atomic service API**: This API can be used in atomic services since API version 15. 5103 5104**System capability**: SystemCapability.Window.SessionManager 5105 5106**Parameters** 5107 5108| Name | Type | Mandatory| Description | 5109| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5110| type | string | Yes | Event type. The value is fixed at **'windowHighlightChange'**, indicating the window highlighted state change event.| 5111| callback | Callback<boolean> | Yes | Callback used to return the highlighted state of the window. which is a Boolean value. The value **true** means that the window is hightlighted, and **false** means the opposite. | 5112 5113**Error codes** 5114 5115For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5116 5117| ID| Error Message| 5118| ------- | -------------------------------------------- | 5119| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5120| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5121| 1300002 | This window state is abnormal. | 5122| 1300003 | This window manager service works abnormally. | 5123 5124**Example** 5125 5126```ts 5127try { 5128 windowClass.on('windowHighlightChange', (data: boolean) => { 5129 console.info(`Window highlight Change: ${data}`); 5130 }); 5131} catch (exception) { 5132 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5133} 5134``` 5135 5136### off('windowHighlightChange')<sup>15+</sup> 5137 5138off(type: 'windowHighlightChange', callback?: Callback<boolean>): void 5139 5140Unsubscribes from the highlighted state change event of the window. 5141 5142**Atomic service API**: This API can be used in atomic services since API version 15. 5143 5144**System capability**: SystemCapability.Window.SessionManager 5145 5146**Parameters** 5147 5148| Name | Type | Mandatory| Description | 5149| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 5150| type | string | Yes | Event type. The value is fixed at **'windowHighlightChange'**, indicating the window highlighted state change event. | 5151| callback | Callback<boolean> | No | Callback used to return the highlighted state of the window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 5152 5153**Error codes** 5154 5155For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5156 5157| ID| Error Message| 5158| ------- | -------------------------------------------- | 5159| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5160| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5161| 1300002 | This window state is abnormal. | 5162| 1300003 | This window manager service works abnormally. | 5163 5164**Example** 5165 5166```ts 5167const callback = (data: boolean) => { 5168 // ... 5169} 5170try { 5171 // Enable listening through the on API. 5172 windowClass.on('windowHighlightChange', callback); 5173 // Disable the listening of a specified callback. 5174 windowClass.off('windowHighlightChange', callback); 5175 // Unregister all the callbacks that have been registered through on(). 5176 windowClass.off('windowHighlightChange'); 5177} catch (exception) { 5178 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 5179} 5180``` 5181 5182### isWindowSupportWideGamut<sup>9+</sup> 5183 5184isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 5185 5186Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 5187 5188**Atomic service API**: This API can be used in atomic services since API version 12. 5189 5190**System capability**: SystemCapability.WindowManager.WindowManager.Core 5191 5192**Parameters** 5193 5194| Name| Type| Mandatory| Description| 5195| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 5196| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite.| 5197 5198**Error codes** 5199 5200For details about the error codes, see [Window Error Codes](errorcode-window.md). 5201 5202| ID| Error Message| 5203| ------- | ------------------------------ | 5204| 1300002 | This window state is abnormal. | 5205 5206**Example** 5207 5208```ts 5209import { BusinessError } from '@kit.BasicServicesKit'; 5210 5211windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 5212 const errCode: number = err.code; 5213 if (errCode) { 5214 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5215 return; 5216 } 5217 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 5218}); 5219``` 5220 5221### isWindowSupportWideGamut<sup>9+</sup> 5222 5223isWindowSupportWideGamut(): Promise<boolean> 5224 5225Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 5226 5227**Atomic service API**: This API can be used in atomic services since API version 12. 5228 5229**System capability**: SystemCapability.WindowManager.WindowManager.Core 5230 5231**Return value** 5232 5233| Type| Description| 5234| ---------------------- | ------------------------------------------------------------------------------------ | 5235| Promise<boolean> | Promise used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite.| 5236 5237**Error codes** 5238 5239For details about the error codes, see [Window Error Codes](errorcode-window.md). 5240 5241| ID| Error Message| 5242| ------- | ------------------------------ | 5243| 1300002 | This window state is abnormal. | 5244 5245**Example** 5246 5247```ts 5248import { BusinessError } from '@kit.BasicServicesKit'; 5249 5250let promise = windowClass.isWindowSupportWideGamut(); 5251promise.then((data) => { 5252 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 5253}).catch((err: BusinessError) => { 5254 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5255}); 5256``` 5257 5258### setWindowColorSpace<sup>9+</sup> 5259 5260setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5261 5262Sets a color space for this window. This API uses an asynchronous callback to return the result. 5263 5264**Atomic service API**: This API can be used in atomic services since API version 12. 5265 5266**System capability**: SystemCapability.WindowManager.WindowManager.Core 5267 5268**Parameters** 5269 5270| Name| Type| Mandatory| Description| 5271| ---------- | ------------------------- | -- | ----------- | 5272| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 5273| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5274 5275**Error codes** 5276 5277For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5278 5279| ID| Error Message| 5280| ------- | ------------------------------ | 5281| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5282| 1300002 | This window state is abnormal. | 5283 5284**Example** 5285 5286```ts 5287import { BusinessError } from '@kit.BasicServicesKit'; 5288 5289try { 5290 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 5291 const errCode: number = err.code; 5292 if (errCode) { 5293 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5294 return; 5295 } 5296 console.info('Succeeded in setting window colorspace.'); 5297 }); 5298} catch (exception) { 5299 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5300} 5301``` 5302 5303### setWindowColorSpace<sup>9+</sup> 5304 5305setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 5306 5307Sets a color space for this window. This API uses a promise to return the result. 5308 5309**Atomic service API**: This API can be used in atomic services since API version 12. 5310 5311**System capability**: SystemCapability.WindowManager.WindowManager.Core 5312 5313**Parameters** 5314 5315| Name| Type| Mandatory| Description| 5316| ---------- | ------------------------- | -- | ------------- | 5317| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 5318 5319**Return value** 5320 5321| Type| Description| 5322| ------------------- | ------------------------ | 5323| Promise<void> | Promise that returns no value.| 5324 5325**Error codes** 5326 5327For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5328 5329| ID| Error Message| 5330| ------- | ------------------------------ | 5331| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5332| 1300002 | This window state is abnormal. | 5333 5334**Example** 5335 5336```ts 5337import { BusinessError } from '@kit.BasicServicesKit'; 5338 5339try { 5340 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 5341 promise.then(() => { 5342 console.info('Succeeded in setting window colorspace.'); 5343 }).catch((err: BusinessError) => { 5344 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5345 }); 5346} catch (exception) { 5347 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5348} 5349``` 5350 5351### getWindowColorSpace<sup>9+</sup> 5352 5353getWindowColorSpace(): ColorSpace 5354 5355Obtains the color space of this window. 5356 5357**Atomic service API**: This API can be used in atomic services since API version 12. 5358 5359**System capability**: SystemCapability.WindowManager.WindowManager.Core 5360 5361**Return value** 5362 5363| Type| Description| 5364| ------------------------- | ------------- | 5365| [ColorSpace](#colorspace8) | Color space obtained.| 5366 5367**Error codes** 5368 5369For details about the error codes, see [Window Error Codes](errorcode-window.md). 5370 5371| ID| Error Message| 5372| ------- | ------------------------------ | 5373| 1300002 | This window state is abnormal. | 5374 5375**Example** 5376 5377```ts 5378let colorSpace = windowClass.getWindowColorSpace(); 5379``` 5380 5381### setWindowBackgroundColor<sup>9+</sup> 5382 5383setWindowBackgroundColor(color: string | ColorMetrics): void 5384 5385Sets the background color for this window. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 5386 5387**System capability**: SystemCapability.WindowManager.WindowManager.Core 5388 5389**Atomic service API**: This API can be used in atomic services since API version 11. 5390 5391**Parameters** 5392 5393| Name| Type| Mandatory| Description| 5394| ----- | ------ | -- | ----------------------------------------------------------------------- | 5395| color | string \| [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12)<sup>16+</sup> | Yes| Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**.<br>Since API version 16, this parameter supports the ColorMetrics type.| 5396 5397**Error codes** 5398 5399For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5400 5401| ID| Error Message| 5402| ------- | ------------------------------ | 5403| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5404| 1300002 | This window state is abnormal. | 5405 5406**Example** 5407 5408```ts 5409import { BusinessError } from '@kit.BasicServicesKit'; 5410import { ColorMetrics } from '@kit.ArkUI'; 5411 5412let storage: LocalStorage = new LocalStorage(); 5413storage.setOrCreate('storageSimpleProp', 121); 5414windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 5415 let errCode: number = err.code; 5416 if (errCode) { 5417 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5418 return; 5419 } 5420 console.info('Succeeded in loading the content.'); 5421 let color1: string = '#00ff33'; 5422 let color2: ColorMetrics = ColorMetrics.numeric(0xff112233); 5423 try { 5424 windowClass?.setWindowBackgroundColor(color1); 5425 windowClass?.setWindowBackgroundColor(color2); 5426 } catch (exception) { 5427 console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); 5428 }; 5429}); 5430``` 5431 5432### setWindowBrightness<sup>9+</sup> 5433 5434setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 5435 5436Sets the screen brightness for the main window. This API uses an asynchronous callback to return the result. 5437 5438- For non-2-in-1 devices, when the screen brightness setting for the window by this API takes effect, Control Panel cannot adjust the overall system screen brightness. It can do so only after the window-specific screen brightness is restored to the default value. 5439- For 2-in-1 devices, Control Panel has the same priority as this API. Event if this API is called to set the window-specific screen brightness, Control Panel can adjust the overall system screen brightness. 5440 5441**System capability**: SystemCapability.WindowManager.WindowManager.Core 5442 5443**Atomic service API**: This API can be used in atomic services since API version 11. 5444 5445**Parameters** 5446 5447| Name| Type| Mandatory| Description | 5448| ---------- | ------------------------- | -- |-------------------------------------------| 5449| brightness | number | Yes| Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 5450| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5451 5452**Error codes** 5453 5454For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5455 5456| ID| Error Message| 5457| ------- | -------------------------------------------- | 5458| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5459| 1300002 | This window state is abnormal. | 5460| 1300003 | This window manager service works abnormally. | 5461 5462**Example** 5463 5464```ts 5465// EntryAbility.ets 5466import { UIAbility } from '@kit.AbilityKit'; 5467import { BusinessError } from '@kit.BasicServicesKit'; 5468 5469export default class EntryAbility extends UIAbility { 5470 // ... 5471 onWindowStageCreate(windowStage: window.WindowStage): void { 5472 console.info('onWindowStageCreate'); 5473 let windowClass: window.Window | undefined = undefined; 5474 windowStage.getMainWindow((err: BusinessError, data) => { 5475 const errCode: number = err.code; 5476 if (errCode) { 5477 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5478 return; 5479 } 5480 windowClass = data; 5481 let brightness: number = 1; 5482 try { 5483 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 5484 const errCode: number = err.code; 5485 if (errCode) { 5486 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5487 return; 5488 } 5489 console.info('Succeeded in setting the brightness.'); 5490 }); 5491 } catch (exception) { 5492 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5493 } 5494 }); 5495 } 5496} 5497``` 5498 5499### setWindowBrightness<sup>9+</sup> 5500 5501setWindowBrightness(brightness: number): Promise<void> 5502 5503Sets the screen brightness for the main window. This API uses a promise to return the result. 5504 5505- For non-2-in-1 devices, when the screen brightness setting for the window by this API takes effect, Control Panel cannot adjust the overall system screen brightness. It can do so only after the window-specific screen brightness is restored to the default value. 5506- For 2-in-1 devices, Control Panel has the same priority as this API. Event if this API is called to set the window-specific screen brightness, Control Panel can adjust the overall system screen brightness. 5507 5508**System capability**: SystemCapability.WindowManager.WindowManager.Core 5509 5510**Atomic service API**: This API can be used in atomic services since API version 11. 5511 5512**Parameters** 5513 5514| Name| Type| Mandatory| Description | 5515| ---------- | ------ | -- |----------------------------------------| 5516| brightness | number | Yes| Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 5517 5518**Return value** 5519 5520| Type| Description| 5521| ------------------- | ------------------------ | 5522| Promise<void> | Promise that returns no value.| 5523 5524**Error codes** 5525 5526For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5527 5528| ID| Error Message| 5529| ------- | -------------------------------------------- | 5530| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5531| 1300002 | This window state is abnormal. | 5532| 1300003 | This window manager service works abnormally. | 5533 5534**Example** 5535 5536```ts 5537// EntryAbility.ets 5538import { UIAbility } from '@kit.AbilityKit'; 5539import { BusinessError } from '@kit.BasicServicesKit'; 5540 5541export default class EntryAbility extends UIAbility { 5542 // ... 5543 onWindowStageCreate(windowStage: window.WindowStage): void { 5544 console.info('onWindowStageCreate'); 5545 let windowClass: window.Window | undefined = undefined; 5546 windowStage.getMainWindow((err: BusinessError, data) => { 5547 const errCode: number = err.code; 5548 if (errCode) { 5549 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5550 return; 5551 } 5552 windowClass = data; 5553 let brightness: number = 1; 5554 try { 5555 let promise = windowClass.setWindowBrightness(brightness); 5556 promise.then(() => { 5557 console.info('Succeeded in setting the brightness.'); 5558 }).catch((err: BusinessError) => { 5559 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5560 }); 5561 } catch (exception) { 5562 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5563 } 5564 }); 5565 } 5566} 5567``` 5568 5569### setWindowFocusable<sup>9+</sup> 5570 5571setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5572 5573Sets whether this window is focusable, that is, whether the window can gain focus after it is being clicked or using other methods. This API uses an asynchronous callback to return the result. 5574 5575**Atomic service API**: This API can be used in atomic services since API version 12. 5576 5577**System capability**: SystemCapability.WindowManager.WindowManager.Core 5578 5579**Parameters** 5580 5581| Name| Type| Mandatory| Description| 5582| ----------- | ------------------------- | -- | ------------------------------------------------------- | 5583| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite.| 5584| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5585 5586**Error codes** 5587 5588For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5589 5590| ID| Error Message| 5591| ------- | -------------------------------------------- | 5592| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5593| 1300002 | This window state is abnormal. | 5594| 1300003 | This window manager service works abnormally. | 5595 5596**Example** 5597 5598```ts 5599import { BusinessError } from '@kit.BasicServicesKit'; 5600 5601let isFocusable: boolean = true; 5602try { 5603 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 5604 const errCode: number = err.code; 5605 if (errCode) { 5606 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5607 return; 5608 } 5609 console.info('Succeeded in setting the window to be focusable.'); 5610 }); 5611} catch (exception) { 5612 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5613} 5614``` 5615 5616### setWindowFocusable<sup>9+</sup> 5617 5618setWindowFocusable(isFocusable: boolean): Promise<void> 5619 5620Sets whether this window is focusable, that is, whether the window can gain focus after it is being clicked or using other methods. This API uses a promise to return the result. 5621 5622**Atomic service API**: This API can be used in atomic services since API version 12. 5623 5624**System capability**: SystemCapability.WindowManager.WindowManager.Core 5625 5626**Parameters** 5627 5628| Name| Type| Mandatory| Description| 5629| ----------- | ------- | -- | -------------------------------------------------------- | 5630| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 5631 5632**Return value** 5633 5634| Type| Description| 5635| ------------------- | ------------------------ | 5636| Promise<void> | Promise that returns no value.| 5637 5638**Error codes** 5639 5640For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5641 5642| ID| Error Message| 5643| ------- | -------------------------------------------- | 5644| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5645| 1300002 | This window state is abnormal. | 5646| 1300003 | This window manager service works abnormally. | 5647 5648**Example** 5649 5650```ts 5651import { BusinessError } from '@kit.BasicServicesKit'; 5652 5653let isFocusable: boolean = true; 5654try { 5655 let promise = windowClass.setWindowFocusable(isFocusable); 5656 promise.then(() => { 5657 console.info('Succeeded in setting the window to be focusable.'); 5658 }).catch((err: BusinessError) => { 5659 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5660 }); 5661} catch (exception) { 5662 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5663} 5664``` 5665 5666### setWindowKeepScreenOn<sup>9+</sup> 5667 5668setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5669 5670Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 5671 5672Set **isKeepScreenOn** to **true** only in necessary scenarios (such as navigation, video playback, drawing, and gaming scenarios). After exiting these scenarios, set the parameter to **false**. Do not use this API in other scenarios (such as no screen interaction or audio playback). When the system detects that the API is used in a non-standard manner, automatic screen-off may be invoked. 5673 5674**System capability**: SystemCapability.WindowManager.WindowManager.Core 5675 5676**Atomic service API**: This API can be used in atomic services since API version 11. 5677 5678**Parameters** 5679 5680| Name| Type| Mandatory| Description| 5681| -------------- | ------------------------- | -- | ---------------------------------------------------- | 5682| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 5683| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5684 5685**Error codes** 5686 5687For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5688 5689| ID| Error Message| 5690| ------- | -------------------------------------------- | 5691| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5692| 1300002 | This window state is abnormal. | 5693| 1300003 | This window manager service works abnormally. | 5694 5695**Example** 5696 5697```ts 5698import { BusinessError } from '@kit.BasicServicesKit'; 5699 5700let isKeepScreenOn: boolean = true; 5701try { 5702 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 5703 const errCode: number = err.code; 5704 if (errCode) { 5705 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5706 return; 5707 } 5708 console.info('Succeeded in setting the screen to be always on.'); 5709 }); 5710} catch (exception) { 5711 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5712} 5713``` 5714 5715### setWindowKeepScreenOn<sup>9+</sup> 5716 5717setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5718 5719Sets whether to keep the screen always on. This API uses a promise to return the result. 5720 5721Set **isKeepScreenOn** to **true** only in necessary scenarios (such as navigation, video playback, drawing, and gaming scenarios). After exiting these scenarios, set the parameter to **false**. Do not use this API in other scenarios (such as no screen interaction or audio playback). When the system detects that the API is used in a non-standard manner, automatic screen-off may be invoked. 5722 5723**System capability**: SystemCapability.WindowManager.WindowManager.Core 5724 5725**Atomic service API**: This API can be used in atomic services since API version 11. 5726 5727**Parameters** 5728 5729| Name| Type| Mandatory| Description| 5730| -------------- | ------- | -- | --------------------------------------------------- | 5731| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite.| 5732 5733**Return value** 5734 5735| Type| Description| 5736| ------------------- | ------------------------ | 5737| Promise<void> | Promise that returns no value.| 5738 5739**Error codes** 5740 5741For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5742 5743| ID| Error Message| 5744| ------- | -------------------------------------------- | 5745| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5746| 1300002 | This window state is abnormal. | 5747| 1300003 | This window manager service works abnormally. | 5748 5749**Example** 5750 5751```ts 5752import { BusinessError } from '@kit.BasicServicesKit'; 5753 5754let isKeepScreenOn: boolean = true; 5755try { 5756 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 5757 promise.then(() => { 5758 console.info('Succeeded in setting the screen to be always on.'); 5759 }).catch((err: BusinessError) => { 5760 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5761 }); 5762} catch (exception) { 5763 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5764} 5765``` 5766 5767### setWindowPrivacyMode<sup>9+</sup> 5768 5769setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 5770 5771Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 5772 5773A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5774 5775**System capability**: SystemCapability.WindowManager.WindowManager.Core 5776 5777**Atomic service API**: This API can be used in atomic services since API version 12. 5778 5779**Required permissions**: ohos.permission.PRIVACY_WINDOW 5780 5781**Parameters** 5782 5783| Name| Type| Mandatory| Description| 5784| ------------- | ------------------------- | -- | ------------------------------------------------------ | 5785| 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. | 5786| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5787 5788**Error codes** 5789 5790For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5791 5792| ID| Error Message| 5793| ------- | ------------------------------ | 5794| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5795| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5796| 1300002 | This window state is abnormal. | 5797 5798**Example** 5799 5800```ts 5801import { BusinessError } from '@kit.BasicServicesKit'; 5802 5803let isPrivacyMode: boolean = true; 5804try { 5805 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 5806 const errCode: number = err.code; 5807 if (errCode) { 5808 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5809 return; 5810 } 5811 console.info('Succeeded in setting the window to privacy mode.'); 5812 }); 5813} catch (exception) { 5814 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5815} 5816``` 5817 5818### setWindowPrivacyMode<sup>9+</sup> 5819 5820setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 5821 5822Sets whether this window is in privacy mode. This API uses a promise to return the result. 5823 5824A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5825 5826**System capability**: SystemCapability.WindowManager.WindowManager.Core 5827 5828**Atomic service API**: This API can be used in atomic services since API version 12. 5829 5830**Required permissions**: ohos.permission.PRIVACY_WINDOW 5831 5832**Parameters** 5833 5834| Name| Type| Mandatory| Description| 5835| ------------- | ------- | -- | ----------------------------------------------------- | 5836| 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.| 5837 5838**Return value** 5839 5840| Type| Description| 5841| ------------------- | ------------------------ | 5842| Promise<void> | Promise that returns no value.| 5843 5844**Error codes** 5845 5846For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5847 5848| ID| Error Message| 5849| ------- | ------------------------------ | 5850| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5851| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5852| 1300002 | This window state is abnormal. | 5853 5854**Example** 5855 5856```ts 5857import { BusinessError } from '@kit.BasicServicesKit'; 5858 5859let isPrivacyMode: boolean = true; 5860try { 5861 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 5862 promise.then(() => { 5863 console.info('Succeeded in setting the window to privacy mode.'); 5864 }).catch((err: BusinessError) => { 5865 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5866 }); 5867} catch (exception) { 5868 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5869} 5870``` 5871 5872### setWindowTouchable<sup>9+</sup> 5873 5874setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 5875 5876Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 5877 5878**Atomic service API**: This API can be used in atomic services since API version 12. 5879 5880**System capability**: SystemCapability.WindowManager.WindowManager.Core 5881 5882**Parameters** 5883 5884| Name| Type| Mandatory| Description| 5885| ----------- | ------------------------- | -- | ----------------------------------------------- | 5886| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 5887| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5888 5889**Error codes** 5890 5891For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5892 5893| ID| Error Message| 5894| ------- | -------------------------------------------- | 5895| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5896| 1300002 | This window state is abnormal. | 5897| 1300003 | This window manager service works abnormally. | 5898 5899**Example** 5900 5901```ts 5902import { BusinessError } from '@kit.BasicServicesKit'; 5903 5904let isTouchable = true; 5905try { 5906 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 5907 const errCode: number = err.code; 5908 if (errCode) { 5909 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5910 return; 5911 } 5912 console.info('Succeeded in setting the window to be touchable.'); 5913 }); 5914} catch (exception) { 5915 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5916} 5917``` 5918 5919### setWindowTouchable<sup>9+</sup> 5920 5921setWindowTouchable(isTouchable: boolean): Promise<void> 5922 5923Sets whether this window is touchable. This API uses a promise to return the result. 5924 5925**Atomic service API**: This API can be used in atomic services since API version 12. 5926 5927**System capability**: SystemCapability.WindowManager.WindowManager.Core 5928 5929**Parameters** 5930 5931| Name| Type| Mandatory| Description| 5932| ----------- | ------- | -- | ----------------------------------------------- | 5933| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 5934 5935**Return value** 5936 5937| Type| Description| 5938| ------------------- | ------------------------- | 5939| Promise<void> | Promise that returns no value.| 5940 5941**Error codes** 5942 5943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5944 5945| ID| Error Message| 5946| ------- | -------------------------------------------- | 5947| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5948| 1300002 | This window state is abnormal. | 5949| 1300003 | This window manager service works abnormally. | 5950 5951**Example** 5952 5953```ts 5954import { BusinessError } from '@kit.BasicServicesKit'; 5955 5956let isTouchable: boolean = true; 5957try { 5958 let promise = windowClass.setWindowTouchable(isTouchable); 5959 promise.then(() => { 5960 console.info('Succeeded in setting the window to be touchable.'); 5961 }).catch((err: BusinessError) => { 5962 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5963 }); 5964} catch (exception) { 5965 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5966} 5967``` 5968 5969### snapshot<sup>9+</sup> 5970 5971snapshot(callback: AsyncCallback<image.PixelMap>): void 5972 5973Captures this window. This API uses an asynchronous callback to return the result. 5974 5975**Atomic service API**: This API can be used in atomic services since API version 12. 5976 5977**System capability**: SystemCapability.WindowManager.WindowManager.Core 5978 5979**Parameters** 5980 5981| Name | Type | Mandatory | Description | 5982| -------- | ------------------------------------------------------------ | --------- | ----------------------------------- | 5983| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the result. | 5984 5985**Error codes** 5986 5987For details about the error codes, see [Window Error Codes](errorcode-window.md). 5988 5989| ID | Error Message | 5990| ------- | ------------------------------ | 5991| 1300002 | This window state is abnormal. | 5992 5993**Example** 5994 5995```ts 5996import { BusinessError } from '@kit.BasicServicesKit'; 5997import { image } from '@kit.ImageKit'; 5998 5999windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 6000 const errCode: number = err.code; 6001 if (errCode) { 6002 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6003 return; 6004 } 6005 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6006 pixelMap.release(); // Release the memory in time after the PixelMap is used. 6007}); 6008``` 6009 6010### snapshot<sup>9+</sup> 6011 6012snapshot(): Promise<image.PixelMap> 6013 6014Captures this window. This API uses a promise to return the result. 6015 6016**Atomic service API**: This API can be used in atomic services since API version 12. 6017 6018**System capability**: SystemCapability.WindowManager.WindowManager.Core 6019 6020**Return value** 6021 6022| Type | Description | 6023| ------------------------------------------------------------ | --------------------------------------------- | 6024| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the window screenshot. | 6025 6026**Error codes** 6027 6028For details about the error codes, see [Window Error Codes](errorcode-window.md). 6029 6030| ID | Error Message | 6031| ------- | ------------------------------ | 6032| 1300002 | This window state is abnormal. | 6033 6034**Example** 6035 6036```ts 6037import { BusinessError } from '@kit.BasicServicesKit'; 6038import { image } from '@kit.ImageKit'; 6039 6040let promise = windowClass.snapshot(); 6041promise.then((pixelMap: image.PixelMap) => { 6042 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6043 pixelMap.release(); // Release the memory in time after the PixelMap is used. 6044}).catch((err: BusinessError) => { 6045 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6046}); 6047``` 6048 6049### setAspectRatio<sup>10+</sup> 6050 6051setAspectRatio(ratio: number): Promise<void> 6052 6053Sets the aspect ratio of the window content layout. This API uses a promise to return the result. 6054 6055When the window size is set by using other APIs such as [resize](#resize9) and [resizeAsync](#resizeasync12), the window size is not restricted by **ratio**. 6056 6057This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). The aspect ratio is saved persistently, which means that the setting is valid even after the application is closed or the device is restarted. 6058 6059**Atomic service API**: This API can be used in atomic services since API version 12. 6060 6061**System capability**: SystemCapability.WindowManager.WindowManager.Core 6062 6063**Parameters** 6064 6065| Name | Type | Mandatory | Description | 6066| ----- | ------ | --------- | ------------------------------------------------------------ | 6067| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number and is restricted by the maximum and minimum sizes of the window. The minimum ratio is the value of minimum width divided by the maximum height, and the maximum ratio is the maximum width divided by the minimum height. The maximum and minimum sizes of the window are determined by the intersection of the setting of [WindowLimits](#windowlimits11) and the system limit. The system limit takes precedence over [WindowLimits](#windowlimits11). The valid range of **ratio** varies with [WindowLimits](#windowlimits11). If [WindowLimits](#windowlimits11) is set prior to **ratio**, any conflict will result in an error code when setting **ratio**. Conversely, if **ratio** is set before and then conflicts arise with the subsequently configured [WindowLimits](#windowlimits11), the window's aspect ratio may not adhere to the initially configured value of **ratio**. | 6068 6069**Return value** 6070 6071| Type | Description | 6072| ------------------- | ------------------------------ | 6073| Promise<void> | Promise that returns no value. | 6074 6075**Error codes** 6076 6077For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6078 6079| ID | Error Message | 6080| ------- | ------------------------------------------------------------ | 6081| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6082| 1300002 | This window state is abnormal. | 6083| 1300004 | Unauthorized operation. | 6084 6085**Example** 6086<!--code_no_check--> 6087 6088```ts 6089// EntryAbility.ets 6090import { UIAbility } from '@kit.AbilityKit'; 6091import { BusinessError } from '@kit.BasicServicesKit'; 6092 6093export default class EntryAbility extends UIAbility { 6094 6095 // ... 6096 onWindowStageCreate(windowStage: window.WindowStage) { 6097 console.info('onWindowStageCreate'); 6098 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6099 if (!windowClass) { 6100 console.info('windowClass is null'); 6101 } 6102 try { 6103 let ratio = 1.0; 6104 let promise = windowClass.setAspectRatio(ratio); 6105 promise.then(() => { 6106 console.info('Succeeded in setting aspect ratio of window.'); 6107 }).catch((err: BusinessError) => { 6108 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6109 }); 6110 } catch (exception) { 6111 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6112 } 6113 } 6114} 6115``` 6116 6117### setAspectRatio<sup>10+</sup> 6118 6119setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 6120 6121Sets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 6122 6123When the window size is set by using other APIs such as [resize](#resize9) and [resizeAsync](#resizeasync12), the window size is not restricted by **ratio**. 6124 6125This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). The aspect ratio is saved persistently, which means that the setting is valid even after the application is closed or the device is restarted. 6126 6127**Atomic service API**: This API can be used in atomic services since API version 12. 6128 6129**System capability**: SystemCapability.WindowManager.WindowManager.Core 6130 6131**Parameters** 6132 6133| Name | Type | Mandatory | Description | 6134| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 6135| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number and is restricted by the maximum and minimum sizes of the window. The minimum ratio is the value of minimum width divided by the maximum height, and the maximum ratio is the maximum width divided by the minimum height. The maximum and minimum sizes of the window are determined by the intersection of the setting of [WindowLimits](#windowlimits11) and the system limit. The system limit takes precedence over [WindowLimits](#windowlimits11). The valid range of **ratio** varies with [WindowLimits](#windowlimits11). If [WindowLimits](#windowlimits11) is set prior to **ratio**, any conflict will result in an error code when setting **ratio**. Conversely, if **ratio** is set before and then conflicts arise with the subsequently configured [WindowLimits](#windowlimits11), the window's aspect ratio may not adhere to the initially configured value of **ratio**. | 6136| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6137 6138**Error codes** 6139 6140For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6141 6142| ID | Error Message | 6143| ------- | ------------------------------------------------------------ | 6144| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6145| 1300002 | This window state is abnormal. | 6146| 1300004 | Unauthorized operation. | 6147 6148**Example** 6149<!--code_no_check--> 6150```ts 6151// EntryAbility.ets 6152import { UIAbility } from '@kit.AbilityKit'; 6153import { BusinessError } from '@kit.BasicServicesKit'; 6154 6155export default class EntryAbility extends UIAbility { 6156 6157 // ... 6158 onWindowStageCreate(windowStage: window.WindowStage) { 6159 console.info('onWindowStageCreate'); 6160 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6161 if (!windowClass) { 6162 console.info('Failed to load the content. Cause: windowClass is null'); 6163 } 6164 try { 6165 let ratio = 1.0; 6166 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 6167 const errCode: number = err.code; 6168 if (errCode) { 6169 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6170 return; 6171 } 6172 console.info('Succeeded in setting the aspect ratio of window.'); 6173 }); 6174 } catch (exception) { 6175 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6176 } 6177 } 6178} 6179 6180``` 6181 6182### resetAspectRatio<sup>10+</sup> 6183 6184resetAspectRatio(): Promise<void> 6185 6186Resets the aspect ratio of the window content layout. This API uses a promise to return the result. 6187 6188This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). After this API is called, the persistently stored aspect ratio is cleared. 6189 6190**Atomic service API**: This API can be used in atomic services since API version 12. 6191 6192**System capability**: SystemCapability.WindowManager.WindowManager.Core 6193 6194**Return value** 6195 6196| Type | Description | 6197| ------------------- | ------------------------------ | 6198| Promise<void> | Promise that returns no value. | 6199 6200**Error codes** 6201 6202For details about the error codes, see [Window Error Codes](errorcode-window.md). 6203 6204| ID | Error Message | 6205| ------- | ------------------------------ | 6206| 1300002 | This window state is abnormal. | 6207| 1300004 | Unauthorized operation. | 6208 6209**Example** 6210<!--code_no_check--> 6211```ts 6212// EntryAbility.ets 6213import { UIAbility } from '@kit.AbilityKit'; 6214import { BusinessError } from '@kit.BasicServicesKit'; 6215 6216export default class EntryAbility extends UIAbility { 6217 6218 // ... 6219 onWindowStageCreate(windowStage: window.WindowStage) { 6220 console.info('onWindowStageCreate'); 6221 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6222 if (!windowClass) { 6223 console.info('Failed to load the content. Cause: windowClass is null'); 6224 } 6225 try { 6226 let promise = windowClass.resetAspectRatio(); 6227 promise.then(() => { 6228 console.info('Succeeded in resetting aspect ratio of window.'); 6229 }).catch((err: BusinessError) => { 6230 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6231 }); 6232 } catch (exception) { 6233 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6234 } 6235 } 6236} 6237``` 6238 6239### resetAspectRatio<sup>10+</sup> 6240 6241resetAspectRatio(callback: AsyncCallback<void>): void 6242 6243Resets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 6244 6245This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). After this API is called, the persistently stored aspect ratio is cleared. 6246 6247**Atomic service API**: This API can be used in atomic services since API version 12. 6248 6249**System capability**: SystemCapability.WindowManager.WindowManager.Core 6250 6251**Parameters** 6252 6253| Name | Type | Mandatory | Description | 6254| -------- | ------------------------- | --------- | ----------------------------------- | 6255| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6256 6257**Error codes** 6258 6259For details about the error codes, see [Window Error Codes](errorcode-window.md). 6260 6261| ID | Error Message | 6262| ------- | ------------------------------ | 6263| 1300002 | This window state is abnormal. | 6264| 1300004 | Unauthorized operation. | 6265 6266**Example** 6267<!--code_no_check--> 6268```ts 6269// EntryAbility.ets 6270import { UIAbility } from '@kit.AbilityKit'; 6271import { BusinessError } from '@kit.BasicServicesKit'; 6272 6273export default class EntryAbility extends UIAbility { 6274 6275 // ... 6276 onWindowStageCreate(windowStage: window.WindowStage) { 6277 console.info('onWindowStageCreate'); 6278 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6279 if (!windowClass) { 6280 console.info('Failed to load the content. Cause: windowClass is null'); 6281 } 6282 try { 6283 windowClass.resetAspectRatio((err: BusinessError) => { 6284 const errCode: number = err.code; 6285 if (errCode) { 6286 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6287 return; 6288 } 6289 console.info('Succeeded in resetting aspect ratio of window.'); 6290 }); 6291 } catch (exception) { 6292 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6293 } 6294 } 6295} 6296``` 6297 6298### minimize<sup>11+</sup> 6299 6300minimize(callback: AsyncCallback<void>): void 6301 6302The behavior of this API varies based on the caller: 6303 6304- Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. For 2-in-1 devices, it can be restored by calling [restore()](#restore14). 6305 6306- Hides the child window if the caller is a child window. The child window cannot be restored in the dock bar. It can be made visible again by calling [showWindow()](#showwindow9). 6307 6308This API uses an asynchronous callback to return the result. 6309 6310**Atomic service API**: This API can be used in atomic services since API version 12. 6311 6312**System capability**: SystemCapability.Window.SessionManager 6313 6314**Parameters** 6315 6316| Name | Type | Mandatory | Description | 6317| -------- | ------------------------- | --------- | ----------------------------------- | 6318| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6319 6320**Error codes** 6321 6322For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6323 6324| ID | Error Message | 6325| ------- | ------------------------------------------------------------ | 6326| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6327| 1300002 | This window state is abnormal. | 6328| 1300003 | This window manager service works abnormally. | 6329 6330**Example** 6331 6332```ts 6333import { BusinessError } from '@kit.BasicServicesKit'; 6334 6335windowClass.minimize((err: BusinessError) => { 6336 const errCode: number = err.code; 6337 if (errCode) { 6338 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6339 return; 6340 } 6341 console.info('Succeeded in minimizing the window.'); 6342}); 6343``` 6344 6345### minimize<sup>11+</sup> 6346 6347minimize(): Promise<void> 6348 6349The behavior of this API varies based on the caller: 6350 6351- Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. For 2-in-1 devices, it can be restored by calling [restore()](#restore14). 6352 6353- Hides the child window if the caller is a child window. The child window cannot be restored in the dock bar. It can be made visible again by calling [showWindow()](#showwindow9). 6354 6355This API uses a promise to return the result. 6356 6357**Atomic service API**: This API can be used in atomic services since API version 12. 6358 6359**System capability**: SystemCapability.Window.SessionManager 6360 6361**Return value** 6362 6363| Type | Description | 6364| ------------------- | ------------------------------ | 6365| Promise<void> | Promise that returns no value. | 6366 6367**Error codes** 6368 6369For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6370 6371| ID | Error Message | 6372| ------- | ------------------------------------------------------------ | 6373| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6374| 1300002 | This window state is abnormal. | 6375| 1300003 | This window manager service works abnormally. | 6376 6377**Example** 6378 6379```ts 6380import { BusinessError } from '@kit.BasicServicesKit'; 6381 6382let promise = windowClass.minimize(); 6383promise.then(() => { 6384 console.info('Succeeded in minimizing the window.'); 6385}).catch((err: BusinessError) => { 6386 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6387}); 6388``` 6389 6390### maximize<sup>12+</sup> 6391maximize(presentation?: MaximizePresentation): Promise<void> 6392 6393Maximizes the main window. This API uses a promise to return the result. 6394 6395<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6396 6397**Atomic service API**: This API can be used in atomic services since API version 12. 6398 6399**System capability**: SystemCapability.Window.SessionManager 6400 6401**Parameters** 6402 6403| Name | Type | Mandatory | Description | 6404| ------------ | ----------------------------------------------- | --------- | ------------------------------------------------------------ | 6405| presentation | [MaximizePresentation](#maximizepresentation12) | No | Layout when the window is maximized. The default value is **window.MaximizePresentation.ENTER_IMMERSIVE**, indicating that the window enters the immersive layout when maximized. | 6406 6407**Return value** 6408 6409| Type | Description | 6410| ------------------- | ------------------------------ | 6411| Promise<void> | Promise that returns no value. | 6412 6413**Error codes** 6414 6415For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6416 6417| ID | Error Message | 6418| ------- | ------------------------------------------------------------ | 6419| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6420| 1300002 | This window state is abnormal. | 6421| 1300003 | This window manager service works abnormally. | 6422| 1300004 | Unauthorized operation. | 6423| 1300005 | This window stage is abnormal. | 6424 6425**Example** 6426 6427```ts 6428// EntryAbility.ets 6429import { UIAbility } from '@kit.AbilityKit'; 6430import { BusinessError } from '@kit.BasicServicesKit'; 6431export default class EntryAbility extends UIAbility { 6432 // ... 6433 6434 onWindowStageCreate(windowStage: window.WindowStage) { 6435 console.info('onWindowStageCreate'); 6436 let windowClass: window.Window | undefined = undefined; 6437 windowStage.getMainWindow((err: BusinessError, data) => { 6438 const errCode: number = err.code; 6439 if (errCode) { 6440 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6441 return; 6442 } 6443 windowClass = data; 6444 let promise = windowClass.maximize(); 6445 // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 6446 promise.then(() => { 6447 console.info('Succeeded in maximizing the window.'); 6448 }).catch((err: BusinessError) => { 6449 console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`); 6450 }); 6451 }); 6452 } 6453}; 6454``` 6455 6456### setResizeByDragEnabled<sup>14+</sup> 6457setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 6458 6459Sets whether to enable the main window or child window with decorations to resize itself by dragging. This API uses an asynchronous callback to return the result. 6460 6461**Atomic service API**: This API can be used in atomic services since API version 14. 6462 6463**System capability**: SystemCapability.Window.SessionManager 6464 6465**Parameters** 6466 6467| Name | Type | Mandatory | Description | 6468| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 6469| enable | boolean | Yes | Whether to enable the window to resize itself by dragging. The value **true** means to enable the window to resize itself by dragging, and **false** means the opposite. | 6470| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6471 6472**Error codes** 6473 6474For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6475 6476| ID | Error Message | 6477| ------- | ------------------------------------------------------------ | 6478| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6479| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6480| 1300002 | This window state is abnormal. | 6481| 1300003 | This window manager service works abnormally. | 6482 6483**Example** 6484 6485```ts 6486import { BusinessError } from '@kit.BasicServicesKit'; 6487 6488let enabled = false; 6489windowClass.setResizeByDragEnabled(enabled, (err) => { 6490 if (err.code) { 6491 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6492 return; 6493 } 6494 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6495}); 6496``` 6497 6498### setResizeByDragEnabled<sup>14+</sup> 6499setResizeByDragEnabled(enable: boolean): Promise<void> 6500 6501Sets whether to enable the main window or child window with decorations to resize itself by dragging. This API uses a promise to return the result. 6502 6503**Atomic service API**: This API can be used in atomic services since API version 14. 6504 6505**System capability**: SystemCapability.Window.SessionManager 6506 6507**Parameters** 6508 6509| Name | Type | Mandatory | Description | 6510| ------ | ------- | --------- | ------------------------------------------------------------ | 6511| enable | boolean | Yes | Whether to enable the window to resize itself by dragging. The value **true** means to enable the window to resize itself by dragging, and **false** means the opposite. | 6512 6513**Return value** 6514 6515| Type | Description | 6516| ------------------- | ------------------------------ | 6517| Promise<void> | Promise that returns no value. | 6518 6519**Error codes** 6520 6521For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6522 6523| ID | Error Message | 6524| ------- | ------------------------------------------------------------ | 6525| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6526| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6527| 1300002 | This window state is abnormal. | 6528| 1300003 | This window manager service works abnormally. | 6529 6530**Example** 6531 6532```ts 6533import { BusinessError } from '@kit.BasicServicesKit'; 6534 6535let enabled = false; 6536let promise = windowClass.setResizeByDragEnabled(enabled); 6537promise.then(() => { 6538 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6539}).catch((err: BusinessError) => { 6540 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6541}); 6542``` 6543 6544### recover<sup>11+</sup> 6545 6546recover(): Promise<void> 6547 6548Restores the main window from the full-screen, maximized, or split-screen mode to a floating window, and restores the window size and position to those before the full-screen, maximized, or split-screen mode is entered. If the main window is already in the floating window mode, nothing will happen. This API uses a promise to return the result. It takes effect only in the multi-window stack layout. 6549 6550<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6551 6552**Atomic service API**: This API can be used in atomic services since API version 12. 6553 6554**System capability**: SystemCapability.Window.SessionManager 6555 6556**Return value** 6557 6558| Type | Description | 6559| ------------------- | ------------------------------ | 6560| Promise<void> | Promise that returns no value. | 6561 6562**Error codes** 6563 6564For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6565 6566| ID | Error Message | 6567| ------- | ------------------------------------------------------------ | 6568| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6569| 1300001 | Repeated operation. | 6570| 1300002 | This window state is abnormal. | 6571 6572**Example** 6573 6574```ts 6575// EntryAbility.ets 6576import { UIAbility } from '@kit.AbilityKit'; 6577import { BusinessError } from '@kit.BasicServicesKit'; 6578 6579export default class EntryAbility extends UIAbility { 6580 // ... 6581 onWindowStageCreate(windowStage: window.WindowStage): void { 6582 console.info('onWindowStageCreate'); 6583 let windowClass: window.Window | undefined = undefined; 6584 windowStage.getMainWindow((err: BusinessError, data) => { 6585 const errCode: number = err.code; 6586 if (errCode) { 6587 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6588 return; 6589 } 6590 windowClass = data; 6591 let promise = windowClass.recover(); 6592 promise.then(() => { 6593 console.info('Succeeded in recovering the window.'); 6594 }).catch((err: BusinessError) => { 6595 console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`); 6596 }); 6597 }); 6598 } 6599} 6600``` 6601 6602### restore<sup>14+</sup> 6603 6604restore(): Promise<void> 6605 6606Restores the main window from minimization to the foreground, returning it to its size and position before it is minimized. This API uses a promise to return the result. 6607 6608This API takes effect only in the multi-window stack layout when the main window is minimized and the UIAbility is in the **onForeground** state. 6609 6610<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6611 6612**Atomic service API**: This API can be used in atomic services since API version 14. 6613 6614**System capability**: SystemCapability.Window.SessionManager 6615 6616**Return value** 6617 6618| Type | Description | 6619| ------------------- | ------------------------------ | 6620| Promise<void> | Promise that returns no value. | 6621 6622**Error codes** 6623 6624For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6625 6626| **ID** | **Error Message** | 6627| ------- | ------------------------------------------------------------ | 6628| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6629| 1300002 | This window state is abnormal. | 6630| 1300003 | This window manager service works abnormally. | 6631| 1300004 | Unauthorized operation. | 6632 6633**Example** 6634 6635```ts 6636// EntryAbility.ets 6637import { UIAbility } from '@kit.AbilityKit'; 6638import { BusinessError } from '@kit.BasicServicesKit'; 6639import { window } from '@kit.ArkUI'; 6640import { BusinessError } from '@kit.BasicServicesKit'; 6641 6642export default class EntryAbility extends UIAbility { 6643 onWindowStageCreate(windowStage: window.WindowStage): void { 6644 // Load the page corresponding to the main window. 6645 windowStage.loadContent('pages/Index', (err) => { 6646 let mainWindow: window.Window | undefined = undefined; 6647 // Obtain the main window. 6648 windowStage.getMainWindow().then( 6649 data => { 6650 mainWindow = data; 6651 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 6652 // Call minimize() to minimize the main window. 6653 mainWindow.minimize(); 6654 // Set the delay function to restore the main window after a delay of 5 seconds. 6655 setTimeout(()=>{ 6656 // Call restore() to restore the main window. 6657 let promise = mainWindow.restore(); 6658 promise.then(() => { 6659 console.info('Succeeded in restoring the window.'); 6660 }).catch((err: BusinessError) => { 6661 console.error(`Failed to restore the window. Cause code: ${err.code}, 6662 message: ${err.message}`); 6663 }); 6664 },5000); 6665 } 6666 ).catch((err: BusinessError) => { 6667 if(err.code){ 6668 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6669 } 6670 }); 6671 }); 6672 } 6673} 6674``` 6675 6676### getWindowLimits<sup>11+</sup> 6677 6678getWindowLimits(): WindowLimits 6679 6680Obtains the size limits of this application window. 6681 6682**Atomic service API**: This API can be used in atomic services since API version 12. 6683 6684**System capability**: SystemCapability.Window.SessionManager 6685 6686**Return value** 6687 6688| Type | Description | 6689| ------------------------------- | ------------------- | 6690| [WindowLimits](#windowlimits11) | Window size limits. | 6691 6692**Error codes** 6693 6694For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6695 6696| ID | Error Message | 6697| :------ | :----------------------------------------------------------- | 6698| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6699| 1300002 | This window state is abnormal. | 6700 6701**Example** 6702 6703```ts 6704try { 6705 let windowLimits = windowClass.getWindowLimits(); 6706} catch (exception) { 6707 console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`); 6708} 6709``` 6710 6711### setWindowLimits<sup>11+</sup> 6712 6713setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 6714 6715Sets the size limits for this application window. This API uses a promise to return the result. 6716By default, system size limits are provided. They are determined by the product configuration and cannot be modified. If **setWindowLimits** has not been called, you can call [getWindowLimits](#getwindowlimits11) to obtain the system size limits. 6717 6718**Atomic service API**: This API can be used in atomic services since API version 12. 6719 6720**System capability**: SystemCapability.Window.SessionManager 6721 6722**Parameters** 6723 6724| Name | Type | Mandatory | Description | 6725| :----------- | :------------------------------ | :-------- | :------------------------- | 6726| windowLimits | [WindowLimits](#windowlimits11) | Yes | Target size limits, in px. | 6727 6728**Return value** 6729 6730| Type | Description | 6731| :--------------------------------------------- | :----------------------------------------------------------- | 6732| Promise<[WindowLimits](#windowlimits11)> | Promise used to return the final size limits, which are the intersection between the passed-in size limits and the system size limits. | 6733 6734**Error codes** 6735 6736For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6737 6738| ID | Error Message | 6739| :------ | :----------------------------------------------------------- | 6740| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6741| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6742| 1300002 | This window state is abnormal. | 6743| 1300003 | This window manager service works abnormally. | 6744| 1300004 | Unauthorized operation. | 6745 6746**Example** 6747 6748```ts 6749import { BusinessError } from '@kit.BasicServicesKit'; 6750try { 6751 let windowLimits: window.WindowLimits = { 6752 maxWidth: 1500, 6753 maxHeight: 1000, 6754 minWidth: 500, 6755 minHeight: 400 6756 }; 6757 let promise = windowClass.setWindowLimits(windowLimits); 6758 promise.then((data) => { 6759 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6760 }).catch((err: BusinessError) => { 6761 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6762 }); 6763} catch (exception) { 6764 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6765} 6766``` 6767 6768### setWindowLimits<sup>15+</sup> 6769 6770setWindowLimits(windowLimits: WindowLimits, isForcible: boolean): Promise<WindowLimits> 6771 6772Sets the size limits for this application window. This API uses a promise to return the result. 6773 6774By default, system size limits are provided. They are determined by the product configuration and cannot be modified. If **setWindowLimits** has not been called, you can call [getWindowLimits](#getwindowlimits11) to obtain the system size limits. 6775 6776This API can be used only on 2-in-1 devices. 6777 6778**Atomic service API**: This API can be used in atomic services since API version 15. 6779 6780**System capability**: SystemCapability.Window.SessionManager 6781 6782**Parameters** 6783 6784| Name | Type | Mandatory | Description | 6785| :----------- | :------------------------------ | :-------- | :----------------------------------------------------------- | 6786| windowLimits | [WindowLimits](#windowlimits11) | Yes | Target size limits, in px. | 6787| isForcible | boolean | Yes | Whether to forcibly set the window size limits.<br>If this parameter is set to **true**, the minimum width and height of the window are determined by the lower value between the system size limits and 40 vp, and the maximum width and height depend on the system size limits.<br>If this parameter is set to **false**, the minimum and maximum window width and height are restricted by the system size limits. | 6788 6789**Return value** 6790 6791| Type | Description | 6792| :--------------------------------------------- | :----------------------------------------------------------- | 6793| Promise<[WindowLimits](#windowlimits11)> | Promise used to return the new window size limits. Depending on the value of **isForcible**, the return value represents the intersection between the value passed and the system size limits. | 6794 6795**Error codes** 6796 6797For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6798 6799| ID | Error Message | 6800| :------ | :----------------------------------------------------------- | 6801| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6802| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6803| 1300002 | This window state is abnormal. | 6804| 1300003 | This window manager service works abnormally. | 6805| 1300004 | Unauthorized operation. | 6806 6807**Example** 6808 6809```ts 6810import { BusinessError } from '@kit.BasicServicesKit'; 6811try { 6812 let windowLimits: window.WindowLimits = { 6813 maxWidth: 1500, 6814 maxHeight: 1000, 6815 minWidth: 100, 6816 minHeight: 100 6817 }; 6818 let promise = windowClass.setWindowLimits(windowLimits, true); 6819 promise.then((data) => { 6820 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6821 }).catch((err: BusinessError) => { 6822 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6823 }); 6824} catch (exception) { 6825 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6826} 6827``` 6828 6829### setWindowMask<sup>12+</sup> 6830 6831setWindowMask(windowMask: Array<Array<number>>): Promise<void>; 6832 6833Sets a mask for this window to get an irregularly shaped window. This API uses a promise to return the result. 6834 6835The mask is used to describe the shape of the irregularly shaped window. 6836 6837This API is available only for child windows and global floating windows. 6838 6839When the size of an irregularly shaped window changes, the actual display content is the intersection of the mask size and the window size. 6840 6841<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6842 6843**Atomic service API**: This API can be used in atomic services since API version 12. 6844 6845**System capability**: SystemCapability.Window.SessionManager 6846 6847**Parameters** 6848 6849| Name | Type | Mandatory | Description | 6850| :--------- | :------------------------------- | :-------- | :----------------------------------------------------------- | 6851| windowMask | Array<Array<number>> | Yes | Mask. The value can only be a two-dimensional array containing the window size in pixels, with each element in the array set to either **0** or **1**. The value **0** indicates that the pixel is transparent, and **1** indicates that the pixel is opaque. If the passed-in pixel array does not match the window size or the value of any element in the array is not **0** or **1**, the value is invalid. | 6852 6853**Return value** 6854 6855| Type | Description | 6856| :------------------ | :----------------------------- | 6857| Promise<void> | Promise that returns no value. | 6858 6859**Error codes** 6860 6861For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6862 6863| ID | Error Message | 6864| :------ | :----------------------------------------------------------- | 6865| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6866| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6867| 1300002 | This window state is abnormal. | 6868| 1300003 | This window manager service works abnormally. | 6869| 1300004 | Unauthorized operation. | 6870 6871**Example** 6872 6873```ts 6874import { BusinessError } from '@kit.BasicServicesKit'; 6875try { 6876 let windowMask: Array<Array<number>> = [ 6877 [0, 0, 0, 1, 0, 0, 0], 6878 [0, 0, 1, 1, 1, 0, 0], 6879 [0, 1, 1, 0, 1, 1, 0], 6880 [1, 1, 0, 0, 0, 1, 1] 6881 ]; 6882 let promise = windowClass.setWindowMask(windowMask); 6883 promise.then(() => { 6884 console.info('Succeeded in setting the window mask.'); 6885 }).catch((err: BusinessError) => { 6886 console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`); 6887 }); 6888} catch (exception) { 6889 console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`); 6890} 6891``` 6892 6893### keepKeyboardOnFocus<sup>11+</sup> 6894 6895keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 6896 6897Sets whether to keep the soft keyboard created by others when a window has focus. This API can be called only by a system window or an application child window. 6898 6899**Atomic service API**: This API can be used in atomic services since API version 12. 6900 6901**System capability**: SystemCapability.Window.SessionManager 6902 6903**Parameters** 6904 6905| Name | Type | Mandatory | Description | 6906| ---------------- | ------- | --------- | ------------------------------------------------------------ | 6907| keepKeyboardFlag | boolean | Yes | Whether to keep the soft keyboard created by others. The value **true** means to keep the soft keyboard, and **false** means the opposite. | 6908 6909**Error codes** 6910 6911For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6912 6913| ID | Error Message | 6914| ------- | ------------------------------------------------------------ | 6915| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6916| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6917| 1300002 | This window state is abnormal. | 6918| 1300004 | Unauthorized operation. | 6919 6920**Example** 6921 6922```ts 6923try { 6924 windowClass.keepKeyboardOnFocus(true); 6925} catch (exception) { 6926 console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`); 6927} 6928``` 6929 6930### setWindowDecorVisible<sup>11+</sup> 6931 6932setWindowDecorVisible(isVisible: boolean): void 6933 6934Sets whether the title bar is visible in the window. This API takes effect for the window that has a title bar or a three-button area on 2-in-1 devices. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 6935 6936When the window title bar is hidden and the main window transitions into full-screen mode, hovering the cursor over the hot zone of the top window's title bar will cause a floating title bar to appear. To prevent the floating title bar from appearing, call [setTitleAndDockHoverShown()](#settitleanddockhovershown14). 6937 6938**Atomic service API**: This API can be used in atomic services since API version 12. 6939 6940**System capability**: SystemCapability.Window.SessionManager 6941 6942**Parameters** 6943 6944| Name | Type | Mandatory | Description | 6945| --------- | ------- | --------- | ------------------------------------------------------------ | 6946| isVisible | boolean | Yes | Whether the title bar is visible. The value **true** means that the title bar is visible and **false** means the opposite. | 6947 6948**Error codes** 6949 6950For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6951 6952| ID | Error Message | 6953| ------- | ------------------------------------------------------------ | 6954| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6955| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6956| 1300002 | This window state is abnormal. | 6957| 1300004 | Unauthorized operation. | 6958 6959**Example** 6960 6961```ts 6962import { BusinessError } from '@kit.BasicServicesKit'; 6963let storage: LocalStorage = new LocalStorage(); 6964storage.setOrCreate('storageSimpleProp', 121); 6965windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 6966 let errCode: number = err.code; 6967 if (errCode) { 6968 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 6969 return; 6970 } 6971 console.info('Succeeded in loading the content.'); 6972 let isVisible = false; 6973 // Call setWindowDecorVisible. 6974 try { 6975 windowClass?.setWindowDecorVisible(isVisible); 6976 } catch (exception) { 6977 console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 6978 } 6979}); 6980``` 6981 6982### getWindowDecorVisible<sup>18+</sup> 6983 6984getWindowDecorVisible(): boolean 6985 6986Checks whether the title bar of this window is visible. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 6987 6988<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6989 6990**Atomic service API**: This API can be used in atomic services since API version 18. 6991 6992**System capability**: SystemCapability.Window.SessionManager 6993 6994**Return value** 6995 6996| Type | Description | 6997| ------- | ------------------------------------------------------------ | 6998| boolean | Check result. The value **true** means that the title bar is visible, and **false** means the opposite. | 6999 7000**Error codes** 7001 7002For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7003 7004| ID | Error Message | 7005| ------- | ------------------------------------------------------------ | 7006| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7007| 1300002 | This window state is abnormal. | 7008 7009**Example** 7010 7011```ts 7012let isVisible: boolean | undefined = undefined; 7013windowClass.setUIContent('pages/WindowPage').then(() => { 7014 try { 7015 isVisible = windowClass?.getWindowDecorVisible(); 7016 } catch (exception) { 7017 console.error(`Failed to get the window decor visibility. Cause code: ${exception.code}, message: ${exception.message}`); 7018 } 7019}) 7020``` 7021 7022### setWindowTitle<sup>15+</sup> 7023 7024setWindowTitle(titleName: string): Promise<void> 7025 7026Sets the window title. This API uses a promise to return the result. The setting takes effect for a window with a title bar. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7027 7028This API can be used only 2-in-1 devices and tablets. 7029 7030**Atomic service API**: This API can be used in atomic services since API version 15. 7031 7032**System capability**: SystemCapability.Window.SessionManager 7033 7034**Parameters** 7035 7036| Name | Type | Mandatory | Description | 7037| --------- | ------ | --------- | ------------- | 7038| titleName | string | Yes | Window title. | 7039 7040**Return value** 7041 7042| Type | Description | 7043| ------------------- | ------------------------------ | 7044| Promise<void> | Promise that returns no value. | 7045 7046**Error codes** 7047 7048For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7049 7050| ID | Error Message | 7051| ------- | ------------------------------------------------------------ | 7052| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7053| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7054| 1300002 | This window state is abnormal. | 7055 7056**Example** 7057 7058```ts 7059import { window } from '@kit.ArkUI'; 7060import { BusinessError } from '@kit.BasicServicesKit'; 7061 7062let windowClass: window.Window | undefined = undefined; 7063try { 7064 let promise = window.getLastWindow(this.context); 7065 promise.then((data) => { 7066 windowClass = data; 7067 let title = "title"; 7068 windowClass.setWindowTitle(title).then(() => { 7069 console.info('Succeeded in setting the window title.'); 7070 }).catch((err: BusinessError) => { 7071 console.error(`Failed to set the window title. Cause code: ${err.code}, message: ${err.message}`); 7072 }); 7073 }).catch((err: BusinessError) => { 7074 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 7075 }); 7076} catch (exception) { 7077 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 7078} 7079``` 7080 7081### setWindowTitleMoveEnabled<sup>14+</sup> 7082 7083setWindowTitleMoveEnabled(enabled: boolean): void 7084 7085Enables or disables the capability to move the window (either main window or child window) by dragging its title bar and to maximize the window with a double-click. When this capability is disabled, you can use [startMoving()](#startmoving14) to move the window by dragging in the application's hot zone and use [maximize()](#maximize12) to maximize the window. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7086 7087<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7088 7089**Atomic service API**: This API can be used in atomic services since API version 14. 7090 7091**System capability**: SystemCapability.Window.SessionManager 7092 7093**Parameters** 7094 7095| Name | Type | Mandatory | Description | 7096| ------- | ------- | --------- | ------------------------------------------------------------ | 7097| enabled | boolean | Yes | Whether to enable the capability to move the window by dragging the title bar and to maximize the window with a double-click. The value **true** means to enable the capability, and **false** means the opposite. | 7098 7099**Error codes** 7100 7101For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7102 7103| ID | Error Message | 7104| ------- | ------------------------------------------------------------ | 7105| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7106| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7107| 1300002 | This window state is abnormal. | 7108| 1300004 | Unauthorized operation. | 7109 7110**Example** 7111 7112```ts 7113windowClass.setUIContent('pages/WindowPage').then(() => { 7114 try { 7115 let enabled = false; 7116 windowClass.setWindowTitleMoveEnabled(enabled); 7117 } catch (exception) { 7118 console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`); 7119 } 7120}) 7121``` 7122 7123### setSubWindowModal<sup>12+</sup> 7124 7125setSubWindowModal(isModal: boolean): Promise<void> 7126 7127Enables the modal property of the child window. This API uses a promise to return the result. 7128 7129This API must be called by a child window and the setting takes effect for the child window. 7130 7131 After the modal property is enabled, the parent window does not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7132 7133If this API is called by a main window, an error is reported. 7134 7135**Atomic service API**: This API can be used in atomic services since API version 12. 7136 7137**System capability**: SystemCapability.Window.SessionManager 7138 7139**Parameters** 7140 7141| Name | Type | Mandatory | Description | 7142| ------- | ------- | --------- | ------------------------------------------------------------ | 7143| isModal | boolean | Yes | Whether to enable the modal property of the child window. The value **true** means to enable the modal property, and **false** means the opposite. | 7144 7145 7146**Return value** 7147 7148| Type | Description | 7149| ------------------- | ------------------------------ | 7150| Promise<void> | Promise that returns no value. | 7151 7152**Error codes** 7153 7154For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7155 7156| ID | Error Message | 7157| ------- | ------------------------------------------------------------ | 7158| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7159| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7160| 1300002 | This window state is abnormal. | 7161| 1300004 | Unauthorized operation. | 7162 7163**Example** 7164 7165```ts 7166// EntryAbility.ets 7167import { UIAbility } from '@kit.AbilityKit'; 7168import { BusinessError } from '@kit.BasicServicesKit'; 7169 7170export default class EntryAbility extends UIAbility { 7171 // ... 7172 onWindowStageCreate(windowStage: window.WindowStage): void { 7173 console.info('onWindowStageCreate'); 7174 let windowClass: window.Window | undefined = undefined; 7175 // Create a child window. 7176 try { 7177 let subWindow = windowStage.createSubWindow("testSubWindow"); 7178 subWindow.then((data) => { 7179 if (data == null) { 7180 console.error("Failed to create the subWindow. Cause: The data is empty"); 7181 return; 7182 } 7183 windowClass = data; 7184 let promise = windowClass.setSubWindowModal(true); 7185 promise.then(() => { 7186 console.info('Succeeded in setting subwindow modal'); 7187 }).catch((err: BusinessError) => { 7188 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7189 }); 7190 }); 7191 } catch (exception) { 7192 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7193 } 7194 } 7195} 7196``` 7197 7198### setSubWindowModal<sup>14+</sup> 7199 7200setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise<void> 7201 7202Sets the modality type of the child window. This API uses a promise to return the result. 7203 7204When the child window is of the window-modal type, its parent window does not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7205 7206When the child window is of the application-modal type, its parent window and the windows from other instances of the application do not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7207 7208This API is used to set the modality type. To disable the modal property, you are advised to use [setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12). 7209 7210If this API is called by a main window, an error is reported. 7211 7212**Atomic service API**: This API can be used in atomic services since API version 14. 7213 7214**System capability**: SystemCapability.Window.SessionManager 7215 7216**Parameters** 7217 7218| Name | Type | Mandatory | Description | 7219| ------------ | ------------------------------- | --------- | ------------------------------------------------------------ | 7220| isModal | boolean | Yes | Whether to enable the modal property of the child window. The value **true** means to enable the modal property, and **false** means the opposite. Currently, this parameter can only be set to **true**. | 7221| modalityType | [ModalityType](#modalitytype14) | Yes | Modality type of the child window. | 7222 7223**Return value** 7224 7225| Type | Description | 7226| ------------------- | ------------------------------ | 7227| Promise<void> | Promise that returns no value. | 7228 7229**Error codes** 7230 7231For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7232 7233| ID | Error Message | 7234| ------- | ------------------------------------------------------------ | 7235| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7236| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7237| 1300002 | This window state is abnormal. | 7238| 1300004 | Unauthorized operation. | 7239 7240**Example** 7241 7242```ts 7243// EntryAbility.ets 7244import { UIAbility } from '@kit.AbilityKit'; 7245import { BusinessError } from '@kit.BasicServicesKit'; 7246import { window } from '@kit.ArkUI'; 7247 7248export default class EntryAbility extends UIAbility { 7249 // ... 7250 onWindowStageCreate(windowStage: window.WindowStage): void { 7251 console.info('onWindowStageCreate'); 7252 let windowClass: window.Window | undefined = undefined; 7253 // Create a child window. 7254 try { 7255 let subWindow = windowStage.createSubWindow("testSubWindow"); 7256 subWindow.then((data) => { 7257 if (data == null) { 7258 console.error("Failed to create the subWindow. Cause: The data is empty"); 7259 return; 7260 } 7261 windowClass = data; 7262 let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY); 7263 promise.then(() => { 7264 console.info('Succeeded in setting subwindow modal'); 7265 }).catch((err: BusinessError) => { 7266 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7267 }); 7268 }); 7269 } catch (exception) { 7270 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7271 } 7272 } 7273} 7274``` 7275 7276### setWindowDecorHeight<sup>11+</sup> 7277 7278setWindowDecorHeight(height: number): void 7279 7280<!--RP1--> 7281Sets the height of the title bar of this window. This API takes effect for the window that has a title bar or a three-button area on 2-in-1 devices. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7282<!--RP1End--> 7283 7284When the main window transitions into full-screen mode, hovering the mouse over the hot zone of the window's title bar region will cause a floating title bar to appear, with a fixed height of 37 vp. 7285 7286**Atomic service API**: This API can be used in atomic services since API version 12. 7287 7288**System capability**: SystemCapability.Window.SessionManager 7289 7290**Parameters** 7291 7292| Name | Type | Mandatory | Description | 7293| ------ | ------ | --------- | ------------------------------------------------------------ | 7294| height | number | Yes | Height of the title bar. It takes effect only for the window with the title bar. The value is an integer in the range [37,112]. The unit is vp. If a floating point number is passed in, the value is rounded down. A value outside the range is invalid. | 7295 7296**Error codes** 7297 7298For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7299 7300| ID | Error Message | 7301| ------- | ------------------------------------------------------------ | 7302| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7303| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7304| 1300002 | This window state is abnormal. | 7305 7306**Example** 7307 7308```ts 7309windowClass.setUIContent('pages/WindowPage').then(() => { 7310 let height: number = 50; 7311 try { 7312 windowClass?.setWindowDecorHeight(height); 7313 console.info(`Succeeded in setting the height of window decor: ${height}`); 7314 } catch (exception) { 7315 console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7316 } 7317}) 7318``` 7319 7320### setDecorButtonStyle<sup>14+</sup> 7321 7322setDecorButtonStyle(dectorStyle: DecorButtonStyle): void 7323 7324Sets the button style of the decoration bar. The setting takes effect only for the main window and the child window with the window title enabled. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7325 7326<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7327 7328**Atomic service API**: This API can be used in atomic services since API version 14. 7329 7330**System capability**: SystemCapability.Window.SessionManager 7331 7332**Parameters** 7333 7334| Name | Type | Mandatory | Description | 7335| ----------- | --------------------------------------- | --------- | ----------------------------------- | 7336| dectorStyle | [DecorButtonStyle](#decorbuttonstyle14) | Yes | Button style of the decoration bar. | 7337 7338**Error codes** 7339 7340For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7341 7342| ID | Error Message | 7343| ------- | ------------------------------------------------------------ | 7344| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7345| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7346| 1300002 | This window state is abnormal. | 7347| 1300004 | Unauthorized operation. | 7348 7349**Example** 7350 7351```ts 7352import { ConfigurationConstant } from '@kit.AbilityKit'; 7353 7354windowClass.setUIContent('pages/WindowPage').then(() => { 7355 try { 7356 let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; 7357 let style: window.DecorButtonStyle = { 7358 colorMode: colorMode, 7359 buttonBackgroundSize: 24, 7360 spacingBetweenButtons: 12, 7361 closeButtonRightMargin: 20 7362 }; 7363 windowClass.setDecorButtonStyle(style); 7364 console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style)); 7365 } catch (exception) { 7366 console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7367 } 7368}) 7369``` 7370 7371### getDecorButtonStyle<sup>14+</sup> 7372 7373getDecorButtonStyle(): DecorButtonStyle 7374 7375Obtains the button style of the decoration bar. The setting takes effect only for the main window and the child window with the window title enabled. 7376 7377<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7378 7379**Atomic service API**: This API can be used in atomic services since API version 14. 7380 7381**System capability**: SystemCapability.Window.SessionManager 7382 7383**Return value** 7384 7385| Type | Description | 7386| --------------------------------------- | ------------------------------------------------------------ | 7387| [DecorButtonStyle](#decorbuttonstyle14) | Button style on the decoration bar of the current window. The decoration button area is located in the upper right corner of the window. | 7388 7389**Error codes** 7390 7391For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7392 7393| ID | Error Message | 7394| ------- | ------------------------------------------------------------ | 7395| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7396| 1300002 | This window state is abnormal. | 7397| 1300003 | This window manager service works abnormally. | 7398| 1300004 | Unauthorized operation. | 7399 7400**Example** 7401 7402```ts 7403try { 7404 let decorButtonStyle = windowClass.getDecorButtonStyle(); 7405 console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle)); 7406} catch (exception) { 7407 console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7408} 7409``` 7410 7411### getWindowDecorHeight<sup>11+</sup> 7412 7413getWindowDecorHeight(): number 7414 7415<!--RP2--> 7416Obtains the height of the title bar of this window. This API takes effect for the window that has a title bar or a three-button area on 2-in-1 devices. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7417<!--RP2End--> 7418 7419**Atomic service API**: This API can be used in atomic services since API version 12. 7420 7421**System capability**: SystemCapability.Window.SessionManager 7422 7423**Return value** 7424 7425| Type | Description | 7426| ------ | ------------------------------------------------------------ | 7427| number | Height of the title bar. The value is an integer in the range [37,112]. The unit is vp. | 7428 7429**Error codes** 7430 7431For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7432 7433| ID | Error Message | 7434| ------- | ------------------------------------------------------------ | 7435| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7436| 1300002 | This window state is abnormal. | 7437 7438**Example** 7439 7440```ts 7441windowClass.setUIContent('pages/WindowPage').then(() => { 7442 try { 7443 let height = windowClass?.getWindowDecorHeight(); 7444 console.info(`Succeeded in getting the height of window decor: ${height}`); 7445 } catch (exception) { 7446 console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7447 } 7448}) 7449``` 7450 7451### getTitleButtonRect<sup>11+</sup> 7452 7453getTitleButtonRect(): TitleButtonRect 7454 7455Obtains the rectangle that holds the minimize, maximize, and close buttons on the title bar of the main window or the decorated child window. 7456 7457**Atomic service API**: This API can be used in atomic services since API version 12. 7458 7459**System capability**: SystemCapability.Window.SessionManager 7460 7461**Return value** 7462 7463| Type | Description | 7464| ------------------------------------- | ------------------------------------------------------------ | 7465| [TitleButtonRect](#titlebuttonrect11) | Rectangle obtained, which is located in the upper right corner of the window. | 7466 7467**Error codes** 7468 7469For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7470 7471| ID | Error Message | 7472| ------- | ------------------------------------------------------------ | 7473| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7474| 1300002 | This window state is abnormal. | 7475 7476**Example** 7477 7478```ts 7479// EntryAbility.ets 7480import { UIAbility } from '@kit.AbilityKit'; 7481import { BusinessError } from '@kit.BasicServicesKit'; 7482 7483export default class EntryAbility extends UIAbility { 7484 // ... 7485 onWindowStageCreate(windowStage: window.WindowStage): void { 7486 console.info('onWindowStageCreate'); 7487 let windowClass: window.Window | undefined = undefined; 7488 windowStage.getMainWindow((err: BusinessError, data) => { 7489 const errCode: number = err.code; 7490 if (errCode) { 7491 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7492 return; 7493 } 7494 windowClass = data; 7495 try { 7496 let titleButtonArea = windowClass.getTitleButtonRect(); 7497 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 7498 } catch (exception) { 7499 console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`); 7500 } 7501 }); 7502 } 7503} 7504``` 7505 7506### getWindowStatus<sup>12+</sup> 7507 7508getWindowStatus(): WindowStatusType 7509 7510Obtains the mode of this window. 7511 7512**Atomic service API**: This API can be used in atomic services since API version 12. 7513 7514**System capability**: SystemCapability.Window.SessionManager 7515 7516**Return value** 7517 7518| Type | Description | 7519| --------------------------------------- | ------------ | 7520| [WindowStatusType](#windowstatustype11) | Window mode. | 7521 7522**Error codes** 7523 7524For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7525 7526| ID | Error Message | 7527| ------- | ------------------------------------------------------------ | 7528| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7529| 1300002 | This window state is abnormal. | 7530 7531**Example** 7532 7533```ts 7534try { 7535 let windowStatusType = windowClass.getWindowStatus(); 7536} catch (exception) { 7537 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 7538} 7539``` 7540 7541### isFocused<sup>12+</sup> 7542 7543isFocused(): boolean 7544 7545Checks whether this window is focused. 7546 7547**System capability**: SystemCapability.WindowManager.WindowManager.Core 7548 7549**Atomic service API**: This API can be used in atomic services since API version 12. 7550 7551**Return value** 7552 7553| Type | Description | 7554| ------- | ------------------------------------------------------------ | 7555| boolean | Result indicating whether the window is focused. The value **true** means that the window is focused, and **false** means the opposite. | 7556 7557**Error codes** 7558 7559For details about the error codes, see [Window Error Codes](errorcode-window.md). 7560 7561| ID | Error Message | 7562| ------- | ------------------------------ | 7563| 1300002 | This window state is abnormal. | 7564 7565**Example** 7566 7567```ts 7568try { 7569 let focus = windowClass.isFocused(); 7570 console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus)); 7571} catch (exception) { 7572 console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`); 7573} 7574``` 7575 7576### createSubWindowWithOptions<sup>12+</sup> 7577 7578createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 7579 7580Creates a child window under the main window, another child window, or floating window. This API uses a promise to return the result. 7581 7582<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7583 7584**Model restriction**: This API can be used only in the stage model. 7585 7586**System capability**: SystemCapability.Window.SessionManager 7587 7588**Atomic service API**: This API can be used in atomic services since API version 12. 7589 7590**Parameters** 7591 7592| Name | Type | Mandatory | Description | 7593| ------- | --------------------------------------- | --------- | ---------------------------------------------- | 7594| name | string | Yes | Name of the child window. | 7595| options | [SubWindowOptions](#subwindowoptions11) | Yes | Parameters used for creating the child window. | 7596 7597**Return value** 7598 7599| Type | Description | 7600| -------------------------------- | -------------------------------------------------------- | 7601| Promise<[Window](#window)> | Promise used to used to return the child window created. | 7602 7603**Error codes** 7604 7605For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7606 7607| ID | Error Message | 7608| ------- | ------------------------------------------------------------ | 7609| 401 | Parameter error. Possible cause: Incorrect parameter types. | 7610| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7611| 1300002 | This window state is abnormal. | 7612| 1300003 | This window manager service works abnormally. | 7613| 1300004 | Unauthorized operation. | 7614 7615**Example** 7616 7617```ts 7618import { BusinessError } from '@kit.BasicServicesKit'; 7619 7620try { 7621 let options : window.SubWindowOptions = { 7622 title: 'title', 7623 decorEnabled: true, 7624 isModal: true 7625 }; 7626 let promise = windowClass.createSubWindowWithOptions('mySubWindow', options); 7627 promise.then((data) => { 7628 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7629 }).catch((err: BusinessError) => { 7630 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 7631 }); 7632} catch (exception) { 7633 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 7634} 7635``` 7636 7637### setWindowTitleButtonVisible<sup>14+</sup> 7638 7639setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void 7640 7641Shows or hides the maximize, minimize, and close buttons on the title bar of the main window. 7642 7643<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7644 7645**Atomic service API**: This API can be used in atomic services since API version 14. 7646 7647**System capability**: SystemCapability.Window.SessionManager 7648 7649**Parameters** 7650 7651| Name | Type | Mandatory | Description | 7652| ----------------------- | ------- | --------- | ------------------------------------------------------------ | 7653| isMaximizeButtonVisible | boolean | Yes | Whether to show the maximize button. The value **true** means to show the button, and **false** means the opposite. If the maximize button is hidden, the corresponding restore button is also hidden in the maximize scenario. | 7654| isMinimizeButtonVisible | boolean | Yes | Whether to show the minimize button. The value **true** means to show the button, and **false** means the opposite. | 7655| isCloseButtonVisible | boolean | No | Whether to show the close button. The value **true** means to show the button, and **false** means the opposite. | 7656 7657**Error codes** 7658 7659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7660 7661| ID | Error Message | 7662| ------- | ------------------------------------------------------------ | 7663| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7664| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7665| 1300002 | This window state is abnormal. | 7666| 1300004 | Unauthorized operation. | 7667 7668**Example** 7669 7670```ts 7671// EntryAbility.ets 7672import { UIAbility } from '@kit.AbilityKit'; 7673import { BusinessError } from '@kit.BasicServicesKit'; 7674import { window } from '@kit.ArkUI'; 7675 7676export default class EntryAbility extends UIAbility { 7677 onWindowStageCreate(windowStage: window.WindowStage): void { 7678 // Load the page corresponding to the main window. 7679 windowStage.loadContent('pages/Index', (err) => { 7680 let mainWindow: window.Window | undefined = undefined; 7681 // Obtain the main window. 7682 windowStage.getMainWindow().then( 7683 data => { 7684 mainWindow = data; 7685 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7686 // Call setWindowTitleButtonVisible to hide the maximize, minimize, and close buttons on the title bar of the main window. 7687 mainWindow.setWindowTitleButtonVisible(false, false, false); 7688 } 7689 ).catch((err: BusinessError) => { 7690 if(err.code){ 7691 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7692 } 7693 }); 7694 }); 7695 } 7696} 7697``` 7698 7699### setWindowTopmost<sup>14+</sup> 7700 7701setWindowTopmost(isWindowTopmost: boolean): Promise<void> 7702 7703Places the main window above all the other windows of the application. This API uses a promise to return the result. 7704 7705Applications use custom shortcut keys to pin or unpin the main window. 7706 7707<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 7708 7709**Atomic service API**: This API can be used in atomic services since API version 14. 7710 7711**System capability**: SystemCapability.Window.SessionManager 7712 7713**Required permissions**: ohos.permission.WINDOW_TOPMOST 7714 7715**Parameters** 7716 7717| Name | Type | Mandatory | Description | 7718| --------------- | ------- | --------- | ------------------------------------------------------------ | 7719| isWindowTopmost | boolean | Yes | Whether to pin the main window on top. The value **true** means to pin the main window on top, and **false** means the opposite. | 7720 7721 7722**Error codes** 7723 7724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7725 7726| ID | Error Message | 7727| ------- | ------------------------------------------------------------ | 7728| 201 | Permission verification failed. The application does not have the permission required to call the API. | 7729| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7730| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7731| 1300002 | This window state is abnormal. | 7732| 1300004 | Unauthorized operation. | 7733 7734**Example** 7735 7736```ts 7737// ets/pages/Index.ets 7738import { window } from '@kit.ArkUI'; 7739import { common } from '@kit.AbilityKit'; 7740import { BusinessError } from '@kit.BasicServicesKit'; 7741 7742const context = (getContext(this) as common.UIAbilityContext); 7743let windowClass: window.Window | undefined; 7744let keyUpEventAry: string[] = []; 7745 7746@Entry 7747@Component 7748struct Index { 7749 build() { 7750 RelativeContainer() { 7751 Button("Pin") 7752 .onClick(() => { 7753 try { 7754 let promiseCtx = window.getLastWindow(context); 7755 promiseCtx.then((data) => { 7756 windowClass = data; 7757 // The value true means to pin the window on top, and false means to unpin the window. 7758 let isWindowTopmost: boolean = true; 7759 let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost); 7760 promiseTopmost.then(() => { 7761 console.info('Succeeded in setting the main window to be topmost.'); 7762 }).catch((err: BusinessError) => { 7763 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 7764 }); 7765 }) 7766 } catch (exception) { 7767 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`) 7768 } 7769 }) 7770 } 7771 .height('100%') 7772 .width('100%') 7773 .onKeyEvent((event) => { 7774 if(event) { 7775 if(event.type === KeyType.Down) { 7776 keyUpEventAry = []; 7777 } 7778 if(event.type === KeyType.Up) { 7779 keyUpEventAry.push(event.keyText); 7780 // Press Ctrl+T to pin or unpin the main window. 7781 if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) { 7782 let isWindowTopmost: boolean = false; 7783 windowClass.setWindowTopmost(isWindowTopmost); 7784 } 7785 } 7786 } 7787 }) 7788 } 7789} 7790``` 7791 7792### raiseToAppTop<sup>14+</sup> 7793 7794raiseToAppTop(): Promise<void> 7795 7796Called by a child window to elevate the child window to the topmost layer. Its effect is limited to child windows of the same type that share the same parent window of the current application. This API uses a promise to return the result. 7797 7798**System capability**: SystemCapability.WindowManager.WindowManager.Core 7799 7800**Return value** 7801 7802| Type | Description | 7803| ------------------- | ------------------------------ | 7804| Promise<void> | Promise that returns no value. | 7805 7806**Error codes** 7807 7808For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7809 7810| ID | Error Message | 7811| ------- | --------------------------------------------- | 7812| 1300002 | This window state is abnormal. | 7813| 1300003 | This window manager service works abnormally. | 7814| 1300004 | Unauthorized operation. | 7815| 1300009 | The parent window is invalid. | 7816 7817**Example** 7818 7819```ts 7820import { BusinessError } from '@kit.BasicServicesKit'; 7821 7822let promise = windowClass.raiseToAppTop(); 7823promise.then(() => { 7824 console.info('Succeeded in raising the window to app top.'); 7825}).catch((err: BusinessError) => { 7826 console.error(`Failed to raise the window to app top. Cause code: ${err.code}, message: ${err.message}`); 7827}); 7828``` 7829 7830### setRaiseByClickEnabled<sup>14+</sup> 7831 7832setRaiseByClickEnabled(enable: boolean): Promise<void> 7833 7834Sets whether to enable a child window to raise itself by click. This API uses a promise to return the result. 7835 7836Generally, when a child window is clicked, it is brought to the forefront among sibling child windows of the same type that share the same parent window within the application. If the **enable** parameter is set to **false**, when the child window is clicked, it still stays in its existing position. 7837 7838**System capability**: SystemCapability.Window.SessionManager 7839 7840**Parameters** 7841 7842| Name | Type | Mandatory | Description | 7843| ------ | ------- | --------- | ------------------------------------------------------------ | 7844| enable | boolean | Yes | Whether a child window can be raised by clicking. The value **true** means that the child window can be raised by clicking, and **false** means the opposite. | 7845 7846**Return value** 7847 7848| Type | Description | 7849| ------------------- | ------------------------------ | 7850| Promise<void> | Promise that returns no value. | 7851 7852**Error codes** 7853 7854For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7855 7856| ID | Error Message | 7857| ------- | ------------------------------------------------------------ | 7858| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7859| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7860| 1300002 | This window state is abnormal. | 7861| 1300003 | This window manager service works abnormally. | 7862| 1300004 | Unauthorized operation. | 7863| 1300009 | The parent window is invalid. | 7864 7865**Example** 7866 7867```ts 7868// EntryAbility.ets 7869import { UIAbility } from '@kit.AbilityKit'; 7870import { BusinessError } from '@kit.BasicServicesKit'; 7871 7872export default class EntryAbility extends UIAbility { 7873 // ... 7874 onWindowStageCreate(windowStage: window.WindowStage): void { 7875 console.info('onWindowStageCreate'); 7876 let windowClass: window.Window | undefined = undefined; 7877 // Create a child window. 7878 try { 7879 let subWindow = windowStage.createSubWindow("testSubWindow"); 7880 subWindow.then((data) => { 7881 if (data == null) { 7882 console.error("Failed to create the subWindow. Cause: The data is empty"); 7883 return; 7884 } 7885 windowClass = data; 7886 let enabled = false; 7887 let promise = windowClass.setRaiseByClickEnabled(enabled); 7888 promise.then(()=> { 7889 console.info('Succeeded in disabling the raise-by-click function.'); 7890 }).catch((err: BusinessError)=>{ 7891 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 7892 }); 7893 }); 7894 } catch (exception) { 7895 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7896 } 7897 } 7898} 7899``` 7900 7901### enableLandscapeMultiWindow<sup>12+</sup> 7902 7903enableLandscapeMultiWindow(): Promise<void> 7904 7905Enables the landscape multi-window mode for the UI page that supports the horizontal layout. You are not advised to call this API for the UI page that adopts the vertical layout. 7906 7907This API takes effect only for the main window of the application. In addition, **preferMultiWindowOrientation** must be set to **landscape_auto** in the [abilities](../../quick-start/module-configuration-file.md#abilities) tag in the **module.json5** file. 7908 7909**Atomic service API**: This API can be used in atomic services since API version 12. 7910 7911**System capability**: SystemCapability.Window.SessionManager 7912 7913**Return value** 7914 7915| Type | Description | 7916| ------------------- | ------------------------------ | 7917| Promise<void> | Promise that returns no value. | 7918 7919**Error codes** 7920 7921For details about the error codes, see [Window Error Codes](errorcode-window.md). 7922 7923| ID | Error Message | 7924| ------- | --------------------------------------------- | 7925| 1300002 | This window state is abnormal. | 7926| 1300003 | This window manager service works abnormally. | 7927 7928**Example** 7929 7930```ts 7931// EntryAbility.ets 7932import { UIAbility } from '@kit.AbilityKit'; 7933import { BusinessError } from '@kit.BasicServicesKit'; 7934import { window } from '@kit.ArkUI'; 7935 7936export default class EntryAbility extends UIAbility { 7937 // ... 7938 onWindowStageCreate(windowStage: window.WindowStage): void { 7939 console.info('onWindowStageCreate'); 7940 let windowClass: window.Window | undefined = undefined; 7941 windowStage.getMainWindow((err: BusinessError, data) => { 7942 const errCode: number = err.code; 7943 if (errCode) { 7944 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7945 return; 7946 } 7947 windowClass = data; 7948 let promise = windowClass.enableLandscapeMultiWindow(); 7949 promise.then(() => { 7950 console.info('Succeeded in making multi-window become landscape.'); 7951 }).catch((err: BusinessError) => { 7952 console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`); 7953 }); 7954 }); 7955 } 7956} 7957``` 7958 7959### disableLandscapeMultiWindow<sup>12+</sup> 7960 7961disableLandscapeMultiWindow(): Promise<void> 7962 7963Disables the landscape multi-window mode for the UI page that supports the horizontal layout. 7964 7965This API takes effect only for the main window of the application. In addition, **preferMultiWindowOrientation** must be set to **landscape_auto** in the [abilities](../../quick-start/module-configuration-file.md#abilities) tag in the **module.json5** file. 7966 7967**Atomic service API**: This API can be used in atomic services since API version 12. 7968 7969**System capability**: SystemCapability.Window.SessionManager 7970 7971**Return value** 7972 7973| Type | Description | 7974| ------------------- | ------------------------------ | 7975| Promise<void> | Promise that returns no value. | 7976 7977**Error codes** 7978 7979For details about the error codes, see [Window Error Codes](errorcode-window.md). 7980 7981| ID | Error Message | 7982| ------- | --------------------------------------------- | 7983| 1300002 | This window state is abnormal. | 7984| 1300003 | This window manager service works abnormally. | 7985 7986**Example** 7987 7988```ts 7989// EntryAbility.ets 7990import { UIAbility } from '@kit.AbilityKit'; 7991import { BusinessError } from '@kit.BasicServicesKit'; 7992import { window } from '@kit.ArkUI'; 7993 7994export default class EntryAbility extends UIAbility { 7995 // ... 7996 onWindowStageCreate(windowStage: window.WindowStage): void { 7997 console.info('onWindowStageCreate'); 7998 let windowClass: window.Window | undefined = undefined; 7999 windowStage.getMainWindow((err: BusinessError, data) => { 8000 const errCode: number = err.code; 8001 if (errCode) { 8002 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8003 return; 8004 } 8005 windowClass = data; 8006 let promise = windowClass.disableLandscapeMultiWindow(); 8007 promise.then(() => { 8008 console.info('Succeeded in making multi-window become not landscape.'); 8009 }).catch((err: BusinessError) => { 8010 console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`); 8011 }); 8012 }); 8013 } 8014} 8015``` 8016 8017### setDialogBackGestureEnabled<sup>12+</sup> 8018 8019setDialogBackGestureEnabled(enabled: boolean): Promise<void> 8020 8021Sets whether the modal window responds to the back gesture event. An error code is returned if this API is called for a non-modal window. 8022 8023**System capability**: SystemCapability.Window.SessionManager 8024 8025**Atomic service API**: This API can be used in atomic services since API version 12. 8026 8027**Parameters** 8028 8029| Name | Type | Mandatory | Description | 8030| ------- | ------- | --------- | ------------------------------------------------------------ | 8031| enabled | boolean | Yes | Whether to respond to the back gesture event.<br>The value **true** means to respond to the back gesture event and trigger the **onBackPress** callback, and **false** means the opposite.<br> | 8032 8033**Return value** 8034 8035| Type | Description | 8036| ------------------- | ------------------------------ | 8037| Promise<void> | Promise that returns no value. | 8038 8039**Error codes** 8040 8041For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8042 8043| ID | Error Message | 8044| ------- | ------------------------------------------------------------ | 8045| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8046| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8047| 1300002 | This window state is abnormal. | 8048| 1300003 | This window manager service works abnormally. | 8049| 1300004 | Unauthorized operation. | 8050 8051**Example** 8052 8053```ts 8054// EntryAbility.ets 8055import { UIAbility } from '@kit.AbilityKit'; 8056import { BusinessError } from '@kit.BasicServicesKit'; 8057 8058export default class EntryAbility extends UIAbility { 8059 onWindowStageCreate(windowStage: window.WindowStage): void { 8060 console.info('onWindowStageCreate'); 8061 let windowClass: window.Window | undefined = undefined; 8062 let config: window.Configuration = { 8063 name: "test", 8064 windowType: window.WindowType.TYPE_DIALOG, 8065 ctx: this.context 8066 }; 8067 try { 8068 window.createWindow(config, (err: BusinessError, data) => { 8069 const errCode: number = err.code; 8070 if (errCode) { 8071 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 8072 return; 8073 } 8074 windowClass = data; 8075 windowClass.setUIContent("pages/Index"); 8076 let enabled = true; 8077 let promise = windowClass.setDialogBackGestureEnabled(enabled); 8078 promise.then(() => { 8079 console.info('Succeeded in setting dialog window to respond back gesture.'); 8080 }).catch((err: BusinessError) => { 8081 console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`); 8082 }); 8083 }); 8084 } catch (exception) { 8085 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 8086 } 8087 } 8088} 8089``` 8090 8091```ts 8092// ets/pages/Index.ets 8093@Entry 8094@Component 8095struct Index { 8096 @State message: string = 'Hello World' 8097 build() { 8098 RelativeContainer() { 8099 Text(this.message) 8100 .id('HelloWorld') 8101 .fontSize(50) 8102 .fontWeight(FontWeight.Bold) 8103 } 8104 .height('100%') 8105 .width('100%') 8106 } 8107 8108 onBackPress(): boolean | void { 8109 console.info('Succeeded in setting dialog window to respond back gesture.'); 8110 return true; 8111 } 8112} 8113``` 8114 8115### startMoving<sup>14+</sup> 8116 8117startMoving(): Promise<void> 8118 8119Starts moving this window. This API uses a promise to return the result. 8120 8121The window moves along with the cursor only when this API is called in the callback function of [onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent), where the event type is **TouchType.Down**. 8122 8123<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 8124 8125This API takes effect only for the main window, child window, and system window. If it is called for other device types or window types, an error is reported. 8126 8127**System capability**: SystemCapability.Window.SessionManager 8128 8129**Atomic service API**: This API can be used in atomic services since API version 14. 8130 8131**Return value** 8132 8133| Type | Description | 8134| ------------------- | ------------------------------ | 8135| Promise<void> | Promise that returns no value. | 8136 8137**Error codes** 8138 8139For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8140 8141| ID | Error Message | 8142| ------- | ------------------------------------------------------------ | 8143| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8144| 1300001 | Repeated operation. | 8145| 1300002 | This window state is abnormal. | 8146| 1300003 | This window manager service works abnormally. | 8147| 1300004 | Unauthorized operation. | 8148 8149**Example** 8150 8151```ts 8152// ets/pages/Index.ets 8153import { BusinessError } from '@kit.BasicServicesKit'; 8154 8155@Entry 8156@Component 8157struct Index { 8158 build() { 8159 Row() { 8160 Column() { 8161 Blank('160') 8162 .color(Color.Blue) 8163 .onTouch((event: TouchEvent) => { 8164 if (event.type === TouchType.Down) { 8165 try { 8166 windowClass.startMoving().then(() => { 8167 console.info('Succeeded in starting moving window.') 8168 }).catch((err: BusinessError) => { 8169 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8170 }); 8171 } catch (exception) { 8172 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8173 } 8174 } 8175 }) 8176 }.width('100%') 8177 }.height('100%').width('100%') 8178 } 8179} 8180``` 8181 8182### startMoving<sup>15+</sup> 8183 8184startMoving(offsetX: number, offsetY: number): Promise<void> 8185 8186Specifies the cursor position within the window and moves the window. This API uses a promise to return the result. 8187 8188When windows within the same application are split or merged, and the mouse is pressed down to move the new window directly, the cursor may move outside the window if it moves too quickly. This API allows you to set the cursor position within the window during movement. It first adjusts the window to the cursor position before starting to move the window. 8189 8190The window moves along with the cursor only when this API is called in the callback function of [onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent), where the event type is **TouchType.Down**. 8191 8192<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 8193 8194**System capability**: SystemCapability.Window.SessionManager 8195 8196**Atomic service API**: This API can be used in atomic services since API version 15. 8197 8198**Parameters** 8199 8200| Name | Type | Mandatory | Description | 8201| ------- | ------ | --------- | ------------------------------------------------------------ | 8202| offsetX | number | Yes | X-axis offset of the cursor position relative to the upper left corner of the window during movement, measured in px. This parameter only accepts integer values; any floating-point input will be rounded down. Negative values or values exceeding the window width are invalid. The window width can be obtained from [WindowProperties](#windowproperties). | 8203| offsetY | number | Yes | Y-axis offset of the cursor position relative to the upper left corner of the window during movement, measured in px. This parameter only accepts integer values; any floating-point input will be rounded down. Negative values or values exceeding the window height are invalid. The window height can be obtained from [WindowProperties](#windowproperties). | 8204 8205**Return value** 8206 8207| Type | Description | 8208| ------------------- | ------------------------------ | 8209| Promise<void> | Promise that returns no value. | 8210 8211**Error codes** 8212 8213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8214 8215| ID | Error Message | 8216| ------- | ------------------------------------------------------------ | 8217| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8218| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8219| 1300001 | Repeated operation. | 8220| 1300002 | This window state is abnormal. | 8221| 1300003 | This window manager service works abnormally. | 8222| 1300004 | Unauthorized operation. | 8223 8224**Example** 8225 8226```ts 8227// ets/pages/Index.ets 8228import { BusinessError } from '@kit.BasicServicesKit'; 8229 8230@Entry 8231@Component 8232struct Index { 8233 build() { 8234 Row() { 8235 Column() { 8236 Blank('160') 8237 .color(Color.Blue) 8238 .onTouch((event: TouchEvent) => { 8239 if (event.type === TouchType.Down) { 8240 try { 8241 windowClass.startMoving(100, 50).then(() => { 8242 console.info('Succeeded in starting moving window.') 8243 }).catch((err: BusinessError) => { 8244 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8245 }); 8246 } catch (exception) { 8247 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8248 } 8249 } 8250 }) 8251 }.width('100%') 8252 }.height('100%').width('100%') 8253 } 8254} 8255``` 8256 8257### stopMoving<sup>15+</sup> 8258 8259stopMoving(): Promise<void> 8260 8261Stops window movement when a window is being dragged. This API uses a promise to return the result. 8262 8263<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 8264 8265**System capability**: SystemCapability.Window.SessionManager 8266 8267**Atomic service API**: This API can be used in atomic services since API version 15. 8268 8269**Return value** 8270 8271| Type | Description | 8272| ------------------- | ------------------------------ | 8273| Promise<void> | Promise that returns no value. | 8274 8275**Error codes** 8276 8277For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8278 8279| ID | Error Message | 8280| ------- | ------------------------------------------------------------ | 8281| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8282| 1300002 | This window state is abnormal. | 8283| 1300003 | This window manager service works abnormally. | 8284| 1300004 | Unauthorized operation. | 8285 8286**Example** 8287 8288```ts 8289// EntryAbility.ets 8290import { UIAbility } from '@kit.AbilityKit'; 8291import { window } from '@kit.ArkUI'; 8292import { BusinessError } from '@kit.BasicServicesKit'; 8293 8294export default class EntryAbility extends UIAbility { 8295 8296 onWindowStageCreate(windowStage: window.WindowStage) { 8297 try { 8298 let windowClass = windowStage.getMainWindowSync(); 8299 windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 8300 if (data.reason === window.RectChangeReason.MOVE) { 8301 windowClass.stopMoving().then(() => { 8302 console.info('Succeeded in stopping moving window.') 8303 }).catch((err: BusinessError) => { 8304 console.error(`Failed to stop moving. Cause code: ${err.code}, message: ${err.message}`); 8305 }); 8306 } 8307 }); 8308 } catch (exception) { 8309 console.error(`Failed to stop moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8310 } 8311 } 8312} 8313``` 8314 8315### setGestureBackEnabled<sup>13+<sup> 8316 8317setGestureBackEnabled(enabled: boolean): Promise<void> 8318 8319Sets whether to enable the back gesture feature in this window. This API takes effect only in full-screen mode of the main window and cannot be used on 2-in-1 devices. 8320 8321When the back gesture feature is disabled, the application does not recognize the gesture hot zone for back redirection, causing the side-swipe gesture non-functional. However, after you switch to another application or return to the home screen, the gesture hot zone functions normally and the side-swipe gesture works properly. 8322 8323When the back gesture feature is enabled, the application recognizes the gesture hot zone for back redirection, allowing the side-swipe gesture to function as expected. 8324 8325**System capability**: SystemCapability.Window.SessionManager 8326 8327**Atomic service API**: This API can be used in atomic services since API version 13. 8328 8329**Parameters** 8330 8331| Name | Type | Mandatory | Description | 8332| ------- | ------- | --------- | ------------------------------------------------------------ | 8333| enabled | boolean | Yes | Whether to enable the back gesture feature. The value **true** means to enable the feature, and **false** means the opposite. | 8334 8335**Return value** 8336 8337| Type | Description | 8338| ------------------- | ------------------------------ | 8339| Promise<void> | Promise that returns no value. | 8340 8341**Error codes** 8342 8343For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8344 8345| ID | Error Message | 8346| ------- | ------------------------------------------------------------ | 8347| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8348| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8349| 1300002 | This window state is abnormal. | 8350| 1300003 | This window manager service works abnormally. | 8351| 1300004 | Unauthorized operation. | 8352 8353**Example** 8354 8355```ts 8356// EntryAbility.ets 8357import { UIAbility } from '@kit.AbilityKit'; 8358import { BusinessError } from '@kit.BasicServicesKit'; 8359import { window } from '@kit.ArkUI'; 8360 8361export default class EntryAbility extends UIAbility { 8362 // ... 8363 onWindowStageCreate(windowStage: window.WindowStage): void { 8364 console.info('onWindowStageCreate'); 8365 let windowClass: window.Window | undefined = undefined; 8366 windowStage.getMainWindow((err: BusinessError, data) => { 8367 const errCode: number = err.code; 8368 if (errCode) { 8369 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8370 return; 8371 } 8372 windowClass = data; 8373 8374 // Disable the back gesture feature in the current window. 8375 try { 8376 let gestureBackEnabled: boolean = false; 8377 let promise = windowClass.setGestureBackEnabled(gestureBackEnabled); 8378 promise.then(() => { 8379 console.info(`Succeeded in setting gesture back disabled`); 8380 }).catch((err: BusinessError) => { 8381 console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`); 8382 }); 8383 } catch(exception) { 8384 console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`); 8385 } 8386 }); 8387 } 8388} 8389``` 8390 8391### isGestureBackEnabled<sup>13+<sup> 8392 8393isGestureBackEnabled(): boolean 8394 8395Checks whether the back gesture feature is enabled in this window. This API takes effect only in full-screen mode of the main window and cannot be used on 2-in-1 devices. 8396 8397**System capability**: SystemCapability.Window.SessionManager 8398 8399**Atomic service API**: This API can be used in atomic services since API version 13. 8400 8401**Return value** 8402 8403| Type | Description | 8404| ------- | ------------------------------------------------------------ | 8405| boolean | Whether the back gesture feature is enabled. The value **true** means that the back gesture feature is enabled, and **false** means that it is disabled. | 8406 8407**Error codes** 8408 8409For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8410 8411| ID | Error Message | 8412| ------- | ------------------------------------------------------------ | 8413| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8414| 1300002 | This window state is abnormal. | 8415| 1300003 | This window manager service works abnormally. | 8416| 1300004 | Unauthorized operation. | 8417 8418**Example** 8419 8420```ts 8421// EntryAbility.ets 8422import { UIAbility } from '@kit.AbilityKit'; 8423import { BusinessError } from '@kit.BasicServicesKit'; 8424import { window } from '@kit.ArkUI'; 8425 8426export default class EntryAbility extends UIAbility { 8427 // ... 8428 onWindowStageCreate(windowStage: window.WindowStage): void { 8429 console.info('onWindowStageCreate'); 8430 let windowClass: window.Window | undefined = undefined; 8431 windowStage.getMainWindow((err: BusinessError, data) => { 8432 const errCode: number = err.code; 8433 if (errCode) { 8434 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8435 return; 8436 } 8437 windowClass = data; 8438 8439 // Check whether the back gesture feature is enabled in the current window. 8440 try { 8441 let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled(); 8442 console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`); 8443 } catch (exception) { 8444 console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 8445 } 8446 }); 8447 } 8448} 8449``` 8450 8451### setWindowShadowRadius<sup>18+</sup> 8452 8453setWindowShadowRadius(radius: number): void 8454 8455Sets the blur radius of the shadow on the edges of a child window or floating window. This API can be used only on 2-in-1 devices or tablets. 8456 8457**System capability**: SystemCapability.Window.SessionManager 8458 8459**Atomic service API**: This API can be used in atomic services since API version 18. 8460 8461**Parameters** 8462 8463| Name | Type | Mandatory | Description | 8464| ------ | ------ | --------- | ------------------------------------------------------------ | 8465| radius | number | Yes | Radius of the shadow, measured in px. The value is a floating point number greater than or equal to 0.0, and the value **0.0** means that the shadow is disabled for the window borders. | 8466 8467**Error codes** 8468 8469For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8470 8471| ID | Error Message | 8472| ------- | ------------------------------------------------------------ | 8473| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8474| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8475| 1300002 | This window state is abnormal. | 8476| 1300004 | Unauthorized operation. | 8477 8478**Example** 8479 8480```ts 8481try { 8482 windowClass.setWindowShadowRadius(4.0); 8483} catch (exception) { 8484 console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`); 8485} 8486``` 8487 8488### setWindowCornerRadius<sup>18+</sup> 8489 8490setWindowCornerRadius(cornerRadius: number): Promise<void> 8491 8492Sets the radius of the rounded corners for a child window or floating window. This API uses a promise to return the result. 8493 8494<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 8495 8496If the radius of the rounded corner is too large, it may cause the three buttons (maximize, minimize, and close) to be clipped and make their hotspots less recognizable. Set an appropriate radius based on the window size. 8497 8498Before calling this API, you can call [getWindowCornerRadius()](#getwindowcornerradius18) to obtain the default radius of rounded corners of the window. 8499 8500**System capability**: SystemCapability.Window.SessionManager 8501 8502**Atomic service API**: This API can be used in atomic services since API version 18. 8503 8504**Parameters** 8505 8506| Name | Type | Mandatory | Description | 8507| ------------ | ------ | --------- | ------------------------------------------------------------ | 8508| cornerRadius | number | Yes | Radius of the rounded corners, measured in vp. The value is a floating point number greater than or equal to 0.0. The value **0.0** means that the window does not use rounded corners. | 8509 8510**Return value** 8511 8512| Type | Description | 8513| ------------------- | ------------------------------ | 8514| Promise<void> | Promise that returns no value. | 8515 8516**Error codes** 8517 8518For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8519 8520| ID | Error Message | 8521| ------- | ------------------------------------------------------------ | 8522| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8523| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8524| 1300002 | This window state is abnormal. | 8525| 1300003 | This window manager service works abnormally. | 8526| 1300004 | Unauthorized operation. | 8527 8528**Example** 8529 8530```ts 8531import { BusinessError } from '@kit.BasicServicesKit'; 8532 8533try{ 8534 let promise = windowClass.setWindowCornerRadius(1.0); 8535 promise.then(() => { 8536 console.info('Succeeded in setting window corner radius.'); 8537 }).catch((err: BusinessError) => { 8538 console.error(`Failed to set window corner radius. Cause code: ${err.code}, message: ${err.message}`); 8539 }); 8540} catch (exception) { 8541 console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8542} 8543 8544``` 8545 8546### getWindowCornerRadius<sup>18+</sup> 8547 8548getWindowCornerRadius(): number 8549 8550Obtains the radius of rounded corners of a child window or floating window. If [setWindowCornerRadius()](#setwindowcornerradius18) is not called to set the radius of rounded corners, this API returns the default radius of rounded corners. 8551 8552<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 8553 8554**System capability**: SystemCapability.Window.SessionManager 8555 8556**Atomic service API**: This API can be used in atomic services since API version 18. 8557 8558**Return value** 8559 8560| Type | Description | 8561| ------ | ------------------------------------------------------------ | 8562| number | Radius of the rounded corner of the child window or floating window, measured in vp. | 8563 8564**Error codes** 8565 8566For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8567 8568| ID | Error Message | 8569| ------- | ------------------------------------------------------------ | 8570| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8571| 1300002 | This window state is abnormal. | 8572| 1300004 | Unauthorized operation. | 8573 8574**Example** 8575 8576```ts 8577try { 8578 let cornerRadius = windowClass.getWindowCornerRadius(); 8579} catch (exception) { 8580 console.error(`Failed to get corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8581} 8582``` 8583 8584### setExclusivelyHighlighted<sup>15+<sup> 8585 8586setExclusivelyHighlighted(exclusivelyHighlighted: boolean): Promise<void> 8587 8588Sets the exclusive highlight property for the window. When a window set to exclusive highlight gains focus, other windows in the current parent-child window chain that are in the highlighted state will lose their highlighted state. This API uses a promise to return the result. 8589 8590This API does not take effect for the main window, modal window, and dialog boxes. 8591 8592**System capability**: SystemCapability.Window.SessionManager 8593 8594**Atomic service API**: This API can be used in atomic services since API version 15. 8595 8596**Parameters** 8597 8598| Name | Type | Mandatory | Description | 8599| ---------------------- | ------- | --------- | ------------------------------------------------------------ | 8600| exclusivelyHighlighted | boolean | Yes | Whether to set exclusive highlight for the window. The value **true** means to set exclusive highlight for the window, and **false** means the opposite. | 8601 8602**Return value** 8603 8604| Type | Description | 8605| ------------------- | ------------------------------ | 8606| Promise<void> | Promise that returns no value. | 8607 8608**Error codes** 8609 8610For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8611 8612| ID | Error Message | 8613| ------- | ------------------------------------------------------------ | 8614| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8615| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8616| 1300002 | This window state is abnormal. | 8617| 1300003 | This window manager service works abnormally. | 8618| 1300004 | Unauthorized operation. | 8619 8620**Example** 8621 8622```ts 8623import { BusinessError } from '@kit.BasicServicesKit'; 8624 8625let exclusivelyHighlighted: boolean = true; 8626try { 8627 let promise = windowClass.setExclusivelyHighlighted(exclusivelyHighlighted); 8628 promise.then(() => { 8629 console.info('Succeeded in setting the window to be exclusively highlight.'); 8630 }).catch((err: BusinessError) => { 8631 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${err.code}, message: ${err.message}`); 8632 }); 8633} catch (exception) { 8634 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${exception.code}, message: ${exception.message}`); 8635} 8636``` 8637 8638### setWindowSystemBarProperties<sup>(deprecated)</sup> 8639 8640setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 8641 8642Sets the properties of the three-button navigation bar and status bar of the main window. This API uses an asynchronous callback to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 8643 8644This API does not take effect when it is called by a child window. 8645 8646> **NOTE** 8647> 8648> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowSystemBarProperties](#setwindowsystembarproperties9) in promise mode instead. 8649 8650**System capability**: SystemCapability.WindowManager.WindowManager.Core 8651 8652**Atomic service API**: This API can be used in atomic services since API version 12. 8653 8654**Parameters** 8655 8656| Name | Type | Mandatory | Description | 8657| ------------------- | ------------------------------------------- | --------- | ------------------------------------------------------------ | 8658| systemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the three-button navigation bar and status bar. | 8659| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8660 8661**Error codes** 8662 8663For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8664 8665| ID | Error Message | 8666| ------- | ------------------------------------------------------------ | 8667| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8668| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8669| 1300002 | This window state is abnormal. | 8670| 1300003 | This window manager service works abnormally. | 8671 8672**Example** 8673 8674```ts 8675// EntryAbility.ets 8676import { UIAbility } from '@kit.AbilityKit'; 8677import { BusinessError } from '@kit.BasicServicesKit'; 8678 8679export default class EntryAbility extends UIAbility { 8680 // ... 8681 onWindowStageCreate(windowStage: window.WindowStage): void { 8682 console.info('onWindowStageCreate'); 8683 let windowClass: window.Window | undefined = undefined; 8684 windowStage.getMainWindow((err: BusinessError, data) => { 8685 const errCode: number = err.code; 8686 if (errCode) { 8687 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8688 return; 8689 } 8690 windowClass = data; 8691 let SystemBarProperties: window.SystemBarProperties = { 8692 statusBarColor: '#ff00ff', 8693 navigationBarColor: '#00ff00', 8694 // The following properties are supported since API version 8. 8695 statusBarContentColor: '#ffffff', 8696 navigationBarContentColor: '#00ffff' 8697 }; 8698 try { 8699 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 8700 const errCode: number = err.code; 8701 if (errCode) { 8702 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 8703 return; 8704 } 8705 console.info('Succeeded in setting the system bar properties.'); 8706 }); 8707 } catch (exception) { 8708 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 8709 } 8710 }); 8711 } 8712} 8713``` 8714 8715### setWindowSystemBarEnable<sup>(deprecated)</sup> 8716 8717setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 8718 8719Sets whether to show the three-button navigation bar, status bar, and bottom navigation bar of the main window. This API uses an asynchronous callback to return the result. The display of the status bar and bottom navigation bar is controlled by **status**, and that of the three-button navigation bar is controlled by **navigation**. From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 8720 8721The return value does not indicate that the visibility changes of the three-button navigation bar, status bar, and bottom navigation bar have been fully executed. This API does not take effect when it is called by a child window. 8722 8723> **NOTE** 8724> 8725> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowSystemBarEnable](#setwindowsystembarenable9) in promise mode instead. 8726 8727**Atomic service API**: This API can be used in atomic services since API version 12. 8728 8729**System capability**: SystemCapability.WindowManager.WindowManager.Core 8730 8731**Parameters** 8732 8733| Name | Type | Mandatory | Description | 8734| -------- | ----------------------------- | --------- | ------------------------------------------------------------ | 8735| names | Array<'status'\|'navigation'> | Yes | Whether to show the three-button navigation bar, status bar, and bottom navigation bar of the window in full-screen mode.<br>For example, to display all of them, set this parameter to **['status', 'navigation']**. By default, they are not displayed. | 8736| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8737 8738**Error codes** 8739 8740For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8741 8742| ID | Error Message | 8743| ------- | ------------------------------------------------------------ | 8744| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8745| 1300002 | This window state is abnormal. | 8746| 1300003 | This window manager service works abnormally. | 8747 8748**Example** 8749 8750```ts 8751// In this example, the three-button navigation bar, status bar, and bottom navigation bar are not displayed. 8752// EntryAbility.ets 8753import { UIAbility } from '@kit.AbilityKit'; 8754import { BusinessError } from '@kit.BasicServicesKit'; 8755 8756export default class EntryAbility extends UIAbility { 8757 // ... 8758 onWindowStageCreate(windowStage: window.WindowStage): void { 8759 console.info('onWindowStageCreate'); 8760 let windowClass: window.Window | undefined = undefined; 8761 windowStage.getMainWindow((err: BusinessError, data) => { 8762 const errCode: number = err.code; 8763 if (errCode) { 8764 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8765 return; 8766 } 8767 windowClass = data; 8768 let names: Array<'status' | 'navigation'> = []; 8769 try { 8770 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 8771 const errCode: number = err.code; 8772 if (errCode) { 8773 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 8774 return; 8775 } 8776 console.info('Succeeded in setting the system bar to be invisible.'); 8777 }); 8778 } catch (exception) { 8779 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 8780 } 8781 }); 8782 } 8783} 8784``` 8785 8786### setWindowLayoutFullScreen<sup>(deprecated)</sup> 8787 8788setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 8789 8790Sets whether the main window layout or the child window layout is immersive. This API uses an asynchronous callback to return the result. 8791- An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 8792- A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 8793 8794> **NOTE** 8795> 8796> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowLayoutFullScreen](#setwindowlayoutfullscreen9) in promise mode instead. 8797 8798**System capability**: SystemCapability.WindowManager.WindowManager.Core 8799 8800**Atomic service API**: This API can be used in atomic services since API version 12. 8801 8802**Parameters** 8803 8804| Name | Type | Mandatory | Description | 8805| ------------------ | ------------------------- | --------- | ------------------------------------------------------------ | 8806| isLayoutFullScreen | boolean | Yes | Whether the window layout is immersive. (The status bar and navigation bar of the immersive layout are still displayed.) The value **true** means that the window layout is immersive, and **false** means the opposite. | 8807| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8808 8809**Error codes** 8810 8811For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8812 8813| ID | Error Message | 8814| ------- | ------------------------------------------------------------ | 8815| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8816| 1300002 | This window state is abnormal. | 8817| 1300003 | This window manager service works abnormally. | 8818 8819**Example** 8820 8821```ts 8822// EntryAbility.ets 8823import { UIAbility } from '@kit.AbilityKit'; 8824import { BusinessError } from '@kit.BasicServicesKit'; 8825 8826export default class EntryAbility extends UIAbility { 8827 // ... 8828 onWindowStageCreate(windowStage: window.WindowStage): void { 8829 console.info('onWindowStageCreate'); 8830 let windowClass: window.Window | undefined = undefined; 8831 windowStage.getMainWindow((err: BusinessError, data) => { 8832 const errCode: number = err.code; 8833 if (errCode) { 8834 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8835 return; 8836 } 8837 windowClass = data; 8838 let isLayoutFullScreen = true; 8839 try { 8840 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 8841 const errCode: number = err.code; 8842 if (errCode) { 8843 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8844 return; 8845 } 8846 console.info('Succeeded in setting the window layout to full-screen mode.'); 8847 }); 8848 } catch (exception) { 8849 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 8850 } 8851 }); 8852 } 8853} 8854``` 8855 8856### show<sup>(deprecated)</sup> 8857 8858show(callback: AsyncCallback<void>): void 8859 8860Shows this window. This API uses an asynchronous callback to return the result. 8861 8862> **NOTE** 8863> 8864> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9) instead. 8865 8866**System capability**: SystemCapability.WindowManager.WindowManager.Core 8867 8868**Parameters** 8869 8870| Name | Type | Mandatory | Description | 8871| -------- | ------------------------- | --------- | ----------------------------------- | 8872| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8873 8874**Example** 8875 8876```ts 8877import { BusinessError } from '@kit.BasicServicesKit'; 8878 8879windowClass.show((err: BusinessError) => { 8880 const errCode: number = err.code; 8881 if (errCode) { 8882 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 8883 return; 8884 } 8885 console.info('Succeeded in showing the window.'); 8886}); 8887``` 8888 8889### show<sup>(deprecated)</sup> 8890 8891show(): Promise<void> 8892 8893Shows this window. This API uses a promise to return the result. 8894 8895> **NOTE** 8896> 8897> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9-1) instead. 8898 8899**System capability**: SystemCapability.WindowManager.WindowManager.Core 8900 8901**Return value** 8902 8903| Type | Description | 8904| ------------------- | ------------------------------ | 8905| Promise<void> | Promise that returns no value. | 8906 8907**Example** 8908 8909```ts 8910import { BusinessError } from '@kit.BasicServicesKit'; 8911 8912let promise = windowClass.show(); 8913promise.then(() => { 8914 console.info('Succeeded in showing the window.'); 8915}).catch((err: BusinessError) => { 8916 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 8917}); 8918``` 8919 8920### destroy<sup>(deprecated)</sup> 8921 8922destroy(callback: AsyncCallback<void>): void 8923 8924Destroys this window. This API uses an asynchronous callback to return the result. 8925 8926> **NOTE** 8927> 8928> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9) instead. 8929 8930**System capability**: SystemCapability.WindowManager.WindowManager.Core 8931 8932**Parameters** 8933 8934| Name | Type | Mandatory | Description | 8935| -------- | ------------------------- | --------- | ----------------------------------- | 8936| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8937 8938**Example** 8939 8940```ts 8941import { BusinessError } from '@kit.BasicServicesKit'; 8942 8943windowClass.destroy((err: BusinessError) => { 8944 const errCode: number = err.code; 8945 if (err.code) { 8946 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 8947 return; 8948 } 8949 console.info('Succeeded in destroying the window.'); 8950}); 8951``` 8952 8953### destroy<sup>(deprecated)</sup> 8954 8955destroy(): Promise<void> 8956 8957Destroys this window. This API uses a promise to return the result. 8958 8959> **NOTE** 8960> 8961> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9-1) instead. 8962 8963**System capability**: SystemCapability.WindowManager.WindowManager.Core 8964 8965**Return value** 8966 8967| Type | Description | 8968| ------------------- | ------------------------------ | 8969| Promise<void> | Promise that returns no value. | 8970 8971**Example** 8972 8973```ts 8974import { BusinessError } from '@kit.BasicServicesKit'; 8975 8976let promise = windowClass.destroy(); 8977promise.then(() => { 8978 console.info('Succeeded in destroying the window.'); 8979}).catch((err: BusinessError) => { 8980 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 8981}); 8982``` 8983 8984### moveTo<sup>(deprecated)</sup> 8985 8986moveTo(x: number, y: number, callback: AsyncCallback<void>): void 8987 8988Moves this window. This API uses an asynchronous callback to return the result. 8989 8990This operation is not supported in a window in full-screen mode. 8991 8992> **NOTE** 8993> 8994> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9) instead. 8995 8996**System capability**: SystemCapability.WindowManager.WindowManager.Core 8997 8998**Parameters** 8999 9000| Name | Type | Mandatory | Description | 9001| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 9002| x | number | Yes | Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down. | 9003| y | number | Yes | Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down. | 9004| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9005 9006**Example** 9007 9008```ts 9009import { BusinessError } from '@kit.BasicServicesKit'; 9010 9011windowClass.moveTo(300, 300, (err: BusinessError) => { 9012 const errCode: number = err.code; 9013 if (errCode) { 9014 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9015 return; 9016 } 9017 console.info('Succeeded in moving the window.'); 9018}); 9019``` 9020 9021### moveTo<sup>(deprecated)</sup> 9022 9023moveTo(x: number, y: number): Promise<void> 9024 9025Moves this window. This API uses a promise to return the result. 9026 9027This operation is not supported in a window in full-screen mode. 9028 9029> **NOTE** 9030> 9031> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9-1) instead. 9032 9033**System capability**: SystemCapability.WindowManager.WindowManager.Core 9034 9035**Parameters** 9036 9037| Name | Type | Mandatory | Description | 9038| ---- | ------ | --------- | ------------------------------------------------------------ | 9039| x | number | Yes | Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down. | 9040| y | number | Yes | Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. If a non-integer is passed in, the value is rounded down. | 9041 9042**Return value** 9043 9044| Type | Description | 9045| ------------------- | ------------------------------ | 9046| Promise<void> | Promise that returns no value. | 9047 9048**Example** 9049 9050```ts 9051import { BusinessError } from '@kit.BasicServicesKit'; 9052 9053let promise = windowClass.moveTo(300, 300); 9054promise.then(() => { 9055 console.info('Succeeded in moving the window.'); 9056}).catch((err: BusinessError) => { 9057 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9058}); 9059``` 9060 9061### resetSize<sup>(deprecated)</sup> 9062 9063resetSize(width: number, height: number, callback: AsyncCallback<void>): void 9064 9065Changes the size of this window. This API uses an asynchronous callback to return the result. 9066 9067- The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 9068- The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 9069 9070The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 9071 9072The window width and height you set must meet the limits. The rules are as follows: 9073- If the window width or height you set is less than the minimum width or height limit, then the minimum width or height limit takes effect. 9074- If the window width or height you set is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 9075 9076This operation is not supported in a window in full-screen mode. 9077 9078> **NOTE** 9079> 9080> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9) instead. 9081 9082**System capability**: SystemCapability.WindowManager.WindowManager.Core 9083 9084**Parameters** 9085 9086| Name | Type | Mandatory | Description | 9087| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 9088| width | number | Yes | New width of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid. | 9089| height | number | Yes | New height of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid. | 9090| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9091 9092**Example** 9093 9094```ts 9095import { BusinessError } from '@kit.BasicServicesKit'; 9096 9097windowClass.resetSize(500, 1000, (err: BusinessError) => { 9098 const errCode: number = err.code; 9099 if (errCode) { 9100 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 9101 return; 9102 } 9103 console.info('Succeeded in changing the window size.'); 9104}); 9105``` 9106 9107### resetSize<sup>(deprecated)</sup> 9108 9109resetSize(width: number, height: number): Promise<void> 9110 9111Changes the size of this window. This API uses a promise to return the result. 9112 9113- The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 9114- The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 9115 9116The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 9117 9118The window width and height you set must meet the limits. The rules are as follows: 9119- If the window width or height you set is less than the minimum width or height limit, then the minimum width or height limit takes effect. 9120- If the window width or height you set is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 9121 9122This operation is not supported in a window in full-screen mode. 9123 9124> **NOTE** 9125> 9126> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9-1) instead. 9127 9128**System capability**: SystemCapability.WindowManager.WindowManager.Core 9129 9130**Parameters** 9131 9132| Name | Type | Mandatory | Description | 9133| ------ | ------ | --------- | ------------------------------------------------------------ | 9134| width | number | Yes | New width of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid. | 9135| height | number | Yes | New height of the window, in px. The value must be an integer. If a floating point number is passed in, the value is rounded down. A negative value is invalid. | 9136 9137**Return value** 9138 9139| Type | Description | 9140| ------------------- | ------------------------------ | 9141| Promise<void> | Promise that returns no value. | 9142 9143**Example** 9144 9145```ts 9146import { BusinessError } from '@kit.BasicServicesKit'; 9147 9148let promise = windowClass.resetSize(500, 1000); 9149promise.then(() => { 9150 console.info('Succeeded in changing the window size.'); 9151}).catch((err: BusinessError) => { 9152 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 9153}); 9154``` 9155 9156### getProperties<sup>(deprecated)</sup> 9157 9158getProperties(callback: AsyncCallback<WindowProperties>): void 9159 9160Obtains the properties of this window. This API uses an asynchronous callback to return the result. 9161 9162> **NOTE** 9163> 9164> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 9165 9166**System capability**: SystemCapability.WindowManager.WindowManager.Core 9167 9168**Parameters** 9169 9170| Name | Type | Mandatory | Description | 9171| -------- | ---------------------------------------------------------- | --------- | ---------------------------------------------- | 9172| callback | AsyncCallback<[WindowProperties](#windowproperties)> | Yes | Callback used to return the window properties. | 9173 9174**Example** 9175 9176```ts 9177import { BusinessError } from '@kit.BasicServicesKit'; 9178 9179windowClass.getProperties((err: BusinessError, data) => { 9180 const errCode: number = err.code; 9181 if (errCode) { 9182 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 9183 return; 9184 } 9185 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 9186}); 9187``` 9188 9189### getProperties<sup>(deprecated)</sup> 9190 9191getProperties(): Promise<WindowProperties> 9192 9193Obtains the properties of this window. This API uses a promise to return the result. 9194 9195> **NOTE** 9196> 9197> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 9198 9199**System capability**: SystemCapability.WindowManager.WindowManager.Core 9200 9201**Return value** 9202 9203| Type | Description | 9204| ---------------------------------------------------- | --------------------------------------------- | 9205| Promise<[WindowProperties](#windowproperties)> | Promise used to return the window properties. | 9206 9207**Example** 9208 9209```ts 9210import { BusinessError } from '@kit.BasicServicesKit'; 9211 9212let promise = windowClass.getProperties(); 9213promise.then((data) => { 9214 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 9215}).catch((err: BusinessError) => { 9216 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 9217}); 9218``` 9219 9220### getAvoidArea<sup>(deprecated)</sup> 9221 9222getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 9223 9224Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. This API uses an asynchronous callback to return the result. 9225 9226> **NOTE** 9227> 9228> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 9229 9230**System capability**: SystemCapability.WindowManager.WindowManager.Core 9231 9232**Parameters** 9233 9234| Name | Type | Mandatory | Description | 9235| -------- | --------------------------------------------- | --------- | --------------------------------- | 9236| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. | 9237| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 9238 9239**Example** 9240 9241```ts 9242import { BusinessError } from '@kit.BasicServicesKit'; 9243 9244let type = window.AvoidAreaType.TYPE_SYSTEM; 9245windowClass.getAvoidArea(type, (err: BusinessError, data) => { 9246 const errCode: number = err.code; 9247 if (errCode) { 9248 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 9249 return; 9250 } 9251 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 9252}); 9253``` 9254 9255### getAvoidArea<sup>(deprecated)</sup> 9256 9257getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 9258 9259Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. This API uses an asynchronous callback to return the result. 9260 9261> **NOTE** 9262> 9263> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 9264 9265**System capability**: SystemCapability.WindowManager.WindowManager.Core 9266 9267**Parameters** 9268 9269| Name | Type | Mandatory | Description | 9270| ---- | -------------------------------- | --------- | ----------------- | 9271| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. | 9272 9273**Return value** 9274 9275| Type | Description | 9276| --------------------------------------- | -------------------------------- | 9277| Promise<[AvoidArea](#avoidarea7)> | Promise used to return the area. | 9278 9279**Example** 9280 9281```ts 9282import { BusinessError } from '@kit.BasicServicesKit'; 9283 9284let type = window.AvoidAreaType.TYPE_SYSTEM; 9285let promise = windowClass.getAvoidArea(type); 9286promise.then((data) => { 9287 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 9288}).catch((err: BusinessError) => { 9289 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 9290}); 9291``` 9292 9293### setFullScreen<sup>(deprecated)</sup> 9294 9295setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 9296 9297Sets whether the main window or the child window is in full-screen mode. This API uses an asynchronous callback to return the result. 9298- In full-screen mode, the layout does not avoid the status bar and navigation bar, and components may overlap with them. 9299- In non-full-screen mode, the layout avoids the status bar and navigation bar, and components do not overlap with them. 9300 9301> **NOTE** 9302> 9303> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) and [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) to implement the full-screen mode. 9304 9305**System capability**: SystemCapability.WindowManager.WindowManager.Core 9306 9307**Parameters** 9308 9309| Name | Type | Mandatory | Description | 9310| ------------ | ------------------------- | --------- | ------------------------------------------------------------ | 9311| isFullScreen | boolean | Yes | Whether to set full-screen mode. This setting affects the display of the status bar and navigation bar. The value **true** means to set full-screen mode, and **false** means the opposite. | 9312| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9313 9314**Example** 9315 9316```ts 9317// EntryAbility.ets 9318import { UIAbility } from '@kit.AbilityKit'; 9319import { BusinessError } from '@kit.BasicServicesKit'; 9320 9321export default class EntryAbility extends UIAbility { 9322 // ... 9323 onWindowStageCreate(windowStage: window.WindowStage): void { 9324 console.info('onWindowStageCreate'); 9325 let windowClass: window.Window | undefined = undefined; 9326 windowStage.getMainWindow((err: BusinessError, data) => { 9327 const errCode: number = err.code; 9328 if (errCode) { 9329 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9330 return; 9331 } 9332 windowClass = data; 9333 let isFullScreen: boolean = true; 9334 windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 9335 const errCode: number = err.code; 9336 if (errCode) { 9337 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9338 return; 9339 } 9340 console.info('Succeeded in enabling the full-screen mode.'); 9341 }); 9342 }); 9343 } 9344} 9345``` 9346 9347### setFullScreen<sup>(deprecated)</sup> 9348 9349setFullScreen(isFullScreen: boolean): Promise<void> 9350 9351Sets whether the main window or the child window is in full-screen mode. This API uses a promise to return the result. 9352- In full-screen mode, the layout does not avoid the status bar and navigation bar, and components may overlap with them. 9353- In non-full-screen mode, the layout avoids the status bar and navigation bar, and components do not overlap with them. 9354 9355> **NOTE** 9356> 9357> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9-1) and [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1) to implement the full-screen mode. 9358 9359**System capability**: SystemCapability.WindowManager.WindowManager.Core 9360 9361**Parameters** 9362 9363| Name | Type | Mandatory | Description | 9364| ------------ | ------- | --------- | ------------------------------------------------------------ | 9365| isFullScreen | boolean | Yes | Whether to set full-screen mode. This setting affects the display of the status bar and navigation bar. The value **true** means to set full-screen mode, and **false** means the opposite. | 9366 9367**Return value** 9368 9369| Type | Description | 9370| ------------------- | ------------------------------ | 9371| Promise<void> | Promise that returns no value. | 9372 9373**Example** 9374 9375```ts 9376// EntryAbility.ets 9377import { UIAbility } from '@kit.AbilityKit'; 9378import { BusinessError } from '@kit.BasicServicesKit'; 9379 9380export default class EntryAbility extends UIAbility { 9381 // ... 9382 onWindowStageCreate(windowStage: window.WindowStage): void { 9383 console.info('onWindowStageCreate'); 9384 let windowClass: window.Window | undefined = undefined; 9385 windowStage.getMainWindow((err: BusinessError, data) => { 9386 const errCode: number = err.code; 9387 if (errCode) { 9388 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9389 return; 9390 } 9391 windowClass = data; 9392 let isFullScreen: boolean = true; 9393 let promise = windowClass.setFullScreen(isFullScreen); 9394 promise.then(() => { 9395 console.info('Succeeded in enabling the full-screen mode.'); 9396 }).catch((err: BusinessError) => { 9397 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9398 }); 9399 }); 9400 } 9401} 9402``` 9403 9404### setLayoutFullScreen<sup>(deprecated)</sup> 9405 9406setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 9407 9408Sets whether the main window layout or the child window layout is immersive. This API uses an asynchronous callback to return the result. 9409- An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 9410- A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 9411 9412> **NOTE** 9413> 9414> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) instead. 9415 9416**System capability**: SystemCapability.WindowManager.WindowManager.Core 9417 9418**Parameters** 9419 9420| Name | Type | Mandatory | Description | 9421| ------------------ | ------------------------- | --------- | ------------------------------------------------------------ | 9422| isLayoutFullScreen | boolean | Yes | Whether the window layout is immersive. This setting does not affect the display of the status bar and navigation bar. The value **true** means that the window layout is immersive, and **false** means the opposite. | 9423| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9424 9425**Example** 9426 9427```ts 9428// EntryAbility.ets 9429import { UIAbility } from '@kit.AbilityKit'; 9430import { BusinessError } from '@kit.BasicServicesKit'; 9431 9432export default class EntryAbility extends UIAbility { 9433 // ... 9434 onWindowStageCreate(windowStage: window.WindowStage): void { 9435 console.info('onWindowStageCreate'); 9436 let windowClass: window.Window | undefined = undefined; 9437 windowStage.getMainWindow((err: BusinessError, data) => { 9438 const errCode: number = err.code; 9439 if (errCode) { 9440 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9441 return; 9442 } 9443 windowClass = data; 9444 let isLayoutFullScreen: boolean = true; 9445 windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 9446 const errCode: number = err.code; 9447 if (errCode) { 9448 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9449 return; 9450 } 9451 console.info('Succeeded in setting the window layout to full-screen mode.'); 9452 }); 9453 }); 9454 } 9455} 9456``` 9457 9458### setLayoutFullScreen<sup>(deprecated)</sup> 9459 9460setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 9461 9462Sets whether the main window layout or the child window layout is immersive. This API uses a promise to return the result. 9463- An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 9464- A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 9465 9466> **NOTE** 9467> 9468> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1) instead. 9469 9470**System capability**: SystemCapability.WindowManager.WindowManager.Core 9471 9472**Parameters** 9473 9474| Name | Type | Mandatory | Description | 9475| ------------------ | ------- | --------- | ------------------------------------------------------------ | 9476| isLayoutFullScreen | boolean | Yes | Whether the window layout is immersive. This setting does not affect the display of the status bar and navigation bar. The value **true** means that the window layout is immersive, and **false** means the opposite. | 9477 9478**Return value** 9479 9480| Type | Description | 9481| ------------------- | ------------------------------ | 9482| Promise<void> | Promise that returns no value. | 9483 9484**Example** 9485 9486```ts 9487// EntryAbility.ets 9488import { UIAbility } from '@kit.AbilityKit'; 9489import { BusinessError } from '@kit.BasicServicesKit'; 9490 9491export default class EntryAbility extends UIAbility { 9492 // ... 9493 onWindowStageCreate(windowStage: window.WindowStage): void { 9494 console.info('onWindowStageCreate'); 9495 let windowClass: window.Window | undefined = undefined; 9496 windowStage.getMainWindow((err: BusinessError, data) => { 9497 const errCode: number = err.code; 9498 if (errCode) { 9499 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9500 return; 9501 } 9502 windowClass = data; 9503 let isLayoutFullScreen: boolean = true; 9504 let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 9505 promise.then(() => { 9506 console.info('Succeeded in setting the window layout to full-screen mode.'); 9507 }).catch((err: BusinessError) => { 9508 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9509 }); 9510 }); 9511 } 9512} 9513``` 9514 9515### setSystemBarEnable<sup>(deprecated)</sup> 9516 9517setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 9518 9519Sets whether to show the three-button navigation bar, status bar, and bottom navigation bar of the main window. This API uses an asynchronous callback to return the result. The display of the status bar and bottom navigation bar is controlled by **status**, and that of the three-button navigation bar is controlled by **navigation**. From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 9520 9521The return value does not indicate that the visibility changes of the three-button navigation bar, status bar, and bottom navigation bar have been fully executed. This API does not take effect when it is called by a child window. 9522 9523> **NOTE** 9524> 9525> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) instead. 9526 9527**System capability**: SystemCapability.WindowManager.WindowManager.Core 9528 9529**Parameters** 9530 9531| Name | Type | Mandatory | Description | 9532| -------- | ----------------------------- | --------- | ------------------------------------------------------------ | 9533| names | Array<'status'\|'navigation'> | Yes | Whether to show the three-button navigation bar, status bar, and bottom navigation bar of the window in full-screen mode.<br>For example, to display all of them, set this parameter to **['status', 'navigation']**. By default, they are not displayed. | 9534| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9535 9536 9537**Example** 9538 9539```ts 9540// In this example, the three-button navigation bar, status bar, and bottom navigation bar are not displayed. 9541// EntryAbility.ets 9542import { UIAbility } from '@kit.AbilityKit'; 9543import { BusinessError } from '@kit.BasicServicesKit'; 9544 9545export default class EntryAbility extends UIAbility { 9546 // ... 9547 onWindowStageCreate(windowStage: window.WindowStage): void { 9548 console.info('onWindowStageCreate'); 9549 let windowClass: window.Window | undefined = undefined; 9550 windowStage.getMainWindow((err: BusinessError, data) => { 9551 const errCode: number = err.code; 9552 if (errCode) { 9553 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9554 return; 9555 } 9556 windowClass = data; 9557 let names: Array<'status' | 'navigation'> = []; 9558 windowClass.setSystemBarEnable(names, (err: BusinessError) => { 9559 const errCode: number = err.code; 9560 if (errCode) { 9561 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9562 return; 9563 } 9564 console.info('Succeeded in setting the system bar to be invisible.'); 9565 }); 9566 }); 9567 } 9568} 9569``` 9570 9571### setSystemBarEnable<sup>(deprecated)</sup> 9572 9573setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 9574 9575Sets whether to show the three-button navigation bar, status bar, and bottom navigation bar of the main window. This API uses a promise to return the result. The display of the status bar and bottom navigation bar is controlled by **status**, and that of the three-button navigation bar is controlled by **navigation**. From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 9576 9577The return value does not indicate that the visibility changes of the three-button navigation bar, status bar, and bottom navigation bar have been fully executed. This API does not take effect when it is called by a child window. 9578 9579> **NOTE** 9580> 9581> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9-1) instead. 9582 9583**System capability**: SystemCapability.WindowManager.WindowManager.Core 9584 9585**Parameters** 9586 9587| Name | Type | Mandatory | Description | 9588| ----- | ----------------------------- | --------- | ------------------------------------------------------------ | 9589| names | Array<'status'\|'navigation'> | Yes | Whether to show the three-button navigation bar, status bar, and bottom navigation bar of the window in full-screen mode.<br>For example, to display all of them, set this parameter to **['status', 'navigation']**. By default, they are not displayed. | 9590 9591**Return value** 9592 9593| Type | Description | 9594| ------------------- | ------------------------------ | 9595| Promise<void> | Promise that returns no value. | 9596 9597 9598**Example** 9599 9600```ts 9601// In this example, the three-button navigation bar, status bar, and bottom navigation bar are not displayed. 9602// EntryAbility.ets 9603import { UIAbility } from '@kit.AbilityKit'; 9604import { BusinessError } from '@kit.BasicServicesKit'; 9605 9606export default class EntryAbility extends UIAbility { 9607 // ... 9608 onWindowStageCreate(windowStage: window.WindowStage): void { 9609 console.info('onWindowStageCreate'); 9610 let windowClass: window.Window | undefined = undefined; 9611 windowStage.getMainWindow((err: BusinessError, data) => { 9612 const errCode: number = err.code; 9613 if (errCode) { 9614 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9615 return; 9616 } 9617 windowClass = data; 9618 let names: Array<'status' | 'navigation'> = []; 9619 let promise = windowClass.setSystemBarEnable(names); 9620 promise.then(() => { 9621 console.info('Succeeded in setting the system bar to be invisible.'); 9622 }).catch((err: BusinessError) => { 9623 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9624 }); 9625 }); 9626 } 9627} 9628``` 9629 9630### setSystemBarProperties<sup>(deprecated)</sup> 9631 9632setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 9633 9634Sets the properties of the three-button navigation bar and status bar of the main window. This API uses an asynchronous callback to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 9635 9636This API does not take effect when it is called by a child window. 9637 9638> **NOTE** 9639> 9640> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9) instead. 9641 9642**System capability**: SystemCapability.WindowManager.WindowManager.Core 9643 9644**Parameters** 9645 9646| Name | Type | Mandatory | Description | 9647| ------------------- | ------------------------------------------- | --------- | ------------------------------------------------------------ | 9648| systemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the three-button navigation bar and status bar. | 9649| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9650 9651**Example** 9652 9653```ts 9654// EntryAbility.ets 9655import { UIAbility } from '@kit.AbilityKit'; 9656import { BusinessError } from '@kit.BasicServicesKit'; 9657 9658export default class EntryAbility extends UIAbility { 9659 // ... 9660 onWindowStageCreate(windowStage: window.WindowStage): void { 9661 console.info('onWindowStageCreate'); 9662 let windowClass: window.Window | undefined = undefined; 9663 windowStage.getMainWindow((err: BusinessError, data) => { 9664 const errCode: number = err.code; 9665 if (errCode) { 9666 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9667 return; 9668 } 9669 windowClass = data; 9670 let SystemBarProperties: window.SystemBarProperties = { 9671 statusBarColor: '#ff00ff', 9672 navigationBarColor: '#00ff00', 9673 // The following properties are supported since API version 8. 9674 statusBarContentColor: '#ffffff', 9675 navigationBarContentColor: '#00ffff' 9676 }; 9677 windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 9678 const errCode: number = err.code; 9679 if (errCode) { 9680 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9681 return; 9682 } 9683 console.info('Succeeded in setting the system bar properties.'); 9684 }); 9685 }); 9686 } 9687} 9688``` 9689 9690### setSystemBarProperties<sup>(deprecated)</sup> 9691 9692setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 9693 9694Sets the properties of the three-button navigation bar and status bar of the main window. This API uses a promise to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 9695 9696This API does not take effect when it is called by a child window. 9697 9698> **NOTE** 9699> 9700> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9-1) instead. 9701 9702**System capability**: SystemCapability.WindowManager.WindowManager.Core 9703 9704**Parameters** 9705 9706| Name | Type | Mandatory | Description | 9707| ------------------- | ------------------------------------------- | --------- | ------------------------------------------------------------ | 9708| systemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the three-button navigation bar and status bar. | 9709 9710**Return value** 9711 9712| Type | Description | 9713| ------------------- | ------------------------------ | 9714| Promise<void> | Promise that returns no value. | 9715 9716**Example** 9717 9718```ts 9719// EntryAbility.ets 9720import { UIAbility } from '@kit.AbilityKit'; 9721import { BusinessError } from '@kit.BasicServicesKit'; 9722 9723export default class EntryAbility extends UIAbility { 9724 // ... 9725 onWindowStageCreate(windowStage: window.WindowStage): void { 9726 console.info('onWindowStageCreate'); 9727 let windowClass: window.Window | undefined = undefined; 9728 windowStage.getMainWindow((err: BusinessError, data) => { 9729 const errCode: number = err.code; 9730 if (errCode) { 9731 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9732 return; 9733 } 9734 windowClass = data; 9735 let SystemBarProperties: window.SystemBarProperties = { 9736 statusBarColor: '#ff00ff', 9737 navigationBarColor: '#00ff00', 9738 // The following properties are supported since API version 8. 9739 statusBarContentColor: '#ffffff', 9740 navigationBarContentColor: '#00ffff' 9741 }; 9742 let promise = windowClass.setSystemBarProperties(SystemBarProperties); 9743 promise.then(() => { 9744 console.info('Succeeded in setting the system bar properties.'); 9745 }).catch((err: BusinessError) => { 9746 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9747 }); 9748 }); 9749 } 9750} 9751``` 9752 9753### loadContent<sup>(deprecated)</sup> 9754 9755loadContent(path: string, callback: AsyncCallback<void>): void 9756 9757Loads content from a page to this window. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 9758 9759> **NOTE** 9760> 9761> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9) instead. 9762 9763**System capability**: SystemCapability.WindowManager.WindowManager.Core 9764 9765**Parameters** 9766 9767| Name | Type | Mandatory | Description | 9768| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 9769| path | string | Yes | Path of the page from which the content will be loaded. In the stage model, the path is configured in the **main_pages.json** file of the project. In the FA model, the path is configured in the **config.json** file of the project. | 9770| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9771 9772**Example** 9773 9774```ts 9775import { BusinessError } from '@kit.BasicServicesKit'; 9776 9777windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 9778 const errCode: number = err.code; 9779 if (errCode) { 9780 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9781 return; 9782 } 9783 console.info('Succeeded in loading the content.'); 9784}); 9785``` 9786 9787### loadContent<sup>(deprecated)</sup> 9788 9789loadContent(path: string): Promise<void> 9790 9791Loads content from a page to this window. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 9792 9793> **NOTE** 9794> 9795> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9-1) instead. 9796 9797**System capability**: SystemCapability.WindowManager.WindowManager.Core 9798 9799**Parameters** 9800 9801| Name | Type | Mandatory | Description | 9802| ---- | ------ | --------- | ------------------------------------------------------------ | 9803| path | string | Yes | Path of the page from which the content will be loaded. In the stage model, the path is configured in the **main_pages.json** file of the project. In the FA model, the path is configured in the **config.json** file of the project. | 9804 9805**Return value** 9806 9807| Type | Description | 9808| ------------------- | ------------------------------ | 9809| Promise<void> | Promise that returns no value. | 9810 9811**Example** 9812 9813```ts 9814import { BusinessError } from '@kit.BasicServicesKit'; 9815 9816let promise = windowClass.loadContent('pages/page2/page3'); 9817promise.then(() => { 9818 console.info('Succeeded in loading the content.'); 9819}).catch((err: BusinessError) => { 9820 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9821}); 9822``` 9823 9824### isShowing<sup>(deprecated)</sup> 9825 9826isShowing(callback: AsyncCallback<boolean>): void 9827 9828Checks whether this window is displayed. This API uses an asynchronous callback to return the result. 9829 9830> **NOTE** 9831> 9832> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 9833 9834**System capability**: SystemCapability.WindowManager.WindowManager.Core 9835 9836**Parameters** 9837 9838| Name | Type | Mandatory | Description | 9839| -------- | ---------------------------- | --------- | ------------------------------------------------------------ | 9840| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the window is displayed, and **false** means the opposite. | 9841 9842**Example** 9843 9844```ts 9845import { BusinessError } from '@kit.BasicServicesKit'; 9846 9847windowClass.isShowing((err: BusinessError, data) => { 9848 const errCode: number = err.code; 9849 if (errCode) { 9850 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 9851 return; 9852 } 9853 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 9854}); 9855``` 9856 9857### isShowing<sup>(deprecated)</sup> 9858 9859isShowing(): Promise<boolean> 9860 9861Checks whether this window is displayed. This API uses a promise to return the result. 9862 9863> **NOTE** 9864> 9865> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 9866 9867**System capability**: SystemCapability.WindowManager.WindowManager.Core 9868 9869**Return value** 9870 9871| Type | Description | 9872| ---------------------- | ------------------------------------------------------------ | 9873| Promise<boolean> | Promise used to return the result. The value **true** means that the window is displayed, and **false** means the opposite. | 9874 9875**Example** 9876 9877```ts 9878import { BusinessError } from '@kit.BasicServicesKit'; 9879 9880let promise = windowClass.isShowing(); 9881promise.then((data) => { 9882 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 9883}).catch((err: BusinessError) => { 9884 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 9885}); 9886``` 9887 9888### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 9889 9890on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 9891 9892Subscribes to the event indicating changes to the area where this window cannot be displayed. 9893 9894> **NOTE** 9895> 9896> This API is supported since API version 7 and deprecated since API version 9. Use [on('avoidAreaChange')](#onavoidareachange9) instead. 9897 9898**System capability**: SystemCapability.WindowManager.WindowManager.Core 9899 9900**Parameters** 9901 9902| Name | Type | Mandatory | Description | 9903| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 9904| type | string | Yes | Event type. The value is fixed at **'systemAvoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed. | 9905| callback | Callback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 9906 9907 9908**Example** 9909 9910```ts 9911windowClass.on('systemAvoidAreaChange', (data) => { 9912 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 9913}); 9914``` 9915 9916### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 9917 9918off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 9919 9920Unsubscribes from the event indicating changes to the area where this window cannot be displayed. 9921 9922> **NOTE** 9923> 9924> This API is supported since API version 7 and deprecated since API version 9. Use [off('avoidAreaChange')](#offavoidareachange9) instead. 9925 9926**System capability**: SystemCapability.WindowManager.WindowManager.Core 9927 9928**Parameters** 9929 9930| Name | Type | Mandatory | Description | 9931| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 9932| type | string | Yes | Event type. The value is fixed at **'systemAvoidAreaChange'**, indicating the event of changes to the area where the window cannot be displayed. | 9933| callback | Callback<[AvoidArea](#avoidarea7)> | No | Callback used to return the area. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 9934 9935**Example** 9936 9937```ts 9938const callback = (avoidArea: window.AvoidArea) => { 9939 // ... 9940} 9941windowClass.on('systemAvoidAreaChange', callback); 9942windowClass.off('systemAvoidAreaChange', callback); 9943// Unregister all the callbacks that have been registered through on(). 9944windowClass.off('systemAvoidAreaChange'); 9945``` 9946 9947### isSupportWideGamut<sup>(deprecated)</sup> 9948 9949isSupportWideGamut(callback: AsyncCallback<boolean>): void 9950 9951Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 9952 9953> **NOTE** 9954> 9955> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9) instead. 9956 9957**System capability**: SystemCapability.WindowManager.WindowManager.Core 9958 9959**Parameters** 9960 9961| Name | Type | Mandatory | Description | 9962| -------- | ---------------------------- | --------- | ------------------------------------------------------------ | 9963| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite. | 9964 9965**Example** 9966 9967```ts 9968import { BusinessError } from '@kit.BasicServicesKit'; 9969 9970windowClass.isSupportWideGamut((err: BusinessError, data) => { 9971 const errCode: number = err.code; 9972 if (errCode) { 9973 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 9974 return; 9975 } 9976 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 9977}); 9978``` 9979 9980### isSupportWideGamut<sup>(deprecated)</sup> 9981 9982isSupportWideGamut(): Promise<boolean> 9983 9984Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 9985 9986> **NOTE** 9987> 9988> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1) instead. 9989 9990**System capability**: SystemCapability.WindowManager.WindowManager.Core 9991 9992**Return value** 9993 9994| Type | Description | 9995| ---------------------- | ------------------------------------------------------------ | 9996| Promise<boolean> | Promise used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite. | 9997 9998**Example** 9999 10000```ts 10001import { BusinessError } from '@kit.BasicServicesKit'; 10002 10003let promise = windowClass.isSupportWideGamut(); 10004promise.then((data) => { 10005 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 10006}).catch((err: BusinessError) => { 10007 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 10008}); 10009``` 10010 10011### setColorSpace<sup>(deprecated)</sup> 10012 10013setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 10014 10015Sets a color space for this window. This API uses an asynchronous callback to return the result. 10016 10017> **NOTE** 10018> 10019> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9) instead. 10020 10021**System capability**: SystemCapability.WindowManager.WindowManager.Core 10022 10023**Parameters** 10024 10025| Name | Type | Mandatory | Description | 10026| ---------- | -------------------------- | --------- | ----------------------------------- | 10027| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set. | 10028| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10029 10030 10031**Example** 10032 10033```ts 10034import { BusinessError } from '@kit.BasicServicesKit'; 10035 10036windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 10037 const errCode: number = err.code; 10038 if (errCode) { 10039 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10040 return; 10041 } 10042 console.info('Succeeded in setting window colorspace.'); 10043}); 10044``` 10045 10046### setColorSpace<sup>(deprecated)</sup> 10047 10048setColorSpace(colorSpace:ColorSpace): Promise<void> 10049 10050Sets a color space for this window. This API uses a promise to return the result. 10051 10052> **NOTE** 10053> 10054> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9-1) instead. 10055 10056**System capability**: SystemCapability.WindowManager.WindowManager.Core 10057 10058**Parameters** 10059 10060| Name | Type | Mandatory | Description | 10061| ---------- | -------------------------- | --------- | ------------------- | 10062| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set. | 10063 10064**Return value** 10065 10066| Type | Description | 10067| ------------------- | ------------------------------ | 10068| Promise<void> | Promise that returns no value. | 10069 10070 10071**Example** 10072 10073```ts 10074import { BusinessError } from '@kit.BasicServicesKit'; 10075 10076let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 10077promise.then(() => { 10078 console.info('Succeeded in setting window colorspace.'); 10079}).catch((err: BusinessError) => { 10080 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10081}); 10082``` 10083 10084### getColorSpace<sup>(deprecated)</sup> 10085 10086getColorSpace(callback: AsyncCallback<ColorSpace>): void 10087 10088Obtains the color space of this window. This API uses an asynchronous callback to return the result. 10089 10090> **NOTE** 10091> 10092> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 10093 10094**System capability**: SystemCapability.WindowManager.WindowManager.Core 10095 10096**Parameters** 10097 10098| Name | Type | Mandatory | Description | 10099| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ | 10100| callback | AsyncCallback<[ColorSpace](#colorspace8)> | Yes | Callback used to return the result. When the color space is obtained successfully, **err** is **undefined**, and **data** is the current color space. | 10101 10102**Example** 10103 10104```ts 10105import { BusinessError } from '@kit.BasicServicesKit'; 10106 10107windowClass.getColorSpace((err: BusinessError, data) => { 10108 const errCode: number = err.code; 10109 if (errCode) { 10110 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10111 return; 10112 } 10113 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 10114}); 10115``` 10116 10117### getColorSpace<sup>(deprecated)</sup> 10118 10119getColorSpace(): Promise<ColorSpace> 10120 10121Obtains the color space of this window. This API uses a promise to return the result. 10122 10123> **NOTE** 10124> 10125> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 10126 10127**System capability**: SystemCapability.WindowManager.WindowManager.Core 10128 10129**Return value** 10130 10131| Type | Description | 10132| ----------------------------------------- | ----------------------------------------------- | 10133| Promise<[ColorSpace](#colorspace8)> | Promise used to return the current color space. | 10134 10135**Example** 10136 10137```ts 10138import { BusinessError } from '@kit.BasicServicesKit'; 10139 10140let promise = windowClass.getColorSpace(); 10141promise.then((data) => { 10142 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 10143}).catch((err: BusinessError) => { 10144 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10145}); 10146``` 10147 10148### setBackgroundColor<sup>(deprecated)</sup> 10149 10150setBackgroundColor(color: string, callback: AsyncCallback<void>): void 10151 10152Sets the background color for this window. This API uses an asynchronous callback to return the result. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 10153 10154> **NOTE** 10155> 10156> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 10157 10158**System capability**: SystemCapability.WindowManager.WindowManager.Core 10159 10160**Parameters** 10161 10162| Name | Type | Mandatory | Description | 10163| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 10164| 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'**. | 10165| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10166 10167 10168**Example** 10169 10170```ts 10171import { BusinessError } from '@kit.BasicServicesKit'; 10172 10173let color: string = '#00ff33'; 10174windowClass.setBackgroundColor(color, (err: BusinessError) => { 10175 const errCode: number = err.code; 10176 if (errCode) { 10177 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 10178 return; 10179 } 10180 console.info('Succeeded in setting the background color.'); 10181}); 10182``` 10183 10184### setBackgroundColor<sup>(deprecated)</sup> 10185 10186setBackgroundColor(color: string): Promise<void> 10187 10188Sets the background color for this window. This API uses a promise to return the result. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 10189 10190> **NOTE** 10191> 10192> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 10193 10194**System capability**: SystemCapability.WindowManager.WindowManager.Core 10195 10196**Parameters** 10197 10198| Name | Type | Mandatory | Description | 10199| ----- | ------ | --------- | ------------------------------------------------------------ | 10200| 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'**. | 10201 10202**Return value** 10203 10204| Type | Description | 10205| ------------------- | ------------------------------ | 10206| Promise<void> | Promise that returns no value. | 10207 10208 10209**Example** 10210 10211```ts 10212import { BusinessError } from '@kit.BasicServicesKit'; 10213 10214let color: string = '#00ff33'; 10215let promise = windowClass.setBackgroundColor(color); 10216promise.then(() => { 10217 console.info('Succeeded in setting the background color.'); 10218}).catch((err: BusinessError) => { 10219 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 10220}); 10221``` 10222 10223### setBrightness<sup>(deprecated)</sup> 10224 10225setBrightness(brightness: number, callback: AsyncCallback<void>): void 10226 10227Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 10228 10229When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 10230 10231> **NOTE** 10232> 10233> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9) instead. 10234 10235**System capability**: SystemCapability.WindowManager.WindowManager.Core 10236 10237**Parameters** 10238 10239| Name | Type | Mandatory | Description | 10240| ---------- | ------------------------- | --------- | ------------------------------------------------------------ | 10241| brightness | number | Yes | Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness. | 10242| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10243 10244 10245**Example** 10246 10247```ts 10248import { BusinessError } from '@kit.BasicServicesKit'; 10249 10250let brightness: number = 1; 10251windowClass.setBrightness(brightness, (err: BusinessError) => { 10252 const errCode: number = err.code; 10253 if (errCode) { 10254 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 10255 return; 10256 } 10257 console.info('Succeeded in setting the brightness.'); 10258}); 10259``` 10260 10261### setBrightness<sup>(deprecated)</sup> 10262 10263setBrightness(brightness: number): Promise<void> 10264 10265Sets the screen brightness for this window. This API uses a promise to return the result. 10266 10267When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 10268 10269> **NOTE** 10270> 10271> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9-1) instead. 10272 10273**System capability**: SystemCapability.WindowManager.WindowManager.Core 10274 10275**Parameters** 10276 10277| Name | Type | Mandatory | Description | 10278| ---------- | ------ | --------- | ------------------------------------------------------------ | 10279| brightness | number | Yes | Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness. | 10280 10281**Return value** 10282 10283| Type | Description | 10284| ------------------- | ------------------------------ | 10285| Promise<void> | Promise that returns no value. | 10286 10287 10288**Example** 10289 10290```ts 10291import { BusinessError } from '@kit.BasicServicesKit'; 10292 10293let brightness: number = 1; 10294let promise = windowClass.setBrightness(brightness); 10295promise.then(() => { 10296 console.info('Succeeded in setting the brightness.'); 10297}).catch((err: BusinessError) => { 10298 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 10299}); 10300``` 10301 10302### setDimBehind<sup>(deprecated)</sup> 10303 10304setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 10305 10306Sets the dimness of the window that is not on top. This API uses an asynchronous callback to return the result. 10307 10308> **NOTE** 10309> 10310> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 10311 10312**System capability**: SystemCapability.WindowManager.WindowManager.Core 10313 10314**Parameters** 10315 10316| Name | Type | Mandatory | Description | 10317| -------------- | ------------------------- | --------- | ------------------------------------------------------------ | 10318| dimBehindValue | number | Yes | Dimness of the window to set. The value range is [0.0, 1.0], and the value **1.0** means the dimmest. | 10319| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10320 10321**Example** 10322 10323```ts 10324import { BusinessError } from '@kit.BasicServicesKit'; 10325 10326windowClass.setDimBehind(0.5, (err: BusinessError) => { 10327 const errCode: number = err.code; 10328 if (errCode) { 10329 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 10330 return; 10331 } 10332 console.info('Succeeded in setting the dimness.'); 10333}); 10334``` 10335 10336### setDimBehind<sup>(deprecated)</sup> 10337 10338setDimBehind(dimBehindValue: number): Promise<void> 10339 10340Sets the dimness of the window that is not on top. This API uses a promise to return the result. 10341 10342> **NOTE** 10343> 10344> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 10345 10346**System capability**: SystemCapability.WindowManager.WindowManager.Core 10347 10348**Parameters** 10349 10350| Name | Type | Mandatory | Description | 10351| -------------- | ------ | --------- | ------------------------------------------------------------ | 10352| dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value **1** indicates the dimmest. | 10353 10354**Return value** 10355 10356| Type | Description | 10357| ------------------- | ------------------------------ | 10358| Promise<void> | Promise that returns no value. | 10359 10360**Example** 10361 10362```ts 10363import { BusinessError } from '@kit.BasicServicesKit'; 10364 10365let promise = windowClass.setDimBehind(0.5); 10366promise.then(() => { 10367 console.info('Succeeded in setting the dimness.'); 10368}).catch((err: BusinessError) => { 10369 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 10370}); 10371``` 10372 10373### setFocusable<sup>(deprecated)</sup> 10374 10375setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 10376 10377Sets whether this window is focusable, that is, whether the window can gain focus after it is being operated or using other methods. This API uses an asynchronous callback to return the result. 10378 10379> **NOTE** 10380> 10381> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9) instead. 10382 10383**System capability**: SystemCapability.WindowManager.WindowManager.Core 10384 10385**Parameters** 10386 10387| Name | Type | Mandatory | Description | 10388| ----------- | ------------------------- | --------- | ------------------------------------------------------------ | 10389| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 10390| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10391 10392 10393**Example** 10394 10395```ts 10396import { BusinessError } from '@kit.BasicServicesKit'; 10397 10398let isFocusable: boolean = true; 10399windowClass.setFocusable(isFocusable, (err: BusinessError) => { 10400 const errCode: number = err.code; 10401 if (errCode) { 10402 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 10403 return; 10404 } 10405 console.info('Succeeded in setting the window to be focusable.'); 10406}); 10407``` 10408 10409### setFocusable<sup>(deprecated)</sup> 10410 10411setFocusable(isFocusable: boolean): Promise<void> 10412 10413Sets whether this window is focusable, that is, whether the window can gain focus after it is being clicked or using other methods. This API uses a promise to return the result. 10414 10415> **NOTE** 10416> 10417> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9-1) instead. 10418 10419**System capability**: SystemCapability.WindowManager.WindowManager.Core 10420 10421**Parameters** 10422 10423| Name | Type | Mandatory | Description | 10424| ----------- | ------- | --------- | ------------------------------------------------------------ | 10425| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 10426 10427**Return value** 10428 10429| Type | Description | 10430| ------------------- | ------------------------------ | 10431| Promise<void> | Promise that returns no value. | 10432 10433 10434**Example** 10435 10436```ts 10437import { BusinessError } from '@kit.BasicServicesKit'; 10438 10439let isFocusable: boolean = true; 10440let promise = windowClass.setFocusable(isFocusable); 10441promise.then(() => { 10442 console.info('Succeeded in setting the window to be focusable.'); 10443}).catch((err: BusinessError) => { 10444 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 10445}); 10446``` 10447 10448### setKeepScreenOn<sup>(deprecated)</sup> 10449 10450setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 10451 10452Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 10453 10454> **NOTE** 10455> 10456> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9) instead. 10457 10458**System capability**: SystemCapability.WindowManager.WindowManager.Core 10459 10460**Parameters** 10461 10462| Name | Type | Mandatory | Description | 10463| -------------- | ------------------------- | --------- | ------------------------------------------------------------ | 10464| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 10465| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10466 10467 10468**Example** 10469 10470```ts 10471import { BusinessError } from '@kit.BasicServicesKit'; 10472 10473let isKeepScreenOn: boolean = true; 10474windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 10475 const errCode: number = err.code; 10476 if (errCode) { 10477 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 10478 return; 10479 } 10480 console.info('Succeeded in setting the screen to be always on.'); 10481}); 10482``` 10483 10484### setKeepScreenOn<sup>(deprecated)</sup> 10485 10486setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 10487 10488Sets whether to keep the screen always on. This API uses a promise to return the result. 10489 10490> **NOTE** 10491> 10492> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9-1) instead. 10493 10494**System capability**: SystemCapability.WindowManager.WindowManager.Core 10495 10496**Parameters** 10497 10498| Name | Type | Mandatory | Description | 10499| -------------- | ------- | --------- | ------------------------------------------------------------ | 10500| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 10501 10502**Return value** 10503 10504| Type | Description | 10505| ------------------- | ------------------------------ | 10506| Promise<void> | Promise that returns no value. | 10507 10508**Example** 10509 10510```ts 10511import { BusinessError } from '@kit.BasicServicesKit'; 10512 10513let isKeepScreenOn: boolean = true; 10514let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 10515promise.then(() => { 10516 console.info('Succeeded in setting the screen to be always on.'); 10517}).catch((err: BusinessError) => { 10518 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 10519}); 10520``` 10521 10522### setOutsideTouchable<sup>(deprecated)</sup> 10523 10524setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 10525 10526Sets whether the area outside the child window is touchable. This API uses an asynchronous callback to return the result. 10527 10528> **NOTE** 10529> 10530> This API is supported since API version 7 and deprecated since API version 9. 10531> 10532> Since API version 9, the area outside the child window is touchable by default. This API is no longer supported and no substitute API is provided. 10533 10534**System capability**: SystemCapability.WindowManager.WindowManager.Core 10535 10536**Parameters** 10537 10538| Name | Type | Mandatory | Description | 10539| --------- | ------------------------- | --------- | ------------------------------------------------------------ | 10540| touchable | boolean | Yes | Whether the area outside the child window is touchable. The value **true** means the area outside the child window is touchable, and **false** means the opposite. | 10541| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10542 10543**Example** 10544 10545```ts 10546import { BusinessError } from '@kit.BasicServicesKit'; 10547 10548windowClass.setOutsideTouchable(true, (err: BusinessError) => { 10549 const errCode: number = err.code; 10550 if (errCode) { 10551 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10552 return; 10553 } 10554 console.info('Succeeded in setting the area to be touchable.'); 10555}); 10556``` 10557 10558### setOutsideTouchable<sup>(deprecated)</sup> 10559 10560setOutsideTouchable(touchable: boolean): Promise<void> 10561 10562Sets whether the area outside the child window is touchable. This API uses a promise to return the result. 10563 10564> **NOTE** 10565> 10566> This API is supported since API version 7 and deprecated since API version 9. 10567> 10568> Since API version 9, the area outside the child window is touchable by default. This API is no longer supported and no substitute API is provided. 10569 10570**System capability**: SystemCapability.WindowManager.WindowManager.Core 10571 10572**Parameters** 10573 10574| Name | Type | Mandatory | Description | 10575| --------- | ------- | --------- | ------------------------------------------------------------ | 10576| touchable | boolean | Yes | Whether the area outside the child window is touchable. The value **true** means the area outside the child window is touchable, and **false** means the opposite. | 10577 10578**Return value** 10579 10580| Type | Description | 10581| ------------------- | ------------------------------ | 10582| Promise<void> | Promise that returns no value. | 10583 10584**Example** 10585 10586```ts 10587import { BusinessError } from '@kit.BasicServicesKit'; 10588 10589let promise = windowClass.setOutsideTouchable(true); 10590promise.then(() => { 10591 console.info('Succeeded in setting the area to be touchable.'); 10592}).catch((err: BusinessError) => { 10593 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10594}); 10595``` 10596 10597### setPrivacyMode<sup>(deprecated)</sup> 10598 10599setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 10600 10601Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 10602 10603A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 10604 10605> **NOTE** 10606> 10607> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9) instead. 10608 10609**System capability**: SystemCapability.WindowManager.WindowManager.Core 10610 10611**Parameters** 10612 10613| Name | Type | Mandatory | Description | 10614| ------------- | ------------------------- | --------- | ------------------------------------------------------------ | 10615| 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. | 10616| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10617 10618**Example** 10619 10620```ts 10621import { BusinessError } from '@kit.BasicServicesKit'; 10622 10623let isPrivacyMode: boolean = true; 10624windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 10625 const errCode: number = err.code; 10626 if (errCode) { 10627 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 10628 return; 10629 } 10630 console.info('Succeeded in setting the window to privacy mode.'); 10631}); 10632``` 10633 10634### setPrivacyMode<sup>(deprecated)</sup> 10635 10636setPrivacyMode(isPrivacyMode: boolean): Promise<void> 10637 10638Sets whether this window is in privacy mode. This API uses a promise to return the result. 10639 10640A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 10641 10642> **NOTE** 10643> 10644> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9-1) instead. 10645 10646**System capability**: SystemCapability.WindowManager.WindowManager.Core 10647 10648**Parameters** 10649 10650| Name | Type | Mandatory | Description | 10651| ------------- | ------- | --------- | ------------------------------------------------------------ | 10652| 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. | 10653 10654**Return value** 10655 10656| Type | Description | 10657| ------------------- | ------------------------------ | 10658| Promise<void> | Promise that returns no value. | 10659 10660**Example** 10661 10662```ts 10663import { BusinessError } from '@kit.BasicServicesKit'; 10664 10665let isPrivacyMode: boolean = true; 10666let promise = windowClass.setPrivacyMode(isPrivacyMode); 10667promise.then(() => { 10668 console.info('Succeeded in setting the window to privacy mode.'); 10669}).catch((err: BusinessError) => { 10670 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 10671}); 10672``` 10673 10674### setTouchable<sup>(deprecated)</sup> 10675 10676setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 10677 10678Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 10679 10680> **NOTE** 10681> 10682> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9) instead. 10683 10684**System capability**: SystemCapability.WindowManager.WindowManager.Core 10685 10686**Parameters** 10687 10688| Name | Type | Mandatory | Description | 10689| ----------- | ------------------------- | --------- | ------------------------------------------------------------ | 10690| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite. | 10691| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10692 10693 10694**Example** 10695 10696```ts 10697import { BusinessError } from '@kit.BasicServicesKit'; 10698 10699let isTouchable = true; 10700windowClass.setTouchable(isTouchable, (err: BusinessError) => { 10701 const errCode: number = err.code; 10702 if (errCode) { 10703 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10704 return; 10705 } 10706 console.info('Succeeded in setting the window to be touchable.'); 10707}); 10708``` 10709 10710### setTouchable<sup>(deprecated)</sup> 10711 10712setTouchable(isTouchable: boolean): Promise<void> 10713 10714Sets whether this window is touchable. This API uses a promise to return the result. 10715 10716> **NOTE** 10717> 10718> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9-1) instead. 10719 10720**System capability**: SystemCapability.WindowManager.WindowManager.Core 10721 10722**Parameters** 10723 10724| Name | Type | Mandatory | Description | 10725| ----------- | ------- | --------- | ------------------------------------------------------------ | 10726| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite. | 10727 10728**Return value** 10729 10730| Type | Description | 10731| ------------------- | ------------------------------ | 10732| Promise<void> | Promise that returns no value. | 10733 10734 10735**Example** 10736 10737```ts 10738import { BusinessError } from '@kit.BasicServicesKit'; 10739 10740let isTouchable = true; 10741let promise = windowClass.setTouchable(isTouchable); 10742promise.then(() => { 10743 console.info('Succeeded in setting the window to be touchable.'); 10744}).catch((err: BusinessError) => { 10745 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10746}); 10747``` 10748 10749## WindowStageEventType<sup>9+</sup> 10750 10751Describes the lifecycle of a window stage. 10752 10753**Model restriction**: This API can be used only in the stage model. 10754 10755**System capability**: SystemCapability.WindowManager.WindowManager.Core 10756 10757**Atomic service API**: This API can be used in atomic services since API version 11. 10758 10759| Name | Value | Description | 10760| --------------------- | ----- | ------------------------------------------------------------ | 10761| SHOWN | 1 | The window stage is shown in the foreground, for example, when launching from the application icon, triggered whether it is the first launch or resuming from the background. | 10762| ACTIVE | 2 | The window stage gains focus, for example, the state of the application window after handling a click event, or the state after the application is launched. | 10763| INACTIVE | 3 | The window stage loses focus, for example, the state of the window that was in focus when a new application is opened or another window is clicked. | 10764| HIDDEN | 4 | The window stage is running in the background, for example, when the application exists after swiping up or the application window is closed. | 10765| RESUMED<sup>11+</sup> | 5 | The window stage is interactive in the foreground, for example, when an application is opened and can interact with the user. | 10766| PAUSED<sup>11+</sup> | 6 | The window stage is non-interactive in the foreground, for example, when the application enters the recent tasks screen after swiping up from the bottom of the screen. | 10767 10768## ModalityType<sup>14+</sup> 10769 10770Enumerates the modality types of the child window. 10771 10772**System capability**: SystemCapability.Window.SessionManager 10773 10774**Atomic service API**: This API can be used in atomic services since API version 14. 10775 10776| Name | Value | Description | 10777| -------------------- | ----- | ------------------------------------------------------------ | 10778| WINDOW_MODALITY | 0 | Window-modal. Select this value when you want the parent window not to respond to user interactions. | 10779| APPLICATION_MODALITY | 1 | Application-modal. Select this value when you want both the parent window and all windows of other instances of the application not to respond to user interactions.<br> This API can be used only on 2-in-1 devices. | 10780 10781## SubWindowOptions<sup>11+</sup> 10782 10783Describes the parameters used for creating a child window. 10784 10785**System capability**: SystemCapability.Window.SessionManager 10786 10787| Name | Type | Read-Only | Optional | Description | 10788| -------------------------- | ------------------------------- | --------- | -------- | ------------------------------------------------------------ | 10789| title<sup>11+</sup> | string | No | No | Title of the child window.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 10790| decorEnabled<sup>11+</sup> | boolean | No | No | Whether decorations are displayed in the child window. The value **true** means decorations are displayed, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 10791| isModal<sup>12+</sup> | boolean | No | Yes | Whether the modal property is enabled for the child window. The value** true** means that the modal property is enabled for the child window, and **false** means to disable it. The default value is **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 10792| modalityType<sup>14+</sup> | [ModalityType](#modalitytype14) | No | Yes | Modality type of the child window. This parameter takes effect only when the modal property is enabled for the child window. **WINDOW_MODALITY** means window-modal, and **APPLICATION_MODALITY** means application-modal. The default value is **WINDOW_MODALITY**.<br>**Atomic service API**: This API can be used in atomic services since API version 14. | 10793| windowRect<sup>18+</sup> | [Rect](#rect7) | No | Yes | Rectangle of the child window, and the size of the child window is limited. For details, see [resize()](#resize9). If this parameter is not specified, the window is displayed in full screen by default.<br>**Atomic service API**: This API can be used in atomic services since API version 18. | 10794 10795## WindowStage<sup>9+</sup> 10796 10797Implements a window manager, which manages each basic window unit, that is, [Window](#window) instance. 10798 10799Before calling any of the following APIs, you must use [onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) to create a **WindowStage** instance. 10800 10801### getMainWindow<sup>9+</sup> 10802 10803getMainWindow(callback: AsyncCallback<Window>): void 10804 10805Obtains the main window of this window stage. This API uses an asynchronous callback to return the result. 10806 10807**Model restriction**: This API can be used only in the stage model. 10808 10809**System capability**: SystemCapability.WindowManager.WindowManager.Core 10810 10811**Atomic service API**: This API can be used in atomic services since API version 11. 10812 10813**Parameters** 10814 10815| Name | Type | Mandatory | Description | 10816| -------- | -------------------------------------- | --------- | ---------------------------------------- | 10817| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the main window. | 10818 10819**Error codes** 10820 10821For details about the error codes, see [Window Error Codes](errorcode-window.md). 10822 10823| ID | Error Message | 10824| ------- | ------------------------------ | 10825| 1300002 | This window state is abnormal. | 10826| 1300005 | This window stage is abnormal. | 10827 10828**Example** 10829 10830```ts 10831// EntryAbility.ets 10832import { UIAbility } from '@kit.AbilityKit'; 10833import { BusinessError } from '@kit.BasicServicesKit'; 10834 10835export default class EntryAbility extends UIAbility { 10836 // ... 10837 10838 onWindowStageCreate(windowStage: window.WindowStage) { 10839 console.info('onWindowStageCreate'); 10840 let windowClass: window.Window | undefined = undefined; 10841 windowStage.getMainWindow((err: BusinessError, data) => { 10842 const errCode: number = err.code; 10843 if (errCode) { 10844 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10845 return; 10846 } 10847 windowClass = data; 10848 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 10849 }); 10850 } 10851}; 10852``` 10853 10854### getMainWindow<sup>9+</sup> 10855 10856getMainWindow(): Promise<Window> 10857 10858Obtains the main window of this window stage. This API uses a promise to return the result. 10859 10860**Model restriction**: This API can be used only in the stage model. 10861 10862**System capability**: SystemCapability.WindowManager.WindowManager.Core 10863 10864**Atomic service API**: This API can be used in atomic services since API version 11. 10865 10866**Return value** 10867 10868| Type | Description | 10869| -------------------------------- | --------------------------------------- | 10870| Promise<[Window](#window)> | Promise used to return the main window. | 10871 10872**Error codes** 10873 10874For details about the error codes, see [Window Error Codes](errorcode-window.md). 10875 10876| ID | Error Message | 10877| ------- | ------------------------------ | 10878| 1300002 | This window state is abnormal. | 10879| 1300005 | This window stage is abnormal. | 10880 10881**Example** 10882 10883```ts 10884// EntryAbility.ets 10885import { UIAbility } from '@kit.AbilityKit'; 10886import { BusinessError } from '@kit.BasicServicesKit'; 10887 10888export default class EntryAbility extends UIAbility { 10889 // ... 10890 10891 onWindowStageCreate(windowStage: window.WindowStage) { 10892 console.info('onWindowStageCreate'); 10893 let windowClass: window.Window | undefined = undefined; 10894 let promise = windowStage.getMainWindow(); 10895 promise.then((data) => { 10896 windowClass = data; 10897 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 10898 }).catch((err: BusinessError) => { 10899 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10900 }); 10901 } 10902}; 10903``` 10904 10905### getMainWindowSync<sup>9+</sup> 10906 10907getMainWindowSync(): Window 10908 10909Obtains the main window of this window stage. 10910 10911**Model restriction**: This API can be used only in the stage model. 10912 10913**System capability**: SystemCapability.WindowManager.WindowManager.Core 10914 10915**Atomic service API**: This API can be used in atomic services since API version 11. 10916 10917**Return value** 10918 10919| Type | Description | 10920| ----------------- | ------------ | 10921| [Window](#window) | Main window. | 10922 10923**Error codes** 10924 10925For details about the error codes, see [Window Error Codes](errorcode-window.md). 10926 10927| ID | Error Message | 10928| ------- | ------------------------------ | 10929| 1300002 | This window state is abnormal. | 10930| 1300005 | This window stage is abnormal. | 10931 10932**Example** 10933<!--code_no_check--> 10934```ts 10935// EntryAbility.ets 10936import { UIAbility } from '@kit.AbilityKit'; 10937 10938export default class EntryAbility extends UIAbility { 10939 // ... 10940 10941 onWindowStageCreate(windowStage: window.WindowStage) { 10942 console.info('onWindowStageCreate'); 10943 try { 10944 let windowClass = windowStage.getMainWindowSync(); 10945 } catch (exception) { 10946 console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`); 10947 } 10948 } 10949}; 10950``` 10951 10952### createSubWindow<sup>9+</sup> 10953 10954createSubWindow(name: string, callback: AsyncCallback<Window>): void 10955 10956Creates a child window for this window stage. This API uses an asynchronous callback to return the result. 10957 10958**Model restriction**: This API can be used only in the stage model. 10959 10960**System capability**: SystemCapability.WindowManager.WindowManager.Core 10961 10962**Atomic service API**: This API can be used in atomic services since API version 11. 10963 10964**Parameters** 10965 10966| Name | Type | Mandatory | Description | 10967| -------- | -------------------------------------- | --------- | ----------------------------------------- | 10968| name | string | Yes | Name of the child window. | 10969| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the child window. | 10970 10971**Error codes** 10972 10973For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 10974 10975| ID | Error Message | 10976| ------- | ----------------------------------------------------------- | 10977| 401 | Parameter error. Possible cause: Incorrect parameter types. | 10978| 1300002 | This window state is abnormal. | 10979| 1300005 | This window stage is abnormal. | 10980 10981**Example** 10982 10983```ts 10984// EntryAbility.ets 10985import { UIAbility } from '@kit.AbilityKit'; 10986import { BusinessError } from '@kit.BasicServicesKit'; 10987 10988export default class EntryAbility extends UIAbility { 10989 // ... 10990 10991 onWindowStageCreate(windowStage: window.WindowStage) { 10992 console.info('onWindowStageCreate'); 10993 let windowClass: window.Window | undefined = undefined; 10994 try { 10995 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 10996 const errCode: number = err.code; 10997 if (errCode) { 10998 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10999 return; 11000 } 11001 windowClass = data; 11002 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11003 if (!windowClass) { 11004 console.info('Failed to load the content. Cause: windowClass is null'); 11005 } 11006 else { 11007 (windowClass as window.Window).resize(500, 1000); 11008 } 11009 }); 11010 } catch (exception) { 11011 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11012 } 11013 } 11014}; 11015``` 11016 11017### createSubWindow<sup>9+</sup> 11018 11019createSubWindow(name: string): Promise<Window> 11020 11021Creates a child window for this window stage. This API uses a promise to return the result. 11022 11023**Model restriction**: This API can be used only in the stage model. 11024 11025**System capability**: SystemCapability.WindowManager.WindowManager.Core 11026 11027**Atomic service API**: This API can be used in atomic services since API version 11. 11028 11029**Parameters** 11030 11031| Name | Type | Mandatory | Description | 11032| ---- | ------ | --------- | ------------------------- | 11033| name | string | Yes | Name of the child window. | 11034 11035**Return value** 11036 11037| Type | Description | 11038| -------------------------------- | ---------------------------------------- | 11039| Promise<[Window](#window)> | Promise used to return the child window. | 11040 11041**Error codes** 11042 11043For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11044 11045| ID | Error Message | 11046| ------- | ----------------------------------------------------------- | 11047| 401 | Parameter error. Possible cause: Incorrect parameter types. | 11048| 1300002 | This window state is abnormal. | 11049| 1300005 | This window stage is abnormal. | 11050 11051**Example** 11052 11053```ts 11054// EntryAbility.ets 11055import { UIAbility } from '@kit.AbilityKit'; 11056import { BusinessError } from '@kit.BasicServicesKit'; 11057 11058export default class EntryAbility extends UIAbility { 11059 // ... 11060 11061 onWindowStageCreate(windowStage: window.WindowStage) { 11062 console.info('onWindowStageCreate'); 11063 let windowClass: window.Window | undefined = undefined; 11064 try { 11065 let promise = windowStage.createSubWindow('mySubWindow'); 11066 promise.then((data) => { 11067 windowClass = data; 11068 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11069 }).catch((err: BusinessError) => { 11070 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11071 }); 11072 } catch (exception) { 11073 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11074 } 11075 } 11076}; 11077``` 11078 11079### createSubWindowWithOptions<sup>11+</sup> 11080 11081createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 11082 11083Creates a child window for this window stage. This API uses a promise to return the result. 11084 11085**Model restriction**: This API can be used only in the stage model. 11086 11087**Atomic service API**: This API can be used in atomic services since API version 12. 11088 11089**System capability**: SystemCapability.Window.SessionManager 11090 11091**Parameters** 11092 11093| Name | Type | Mandatory | Description | 11094| ------- | --------------------------------------- | --------- | ---------------------------------------------- | 11095| name | string | Yes | Name of the child window. | 11096| options | [SubWindowOptions](#subwindowoptions11) | Yes | Parameters used for creating the child window. | 11097 11098**Return value** 11099 11100| Type | Description | 11101| -------------------------------- | ------------------------------------------------ | 11102| Promise<[Window](#window)> | Promise used to return the child window created. | 11103 11104**Error codes** 11105 11106For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11107 11108| ID | Error Message | 11109| ------- | ------------------------------------------------------------ | 11110| 401 | Parameter error. Possible cause: Incorrect parameter types. | 11111| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11112| 1300002 | This window state is abnormal. | 11113| 1300005 | This window stage is abnormal. | 11114 11115**Example** 11116 11117```ts 11118// EntryAbility.ets 11119import { UIAbility } from '@kit.AbilityKit'; 11120import { BusinessError } from '@kit.BasicServicesKit'; 11121 11122export default class EntryAbility extends UIAbility { 11123 // ... 11124 11125 onWindowStageCreate(windowStage: window.WindowStage) { 11126 console.info('onWindowStageCreate'); 11127 let windowClass: window.Window | undefined = undefined; 11128 try { 11129 let options : window.SubWindowOptions = { 11130 title: 'title', 11131 decorEnabled: true 11132 }; 11133 let promise = windowStage.createSubWindowWithOptions('mySubWindow', options); 11134 promise.then((data) => { 11135 windowClass = data; 11136 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11137 }).catch((err: BusinessError) => { 11138 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11139 }); 11140 } catch (exception) { 11141 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11142 } 11143 } 11144}; 11145``` 11146 11147### getSubWindow<sup>9+</sup> 11148 11149getSubWindow(callback: AsyncCallback<Array<Window>>): void 11150 11151Obtains all the child windows of this window stage. This API uses an asynchronous callback to return the result. 11152 11153**Model restriction**: This API can be used only in the stage model. 11154 11155**System capability**: SystemCapability.WindowManager.WindowManager.Core 11156 11157**Atomic service API**: This API can be used in atomic services since API version 11. 11158 11159**Parameters** 11160 11161| Name | Type | Mandatory | Description | 11162| -------- | --------------------------------------------------- | --------- | ---------------------------------------------- | 11163| callback | AsyncCallback<Array<[Window](#window)>> | Yes | Callback used to return all the child windows. | 11164 11165**Error codes** 11166 11167For details about the error codes, see [Window Error Codes](errorcode-window.md). 11168 11169| ID | Error Message | 11170| ------- | ------------------------------ | 11171| 1300005 | This window stage is abnormal. | 11172 11173**Example** 11174<!--code_no_check--> 11175```ts 11176// EntryAbility.ets 11177import { UIAbility } from '@kit.AbilityKit'; 11178import { BusinessError } from '@kit.BasicServicesKit'; 11179 11180export default class EntryAbility extends UIAbility { 11181 // ... 11182 11183 onWindowStageCreate(windowStage: window.WindowStage) { 11184 console.info('onWindowStageCreate'); 11185 let windowClass: window.Window[] = []; 11186 windowStage.getSubWindow((err: BusinessError, data) => { 11187 const errCode: number = err.code; 11188 if (errCode) { 11189 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11190 return; 11191 } 11192 windowClass = data; 11193 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 11194 }); 11195 } 11196}; 11197``` 11198 11199### getSubWindow<sup>9+</sup> 11200 11201getSubWindow(): Promise<Array<Window>> 11202 11203Obtains all the child windows of this window stage. This API uses a promise to return the result. 11204 11205**Model restriction**: This API can be used only in the stage model. 11206 11207**System capability**: SystemCapability.WindowManager.WindowManager.Core 11208 11209**Atomic service API**: This API can be used in atomic services since API version 11. 11210 11211**Return value** 11212 11213| Type | Description | 11214| --------------------------------------------- | --------------------------------------------- | 11215| Promise<Array<[Window](#window)>> | Promise used to return all the child windows. | 11216 11217**Error codes** 11218 11219For details about the error codes, see [Window Error Codes](errorcode-window.md). 11220 11221| ID | Error Message | 11222| ------- | ------------------------------ | 11223| 1300005 | This window stage is abnormal. | 11224 11225**Example** 11226<!--code_no_check--> 11227```ts 11228// EntryAbility.ets 11229import { UIAbility } from '@kit.AbilityKit'; 11230import { BusinessError } from '@kit.BasicServicesKit'; 11231 11232export default class EntryAbility extends UIAbility { 11233 // ... 11234 11235 onWindowStageCreate(windowStage: window.WindowStage) { 11236 console.info('onWindowStageCreate'); 11237 let windowClass: window.Window[] = []; 11238 let promise = windowStage.getSubWindow(); 11239 promise.then((data) => { 11240 windowClass = data; 11241 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 11242 }).catch((err: BusinessError) => { 11243 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11244 }); 11245 } 11246}; 11247``` 11248 11249### loadContent<sup>9+</sup> 11250 11251loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 11252 11253Loads the content of a page, with its path in the current project specified, to the main window of this window stage, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11254 11255**Model restriction**: This API can be used only in the stage model. 11256 11257**System capability**: SystemCapability.WindowManager.WindowManager.Core 11258 11259**Atomic service API**: This API can be used in atomic services since API version 11. 11260 11261**Parameters** 11262 11263| Name | Type | Mandatory | Description | 11264| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 11265| path | string | Yes | Path of the page from which the content will be loaded. The path is configured in the **main_pages.json** file of the project. | 11266| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page. | 11267| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11268 11269**Error codes** 11270 11271For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11272 11273| ID | Error Message | 11274| ------- | ------------------------------------------------------------ | 11275| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11276| 1300002 | This window state is abnormal. | 11277| 1300005 | This window stage is abnormal. | 11278 11279**Example** 11280 11281```ts 11282// EntryAbility.ets 11283import { UIAbility } from '@kit.AbilityKit'; 11284import { BusinessError } from '@kit.BasicServicesKit'; 11285 11286export default class EntryAbility extends UIAbility { 11287 // ... 11288 11289 storage: LocalStorage = new LocalStorage(); 11290 11291 onWindowStageCreate(windowStage: window.WindowStage) { 11292 this.storage.setOrCreate('storageSimpleProp', 121); 11293 console.info('onWindowStageCreate'); 11294 try { 11295 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 11296 const errCode: number = err.code; 11297 if (errCode) { 11298 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11299 return; 11300 } 11301 console.info('Succeeded in loading the content.'); 11302 }); 11303 } catch (exception) { 11304 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11305 } 11306 } 11307}; 11308``` 11309 11310### loadContent<sup>9+</sup> 11311 11312loadContent(path: string, storage?: LocalStorage): Promise<void> 11313 11314Loads the content of a page, with its path in the current project specified, to the main window of this window stage, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11315 11316**Model restriction**: This API can be used only in the stage model. 11317 11318**System capability**: SystemCapability.WindowManager.WindowManager.Core 11319 11320**Atomic service API**: This API can be used in atomic services since API version 11. 11321 11322**Parameters** 11323 11324| Name | Type | Mandatory | Description | 11325| ------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 11326| path | string | Yes | Path of the page from which the content will be loaded. The path is configured in the **main_pages.json** file of the project. | 11327| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | No | Page-level UI state storage unit, which is used to transfer the state attribute for the page. | 11328 11329**Return value** 11330 11331| Type | Description | 11332| ------------------- | ------------------------------ | 11333| Promise<void> | Promise that returns no value. | 11334 11335**Error codes** 11336 11337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11338 11339| ID | Error Message | 11340| ------- | ------------------------------------------------------------ | 11341| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11342| 1300002 | This window state is abnormal. | 11343| 1300005 | This window stage is abnormal. | 11344 11345**Example** 11346 11347```ts 11348// EntryAbility.ets 11349import { UIAbility } from '@kit.AbilityKit'; 11350import { BusinessError } from '@kit.BasicServicesKit'; 11351 11352export default class EntryAbility extends UIAbility { 11353 // ... 11354 11355 storage: LocalStorage = new LocalStorage(); 11356 11357 onWindowStageCreate(windowStage: window.WindowStage) { 11358 this.storage.setOrCreate('storageSimpleProp', 121); 11359 console.info('onWindowStageCreate'); 11360 try { 11361 let promise = windowStage.loadContent('pages/page2', this.storage); 11362 promise.then(() => { 11363 console.info('Succeeded in loading the content.'); 11364 }).catch((err: BusinessError) => { 11365 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11366 }); 11367 } catch (exception) { 11368 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11369 } 11370 ; 11371 } 11372}; 11373``` 11374 11375### loadContent<sup>9+</sup> 11376 11377loadContent(path: string, callback: AsyncCallback<void>): void 11378 11379Loads content from a page to this window stage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11380 11381**Model restriction**: This API can be used only in the stage model. 11382 11383**System capability**: SystemCapability.WindowManager.WindowManager.Core 11384 11385**Atomic service API**: This API can be used in atomic services since API version 11. 11386 11387**Parameters** 11388 11389| Name | Type | Mandatory | Description | 11390| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 11391| path | string | Yes | Path of the page from which the content will be loaded. The path is configured in the **main_pages.json** file of the project. | 11392| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11393 11394**Error codes** 11395 11396For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11397 11398| ID | Error Message | 11399| ------- | ------------------------------------------------------------ | 11400| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11401| 1300002 | This window state is abnormal. | 11402| 1300005 | This window stage is abnormal. | 11403 11404**Example** 11405 11406```ts 11407// EntryAbility.ets 11408import { UIAbility } from '@kit.AbilityKit'; 11409import { BusinessError } from '@kit.BasicServicesKit'; 11410 11411export default class EntryAbility extends UIAbility { 11412 // ... 11413 11414 onWindowStageCreate(windowStage: window.WindowStage) { 11415 console.info('onWindowStageCreate'); 11416 try { 11417 windowStage.loadContent('pages/page2', (err: BusinessError) => { 11418 const errCode: number = err.code; 11419 if (errCode) { 11420 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11421 return; 11422 } 11423 console.info('Succeeded in loading the content.'); 11424 }); 11425 } catch (exception) { 11426 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11427 } 11428 } 11429}; 11430``` 11431 11432### loadContentByName<sup>11+</sup> 11433 11434loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 11435 11436Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window stage, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11437 11438**Model restriction**: This API can be used only in the stage model. 11439 11440**System capability**: SystemCapability.WindowManager.WindowManager.Core 11441 11442**Atomic service API**: This API can be used in atomic services since API version 11. 11443 11444**Parameters** 11445 11446| Name | Type | Mandatory | Description | 11447| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 11448| name | string | Yes | Name of the named route page. | 11449| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page. | 11450| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11451 11452**Error codes** 11453 11454For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11455 11456| ID | Error Message | 11457| ------- | ------------------------------------------------------------ | 11458| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11459| 1300002 | This window state is abnormal. | 11460| 1300003 | This window manager service works abnormally. | 11461 11462**Example** 11463 11464<!--code_no_check--> 11465```ts 11466// EntryAbility.ets 11467import { UIAbility } from '@kit.AbilityKit'; 11468import { BusinessError } from '@kit.BasicServicesKit'; 11469import * as Index from '../pages/Index'; // Import the named route page. 11470 11471export default class EntryAbility extends UIAbility { 11472 // ... 11473 11474 storage: LocalStorage = new LocalStorage(); 11475 11476 onWindowStageCreate(windowStage: window.WindowStage) { 11477 console.info('onWindowStageCreate'); 11478 this.storage.setOrCreate('storageSimpleProp', 121); 11479 try { 11480 windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => { 11481 const errCode: number = err.code; 11482 if (errCode) { 11483 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11484 return; 11485 } 11486 console.info('Succeeded in loading the content.'); 11487 }); 11488 } catch (exception) { 11489 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11490 } 11491 } 11492}; 11493``` 11494<!--code_no_check--> 11495```ts 11496// ets/pages/Index.ets 11497export const entryName : string = 'Index'; 11498@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 11499@Component 11500export struct Index { 11501 @State message: string = 'Hello World' 11502 build() { 11503 Row() { 11504 Column() { 11505 Text(this.message) 11506 .fontSize(50) 11507 .fontWeight(FontWeight.Bold) 11508 } 11509 .width('100%') 11510 } 11511 .height('100%') 11512 } 11513} 11514``` 11515 11516### loadContentByName<sup>11+</sup> 11517 11518loadContentByName(name: string, callback: AsyncCallback<void>): void 11519 11520Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window stage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11521 11522**Model restriction**: This API can be used only in the stage model. 11523 11524**System capability**: SystemCapability.WindowManager.WindowManager.Core 11525 11526**Atomic service API**: This API can be used in atomic services since API version 11. 11527 11528**Parameters** 11529 11530| Name | Type | Mandatory | Description | 11531| -------- | ------------------------- | --------- | ----------------------------------- | 11532| name | string | Yes | Name of the named route page. | 11533| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11534 11535**Error codes** 11536 11537For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11538 11539| ID | Error Message | 11540| ------- | ------------------------------------------------------------ | 11541| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11542| 1300002 | This window state is abnormal. | 11543| 1300003 | This window manager service works abnormally. | 11544 11545**Example** 11546 11547<!--code_no_check--> 11548```ts 11549// EntryAbility.ets 11550import { UIAbility } from '@kit.AbilityKit'; 11551import { BusinessError } from '@kit.BasicServicesKit'; 11552import * as Index from '../pages/Index'; // Import the named route page. 11553 11554export default class EntryAbility extends UIAbility { 11555 // ... 11556 11557 onWindowStageCreate(windowStage: window.WindowStage) { 11558 console.info('onWindowStageCreate'); 11559 try { 11560 windowStage.loadContentByName(Index.entryName, (err: BusinessError) => { 11561 const errCode: number = err.code; 11562 if (errCode) { 11563 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11564 return; 11565 } 11566 console.info('Succeeded in loading the content.'); 11567 }); 11568 } catch (exception) { 11569 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11570 } 11571 } 11572}; 11573``` 11574<!--code_no_check--> 11575```ts 11576// ets/pages/Index.ets 11577export const entryName : string = 'Index'; 11578@Entry({routeName: entryName}) 11579@Component 11580export struct Index { 11581 @State message: string = 'Hello World' 11582 build() { 11583 Row() { 11584 Column() { 11585 Text(this.message) 11586 .fontSize(50) 11587 .fontWeight(FontWeight.Bold) 11588 } 11589 .width('100%') 11590 } 11591 .height('100%') 11592 } 11593} 11594``` 11595 11596### loadContentByName<sup>11+</sup> 11597 11598loadContentByName(name: string, storage?: LocalStorage): Promise<void>; 11599 11600Loads the content a [named route](../../ui/arkts-routing.md#named-route) page to this window stage, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. 11601 11602**Model restriction**: This API can be used only in the stage model. 11603 11604**System capability**: SystemCapability.WindowManager.WindowManager.Core 11605 11606**Atomic service API**: This API can be used in atomic services since API version 11. 11607 11608**Parameters** 11609 11610| Name | Type | Mandatory | Description | 11611| ------- | ------------ | --------- | ------------------------------------------------------------ | 11612| name | string | Yes | Name of the named route page. | 11613| storage | LocalStorage | No | Page-level UI state storage unit, which is used to transfer the state attribute for the page. | 11614 11615**Error codes** 11616 11617For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11618 11619| ID | Error Message | 11620| ------- | ------------------------------------------------------------ | 11621| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11622| 1300002 | This window state is abnormal. | 11623| 1300003 | This window manager service works abnormally. | 11624 11625**Example** 11626 11627<!--code_no_check--> 11628```ts 11629// EntryAbility.ets 11630import { UIAbility } from '@kit.AbilityKit'; 11631import { BusinessError } from '@kit.BasicServicesKit'; 11632import * as Index from '../pages/Index'; // Import the named route page. 11633 11634export default class EntryAbility extends UIAbility { 11635 // ... 11636 11637 storage: LocalStorage = new LocalStorage(); 11638 11639 onWindowStageCreate(windowStage: window.WindowStage) { 11640 console.info('onWindowStageCreate'); 11641 this.storage.setOrCreate('storageSimpleProp', 121); 11642 try { 11643 let promise = windowStage.loadContentByName(Index.entryName, this.storage); 11644 promise.then(() => { 11645 console.info('Succeeded in loading the content.'); 11646 }).catch((err: BusinessError) => { 11647 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11648 }); 11649 } catch (exception) { 11650 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11651 } 11652 } 11653}; 11654``` 11655<!--code_no_check--> 11656```ts 11657// ets/pages/Index.ets 11658export const entryName : string = 'Index'; 11659@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 11660@Component 11661export struct Index { 11662 @State message: string = 'Hello World' 11663 build() { 11664 Row() { 11665 Column() { 11666 Text(this.message) 11667 .fontSize(50) 11668 .fontWeight(FontWeight.Bold) 11669 } 11670 .width('100%') 11671 } 11672 .height('100%') 11673 } 11674} 11675``` 11676 11677### on('windowStageEvent')<sup>9+</sup> 11678 11679on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 11680 11681Subscribes to the window stage lifecycle change event. 11682 11683**Model restriction**: This API can be used only in the stage model. 11684 11685**System capability**: SystemCapability.WindowManager.WindowManager.Core 11686 11687**Atomic service API**: This API can be used in atomic services since API version 11. 11688 11689**Parameters** 11690 11691| Name | Type | Mandatory | Description | 11692| --------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 11693| eventType | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event. | 11694| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | Yes | Callback used to return the window stage lifecycle state. | 11695 11696**Error codes** 11697 11698For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11699 11700| ID | Error Message | 11701| ------- | ------------------------------------------------------------ | 11702| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11703| 1300002 | This window state is abnormal. | 11704| 1300005 | This window stage is abnormal. | 11705 11706**Example** 11707 11708```ts 11709// EntryAbility.ets 11710import { UIAbility } from '@kit.AbilityKit'; 11711 11712export default class EntryAbility extends UIAbility { 11713 // ... 11714 11715 onWindowStageCreate(windowStage: window.WindowStage) { 11716 console.info('onWindowStageCreate'); 11717 try { 11718 windowStage.on('windowStageEvent', (data) => { 11719 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 11720 JSON.stringify(data)); 11721 }); 11722 } catch (exception) { 11723 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11724 } 11725 } 11726}; 11727``` 11728 11729### off('windowStageEvent')<sup>9+</sup> 11730 11731off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 11732 11733Unsubscribes from the window stage lifecycle change event. 11734 11735**Model restriction**: This API can be used only in the stage model. 11736 11737**System capability**: SystemCapability.WindowManager.WindowManager.Core 11738 11739**Atomic service API**: This API can be used in atomic services since API version 11. 11740 11741**Parameters** 11742 11743| Name | Type | Mandatory | Description | 11744| --------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 11745| eventType | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event. | 11746| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | No | Callback used to return the window stage lifecycle state. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 11747 11748**Error codes** 11749 11750For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11751 11752| ID | Error Message | 11753| ------- | ------------------------------------------------------------ | 11754| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 11755| 1300002 | This window state is abnormal. | 11756| 1300005 | This window stage is abnormal. | 11757 11758**Example** 11759 11760```ts 11761// EntryAbility.ets 11762import { UIAbility } from '@kit.AbilityKit'; 11763 11764export default class EntryAbility extends UIAbility { 11765 // ... 11766 11767 onWindowStageCreate(windowStage: window.WindowStage) { 11768 console.info('onWindowStageCreate'); 11769 const callback = (windowStageEventType: window.WindowStageEventType) => { 11770 // ... 11771 } 11772 try { 11773 windowStage.on('windowStageEvent', callback); 11774 } catch (exception) { 11775 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11776 } 11777 try { 11778 windowStage.off('windowStageEvent', callback); 11779 // Unregister all the callbacks that have been registered through on(). 11780 windowStage.off('windowStageEvent'); 11781 } catch (exception) { 11782 console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11783 } 11784 } 11785}; 11786``` 11787 11788### on('windowStageClose')<sup>14+</sup> 11789 11790on(eventType: 'windowStageClose', callback: Callback<void>): void 11791 11792Subscribes to the click event on the close button in the three-button navigation bar of the main window. This event is triggered when the close button in the three-button navigation bar of the main window is clicked. The registered lifecycle callback function [UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonpreparetoterminate10) is not executed. 11793 11794If the event is subscribed to multiple times, only the most recently subscribed-to event takes effect. 11795 11796The callback function in this API is executed synchronously. For asynchronous close events of the main window, refer to [on('windowWillClose')](#onwindowwillclose15). 11797 11798If there is an existing event subscribed to by calling [on('windowWillClose')](#onwindowwillclose15), only the [on('windowWillClose')](#onwindowwillclose15) API will be responded to. 11799 11800<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 11801 11802**Model restriction**: This API can be used only in the stage model. 11803 11804**System capability**: SystemCapability.Window.SessionManager 11805 11806**Atomic service API**: This API can be used in atomic services since API version 14. 11807 11808**Parameters** 11809 11810| Name | Type | Mandatory | Description | 11811| --------- | -------------------- | --------- | ------------------------------------------------------------ | 11812| eventType | string | Yes | Event type. The value is fixed at **'windowStageClose'**, indicating that the close button in the three-button navigation bar of the main window is clicked | 11813| callback | Callback<void> | Yes | Callback invoked when the close button in the upper right corner of the main window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Boolean type. The return value determines whether to continue to close the main window. The value **true** means not to close the main window, and **false** means to continue to close the main window. | 11814 11815**Error codes** 11816 11817For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11818 11819| ID | Error Message | 11820| ------- | ------------------------------------------------------------ | 11821| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11822| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11823| 1300002 | This window state is abnormal. | 11824 11825**Example** 11826 11827```ts 11828// EntryAbility.ets 11829import { UIAbility } from '@kit.AbilityKit'; 11830import { window } from '@kit.ArkUI'; 11831 11832export default class EntryAbility extends UIAbility { 11833 // ... 11834 11835 onWindowStageCreate(windowStage: window.WindowStage) { 11836 console.info('onWindowStageCreate'); 11837 try { 11838 windowStage.on('windowStageClose', () => { 11839 console.info('Succeeded in enabling the listener for window stage close event.'); 11840 return false; 11841 }); 11842 } catch (exception) { 11843 console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`); 11844 } 11845 } 11846}; 11847``` 11848 11849### off('windowStageClose')<sup>14+</sup> 11850 11851off(eventType: 'windowStageClose', callback?: Callback<void>): void 11852 11853Unsubscribes from the event indicating that the main window is closed. 11854 11855<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 11856 11857**Model restriction**: This API can be used only in the stage model. 11858 11859**System capability**: SystemCapability.Window.SessionManager 11860 11861**Atomic service API**: This API can be used in atomic services since API version 14. 11862 11863**Parameters** 11864 11865| Name | Type | Mandatory | Description | 11866| --------- | -------------------- | --------- | ------------------------------------------------------------ | 11867| eventType | string | Yes | Event type. The value is fixed at **'windowStageClose'**, indicating that the close button in the three-button navigation bar of the main window is clicked. | 11868| callback | Callback<void> | No | Callback invoked when the close button in the upper right corner of the main window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Boolean type. The return value determines whether to continue to close the main window. The value **true** means not to close the main window, and **false** means to continue to close the main window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 11869 11870**Error codes** 11871 11872For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11873 11874| ID | Error Message | 11875| ------- | ------------------------------------------------------------ | 11876| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11877| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11878| 1300002 | This window state is abnormal. | 11879 11880**Example** 11881 11882```ts 11883// EntryAbility.ets 11884import { UIAbility } from '@kit.AbilityKit'; 11885import { window } from '@kit.ArkUI'; 11886 11887export default class EntryAbility extends UIAbility { 11888 // ... 11889 11890 onWindowStageCreate(windowStage: window.WindowStage) { 11891 console.info('onWindowStageCreate'); 11892 const callback = () => { 11893 // ... 11894 return false; 11895 } 11896 try { 11897 windowStage.on('windowStageClose', callback); 11898 windowStage.off('windowStageClose', callback); 11899 windowStage.off('windowStageClose'); 11900 } catch (exception) { 11901 console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`); 11902 } 11903 } 11904}; 11905``` 11906 11907### setDefaultDensityEnabled<sup>12+</sup> 11908 11909setDefaultDensityEnabled(enabled: boolean): void 11910 11911Enables the system's default density. 11912 11913By default, the system's default density is not used, and the window layout changes with the system display size. 11914 11915**Model restriction**: This API can be used only in the stage model. 11916 11917**Atomic service API**: This API can be used in atomic services since API version 12. 11918 11919**System capability**: SystemCapability.Window.SessionManager 11920 11921**Parameters** 11922 11923| Name | Type | Mandatory | Description | 11924| ------- | ------- | --------- | ------------------------------------------------------------ | 11925| enabled | boolean | Yes | Whether to enable the system's default density. The value **true** means to enable the system's default density, and **false** means the opposite. When the system's default density is enabled, the window layout does not change with the system display size. | 11926 11927**Error codes** 11928 11929For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11930 11931| ID | Error Message | 11932| ------- | ------------------------------------------------------------ | 11933| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11934| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11935| 1300002 | This window state is abnormal. | 11936| 1300005 | This window stage is abnormal. | 11937 11938**Example** 11939 11940```ts 11941// EntryAbility.ets 11942import { UIAbility } from '@kit.AbilityKit'; 11943 11944export default class EntryAbility extends UIAbility { 11945 // ... 11946 11947 onWindowStageCreate(windowStage: window.WindowStage) { 11948 console.info('onWindowStageCreate'); 11949 try { 11950 windowStage.setDefaultDensityEnabled(true); 11951 } catch (exception) { 11952 console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`); 11953 } 11954 } 11955}; 11956``` 11957 11958### setCustomDensity<sup>15+</sup> 11959 11960setCustomDensity(density: number): void 11961 11962Called by the main window to set its own display size scale factor for the main window. Any child windows will adopt the same scale factor as the main window. If both this API and [setDefaultDensityEnabled(true)](#setdefaultdensityenabled12) are called to set a display size scale factor, the settings from the last called API will be applied. 11963 11964**Model restriction**: This API can be used only in the stage model. 11965 11966**Atomic service API**: This API can be used in atomic services since API version 15. 11967 11968**System capability**: SystemCapability.Window.SessionManager 11969 11970**Parameters** 11971 11972| Name | Type | Mandatory | Description | 11973| ------- | ------ | --------- | ------------------------------------------------------------ | 11974| density | number | Yes | Custom display size scale factor. The value is a floating point number in the range [0.5, 4.0] or set to **-1.0**, The value **4.0** indicates the largest permissible display size scale factor for the window, and **-1.0** means that the window uses the system's default display size scale factor. | 11975 11976**Error codes** 11977 11978For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 11979 11980| ID | Error Message | 11981| ------- | ------------------------------------------------------------ | 11982| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11983| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11984| 1300002 | This window state is abnormal. | 11985| 1300005 | This window stage is abnormal. | 11986 11987**Example** 11988 11989```ts 11990// EntryAbility.ets 11991import { UIAbility } from '@kit.AbilityKit'; 11992 11993export default class EntryAbility extends UIAbility { 11994 // ... 11995 11996 onWindowStageCreate(windowStage: window.WindowStage) { 11997 console.info('onWindowStageCreate'); 11998 try { 11999 windowStage.setCustomDensity(-1.0); 12000 } catch (exception) { 12001 console.error(`Failed to set custom density. Cause code: ${exception.code}, message: ${exception.message}`); 12002 } 12003 } 12004}; 12005``` 12006 12007### setWindowModal<sup>14+</sup> 12008 12009setWindowModal(isModal: boolean): Promise<void> 12010 12011Enables the modal property of the main window. This API uses a promise to return the result. 12012 12013This API must be called by the main window and the setting takes effect for the main window. After the modal property of the main window is enabled, other main windows in the same application process and their child windows do not respond to user interactions until the main window is closed or the main window's modal property is disabled. 12014 12015<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 12016 12017**Model restriction**: This API can be used only in the stage model. 12018 12019**Atomic service API**: This API can be used in atomic services since API version 14. 12020 12021**System capability**: SystemCapability.Window.SessionManager 12022 12023**Parameters** 12024 12025| Name | Type | Mandatory | Description | 12026| ------- | ------- | --------- | ------------------------------------------------------------ | 12027| isModal | boolean | Yes | Whether to enable the modal property of the main window. The value **true** means to enable the modal property, and **false** means the opposite. | 12028 12029 12030**Return value** 12031 12032| Type | Description | 12033| ------------------- | ------------------------------ | 12034| Promise<void> | Promise that returns no value. | 12035 12036**Error codes** 12037 12038For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 12039 12040| ID | Error Message | 12041| ------- | ------------------------------------------------------------ | 12042| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12043| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12044| 1300002 | This window state is abnormal. | 12045| 1300003 | This window manager service works abnormally. | 12046 12047**Example** 12048 12049```ts 12050// EntryAbility.ets 12051import { UIAbility } from '@kit.AbilityKit'; 12052import { BusinessError } from '@kit.BasicServicesKit'; 12053 12054export default class EntryAbility extends UIAbility { 12055 // ... 12056 onWindowStageCreate(windowStage: window.WindowStage): void { 12057 console.info('onWindowStageCreate'); 12058 try { 12059 let promise = windowStage.setWindowModal(true); 12060 promise.then(() => { 12061 console.info('Succeeded in setting window modal'); 12062 }).catch((err: BusinessError) => { 12063 console.error(`Failed to set window modal. Cause code: ${err.code}, message: ${err.message}`); 12064 }); 12065 } catch (exception) { 12066 console.error(`Failed to set window modal. Cause code: ${exception.code}, message: ${exception.message}`); 12067 } 12068 } 12069} 12070``` 12071 12072### removeStartingWindow<sup>14+</sup> 12073 12074removeStartingWindow(): Promise<void> 12075 12076Allows the application to control the time when the launch page disappears. 12077 12078This API takes effect only for the application main window when **enable.remove.starting.window** under **metadata** in [abilities](../../quick-start/module-configuration-file.md#abilities) in the **module.json5** file is set to **true**. 12079 12080If the tag is set to **true**, the system provides timeout protection for the launch page. If this API is not called within 5 seconds, the system automatically removes the launch page. 12081 12082If the tag is set to **false** or is not configured, this API does not take effect. The launch page will be automatically removed after the first frame of the application is rendered. 12083 12084**Model restriction**: This API can be used only in the stage model. 12085 12086**Atomic service API**: This API can be used in atomic services since API version 14. 12087 12088**System capability**: SystemCapability.Window.SessionManager 12089 12090**Return value** 12091 12092| Type | Description | 12093| ------------------- | ------------------------------ | 12094| Promise<void> | Promise that returns no value. | 12095 12096**Error codes** 12097 12098For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 12099 12100| ID | Error Message | 12101| ------- | ------------------------------------------------------------ | 12102| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12103| 1300002 | This window state is abnormal. | 12104| 1300003 | This window manager service works abnormally. | 12105 12106**Example** 12107 12108```ts 12109// EntryAbility.ets 12110import { UIAbility } from '@kit.AbilityKit'; 12111import { BusinessError } from '@kit.BasicServicesKit'; 12112 12113export default class EntryAbility extends UIAbility { 12114 // ... 12115 12116 onWindowStageCreate(windowStage: window.WindowStage) { 12117 console.info('onWindowStageCreate'); 12118 windowStage.removeStartingWindow().then(() => { 12119 console.info('Succeeded in removing starting window.'); 12120 }).catch((err: BusinessError) => { 12121 console.error(`Failed to remove starting window. Cause code: ${err.code}, message: ${err.message}`); 12122 }); 12123 } 12124}; 12125``` 12126 12127### setWindowRectAutoSave<sup>14+</sup> 12128 12129setWindowRectAutoSave(enabled: boolean): Promise<void> 12130 12131Sets whether to enable the auto-save feature for the size of the main window. This API uses a promise to return the result. It takes effect only on 2-in-1 devices. 12132 12133This API must be called by the main window and the setting takes effect for the main window. When the auto-save feature is enabled, the application will remember the size and state of the main window upon its closure under the same UIAbility. 12134 12135Upon relaunch, the window will reopen in accordance with these remembered size and state. 12136 12137The following rules apply in stacking scenarios: 12138 121391. If the current instance is a free-form window, the next opened window will adopt the same size when stacked. 121402. If the current instance is maximized or in full-screen mode, the next opened window will maintain the maximized state when stacked. 12141 12142The following table describes the memory rules: 12143 12144| Last Window State | Memorizing Rule | 12145| ------------------- | ------------------------------------------------------------ | 12146| Free-form window | Retains the size/position of the free-form window, rebound if exceeding the workspace | 12147| Split-screen window | Retains the size and position of the free-form window before screen splitting. | 12148| Maximized window | Retains the maximized state. | 12149| Immersive window | Retains the size and position of the free-form window before immersive mode. | 12150| Minimized window | Retains the size and position of the free-form window before minimization. | 12151 12152**Model restriction**: This API can be used only in the stage model. 12153 12154**Atomic service API**: This API can be used in atomic services since API version 14. 12155 12156**System capability**: SystemCapability.Window.SessionManager 12157 12158**Parameters** 12159 12160| Name | Type | Mandatory | Description | 12161| ------- | ------- | --------- | ------------------------------------------------------------ | 12162| enabled | boolean | Yes | Whether to enable the auto-save feature for the main window's size. The value **true** means to enable the auto-save feature, and **false** means the opposite. | 12163 12164 12165**Return value** 12166 12167| Type | Description | 12168| ------------------- | ------------------------------ | 12169| Promise<void> | Promise that returns no value. | 12170 12171**Error codes** 12172 12173For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 12174 12175| ID | Error Message | 12176| ------- | ------------------------------------------------------------ | 12177| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12178| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12179| 1300002 | This window state is abnormal. | 12180| 1300003 | This window manager service works abnormally. | 12181 12182**Example** 12183 12184```ts 12185// EntryAbility.ets 12186import { UIAbility } from '@kit.AbilityKit'; 12187import { BusinessError } from '@kit.BasicServicesKit'; 12188 12189export default class EntryAbility extends UIAbility { 12190 // ... 12191 onWindowStageCreate(windowStage: window.WindowStage): void { 12192 console.info('onWindowStageCreate'); 12193 try { 12194 let promise = windowStage.setWindowRectAutoSave(true); 12195 promise.then(() => { 12196 console.info('Succeeded in setting window rect auto-save'); 12197 }).catch((err: BusinessError) => { 12198 console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 12199 }); 12200 } catch (exception) { 12201 console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 12202 } 12203 } 12204} 12205``` 12206 12207### isWindowRectAutoSave<sup>14+</sup> 12208 12209isWindowRectAutoSave(): Promise<boolean> 12210 12211Checks whether the auto-save feature is enabled for the main window's size. This API uses a promise to return the result. It takes effect only on 2-in-1 devices. 12212 12213**Model restriction**: This API can be used only in the stage model. 12214 12215**Atomic service API**: This API can be used in atomic services since API version 14. 12216 12217**System capability**: SystemCapability.Window.SessionManager 12218 12219**Return value** 12220 12221| Type | Description | 12222| ---------------------- | ------------------------------------------------------------ | 12223| Promise<boolean> | Promise used to return the result. The value **true** means that the auto-save feature is enabled, and **false** means the opposite. | 12224 12225**Error codes** 12226 12227For details about the error codes, see [Window Error Codes](errorcode-window.md). 12228 12229| ID | Error Message | 12230| ------- | ------------------------------------------------------------ | 12231| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12232| 1300002 | This window state is abnormal. | 12233 12234**Example** 12235 12236```ts 12237// EntryAbility.ets 12238import { UIAbility } from '@kit.AbilityKit'; 12239import { BusinessError } from '@kit.BasicServicesKit'; 12240 12241export default class EntryAbility extends UIAbility { 12242 // ... 12243 onWindowStageCreate(windowStage: window.WindowStage): void { 12244 console.info('onWindowStageCreate'); 12245 try { 12246 let promise = windowStage.isWindowRectAutoSave(); 12247 promise.then((data) => { 12248 console.info('Succeeded in checking whether the window support the rect auto-save. Data: ' + JSON.stringify(data)); 12249 }).catch((err: BusinessError) => { 12250 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 12251 }); 12252 } catch (exception) { 12253 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 12254 } 12255 } 12256} 12257``` 12258 12259### setSupportedWindowModes<sup>15+</sup> 12260 12261setSupportedWindowModes(supportedWindowModes: Array<bundleManager.SupportWindowMode>): Promise<void> 12262 12263Sets the supported window modes of the main window. This API uses a promise to return the result. 12264 12265<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 12266 12267**Model restriction**: This API can be used only in the stage model. 12268 12269**Atomic service API**: This API can be used in atomic services since API version 15. 12270 12271**System capability**: SystemCapability.Window.SessionManager 12272 12273**Parameters** 12274 12275| Name | Type | Mandatory | Description | 12276| -------------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 12277| supportedWindowModes | Array<[bundleManager.SupportWindowMode](../apis-ability-kit/js-apis-bundleManager.md#supportwindowmode)> | Yes | Supported window modes.<br>- **FULL_SCREEN**: full-screen mode.<br>- **FLOATING**: floating window mode.<br>- **SPLIT**: split-screen mode. **FULL_SCREEN** or **FLOATING** must be used together. Configuring only **SPLIT** is not supported.<br> Note: The values of the **SupportWindowMode** field in the array should not conflict with the values of the **supportWindowMode** field under [abilities](../../quick-start/module-configuration-file.md#abilities) of the [module.json5 file](../../quick-start/module-configuration-file.md) corresponding to this UIAbility, or with the values of the **supportWindowModes** field in [StartOptions](../apis-ability-kit/js-apis-app-ability-startOptions.md). In case of a conflict, the window support mode set by this parameter will take precedence. | 12278 12279**Return value** 12280 12281| Type | Description | 12282| ------------------- | ------------------------------ | 12283| Promise<void> | Promise that returns no value. | 12284 12285**Error codes** 12286 12287For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 12288 12289| ID | Error Message | 12290| ------- | ------------------------------------------------------------ | 12291| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12292| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12293| 1300002 | This window state is abnormal. | 12294| 1300003 | This window manager service works abnormally. | 12295 12296**Example** 12297 12298```ts 12299// EntryAbility.ets 12300import { UIAbility, bundleManager } from '@kit.AbilityKit'; 12301import { BusinessError } from '@kit.BasicServicesKit'; 12302 12303export default class EntryAbility extends UIAbility { 12304 // ... 12305 onWindowStageCreate(windowStage: window.WindowStage): void { 12306 console.info('onWindowStageCreate'); 12307 try { 12308 let promise = windowStage.setSupportedWindowModes([ 12309 bundleManager.SupportWindowMode.FULL_SCREEN, 12310 bundleManager.SupportWindowMode.SPLIT, 12311 bundleManager.SupportWindowMode.FLOATING 12312 ]); 12313 promise.then(() => { 12314 console.info('Succeeded in setting window support modes'); 12315 }).catch((err: BusinessError) => { 12316 console.error(`Failed to set window support modes. Cause code: ${err.code}, message: ${err.message}`); 12317 }); 12318 } catch (exception) { 12319 console.error(`Failed to set window support modes. Cause code: ${exception.code}, message: ${exception.message}`); 12320 } 12321 } 12322} 12323```