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 functions: 6 7- [Window](#window): the current 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 '@ohos.window'; 18``` 19 20## WindowType<sup>7+</sup> 21 22 23Enumerates the window types. 24 25**System capability**: SystemCapability.WindowManager.WindowManager.Core 26 27| Name | Value| Description | 28|-------------------------------------| ------ |----------------------------------------------------------------------------------------| 29| TYPE_APP | 0 | Application subwindow.<br>**Model restriction**: This API can be used only in the FA model. | 30| TYPE_SYSTEM_ALERT | 1 | System alert window.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 11. | 31| TYPE_FLOAT<sup>9+</sup> | 8 | Floating window.<br>**Model restriction**: This API can be used only in the stage model.<br>**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW| 32| TYPE_DIALOG<sup>10+</sup> | 16 | Modal window.<br>**Model restriction**: This API can be used only in the stage model. | 33 34## Configuration<sup>9+</sup> 35 36Defines the parameters for creating a subwindow or system window. 37 38**System capability**: SystemCapability.WindowManager.WindowManager.Core 39 40| Name| Type| Mandatory| Description | 41| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 42| name | string | Yes| Name of the window. | 43| windowType | [WindowType](#windowtype7) | Yes| Type of the window. | 44| 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>You do not need to set this parameter to create a subwindow in the FA model or a system window in the stage model.| 45| 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. | 46| 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. | 47 48## AvoidAreaType<sup>7+</sup> 49 50Enumerates the types of the area where the window cannot be displayed. 51 52**System capability**: SystemCapability.WindowManager.WindowManager.Core 53 54| Name | Value | Description | 55| -------------------------------- | ---- | ------------------------------------------------------------ | 56| 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.| 57| TYPE_CUTOUT | 1 | Notch. | 58| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | Gesture area. | 59| TYPE_KEYBOARD<sup>9+</sup> | 3 | Soft keyboard area. | 60| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4 | Navigation bar area. | 61 62 63## SystemBarProperties 64 65Describes the properties of the status bar and navigation bar. 66 67**System capability**: SystemCapability.WindowManager.WindowManager.Core 68 69| Name | Type| Mandatory| Description | 70| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 71| 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 **#0x66000000**.| 72| 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**.| 73| 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 **0xE5FFFFFF**.| 74| 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 **#0x66000000**.| 75| 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**.| 76| 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 **0xE5FFFFFF**.| 77 78## Orientation<sup>9+</sup> 79 80Enumerates the window orientations. 81 82**System capability**: SystemCapability.WindowManager.WindowManager.Core 83 84| Name | Value | Description | 85| ------------------------------------- | ---- | ----------------------------- | 86| UNSPECIFIED | 0 | Unspecified. The orientation is determined by the system.| 87| PORTRAIT | 1 | Portrait. | 88| LANDSCAPE | 2 | Landscape. | 89| PORTRAIT_INVERTED | 3 | Reverse portrait. | 90| LANDSCAPE_INVERTED | 4 | Reverse landscape.| 91| AUTO_ROTATION | 5 | Auto rotation.| 92| AUTO_ROTATION_PORTRAIT | 6 | Auto rotation in the vertical direction.| 93| AUTO_ROTATION_LANDSCAPE | 7 | Auto rotation in the horizontal direction.| 94| AUTO_ROTATION_RESTRICTED | 8 | Switched-determined auto rotation.| 95| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | Switched-determined auto rotation in the vertical direction.| 96| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | Switched-determined auto rotation in the horizontal direction.| 97| LOCKED | 11 | Locked.| 98 99 100## Rect<sup>7+</sup> 101 102Describes the rectangular area of the window. 103 104**System capability**: SystemCapability.WindowManager.WindowManager.Core 105 106| Name | Type| Readable| Writable| Description | 107| ------ | -------- | ---- | ---- | ------------------ | 108| left | number | Yes | Yes | Left boundary of the rectangle, in px. The value must be an integer.| 109| top | number | Yes | Yes | Top boundary of the rectangle, in px. The value must be an integer.| 110| width | number | Yes | Yes | Width of the rectangle, in px. The value must be an integer.| 111| height | number | Yes | Yes | Height of the rectangle, in px. The value must be an integer.| 112 113## AvoidArea<sup>7+</sup> 114 115Describes the area where the window cannot be displayed. 116 117**System capability**: SystemCapability.WindowManager.WindowManager.Core 118 119| Name | Type | Readable| Writable| Description | 120| ---------- | ------------- | ---- | ---- | ------------------ | 121| 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.| 122| leftRect | [Rect](#rect7) | Yes | Yes | Rectangle on the left of the screen.| 123| topRect | [Rect](#rect7) | Yes | Yes | Rectangle at the top of the screen.| 124| rightRect | [Rect](#rect7) | Yes | Yes | Rectangle on the right of the screen.| 125| bottomRect | [Rect](#rect7) | Yes | Yes | Rectangle at the bottom of the screen.| 126 127## Size<sup>7+</sup> 128 129Describes the window size. 130 131**System capability**: SystemCapability.WindowManager.WindowManager.Core 132 133| Name | Type| Readable| Writable| Description | 134| ------ | -------- | ---- | ---- | ---------- | 135| width | number | Yes | Yes | Window width, in px. The value must be an integer.| 136| height | number | Yes | Yes | Window height, in px. The value must be an integer.| 137 138## WindowProperties 139 140Describes the window properties. 141 142**System capability**: SystemCapability.WindowManager.WindowManager.Core 143 144| Name | Type | Readable| Writable| Description | 145| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 146| windowRect<sup>7+</sup> | [Rect](#rect7) | Yes | Yes | Window size. | 147| drawableRect<sup>11+</sup> | [Rect](#rect7) | Yes | Yes | Size of the rectangle that can be drawn in the window. The upper boundary and left boundary are calculated relative to the window. | 148| type<sup>7+</sup> | [WindowType](#windowtype7) | Yes | Yes | Window type. | 149| isFullScreen | boolean | Yes | Yes | 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. | 150| isLayoutFullScreen<sup>7+</sup> | boolean | Yes | Yes | 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. | 151| 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. | 152| 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. | 153| brightness | number | Yes | Yes | 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**. | 154| dimBehindValue<sup>(deprecated)</sup> | number | Yes | Yes | 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. | 155| isKeepScreenOn | boolean | Yes | Yes | 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. | 156| isPrivacyMode<sup>7+</sup> | boolean | Yes | Yes | 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. | 157| isRoundCorner<sup>(deprecated)</sup> | boolean | Yes | Yes | 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. | 158| isTransparent<sup>7+</sup> | boolean | Yes | Yes | Whether the window is transparent. The default value is **false**. The value **true** means that the window is transparent, and **false** means the opposite. | 159| id<sup>9+</sup> | number | Yes | No | Window ID. The default value is **0**. The value must be an integer. | 160 161## ColorSpace<sup>8+</sup> 162 163Enumerates the color spaces. 164 165**System capability**: SystemCapability.WindowManager.WindowManager.Core 166 167| Name | Value| Description | 168| ---------- | ------ | -------------- | 169| DEFAULT | 0 | Default SRGB gamut.| 170| WIDE_GAMUT | 1 | Wide-gamut. | 171 172## WindowEventType<sup>10+</sup> 173 174Enumerates the window lifecycle states. 175 176| Name | Value| Description | 177| ---------- | ------ | ---------- | 178| WINDOW_SHOWN | 1 | The window is running in the foreground.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 179| WINDOW_ACTIVE | 2 | The window gains focus.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 180| WINDOW_INACTIVE | 3 | The window loses focus.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 181| WINDOW_HIDDEN | 4 | The window is running in the background.<br>**System capability**: SystemCapability.WindowManager.WindowManager.Core| 182| WINDOW_DESTROYED<sup>11+</sup> | 7 | The window is destroyed.<br>**System capability**: SystemCapability.Window.SessionManager| 183 184## WindowLimits<sup>11+</sup> 185 186Defines the window size limits. 187 188**System capability**: SystemCapability.Window.SessionManager 189 190| Name | Type | Readable| Writable| Description | 191| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- | 192| maxWidth | number | Yes | Yes | Maximum window width, in px. The value must be an integer. The default value is **0**, indicating that the attribute does not change. The lower limit is **0**, and the upper limit is the maximum width specified by the system. | 193| maxHeight | number | Yes | Yes | Maximum window height, in px. The value must be an integer. The default value is **0**, indicating that the attribute does not change. The lower limit is **0**, and the upper limit is the maximum height specified by the system. | 194| minWidth | number | Yes | Yes | Minimum window width, in px. The value must be an integer. The default value is **0**, indicating that the attribute does not change. The lower limit is **0**, and the upper limit is the minimum width specified by the system. | 195| minHeight | number | Yes | Yes | Minimum window height, in px. The value must be an integer. The default value is **0**, indicating that the attribute does not change. The lower limit is **0**, and the upper limit is the minimum height specified by the system. | 196 197## WindowStatusType<sup>11+</sup> 198 199Enumerates the window modes. 200 201**System capability**: SystemCapability.Window.SessionManager 202 203| Name | Value | Description | 204| ---------- | ---- | ----------------------------- | 205| UNDEFINED | 0 | The window mode is not defined by the application. | 206| FULL_SCREEN | 1 | The application is displayed in full screen. | 207| MAXIMIZE | 2 | The application window is maximized. | 208| MINIMIZE | 3 | The application window is minimized. | 209| FLOATING | 4 | The application is displayed in a floating window. | 210| SPLIT_SCREEN | 5 | The application is displayed in split-screen mode. | 211 212## TitleButtonRect<sup>11+</sup> 213 214Defines 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. 215 216**System capability**: SystemCapability.Window.SessionManager 217 218| Name | Type | Readable| Writable| Description | 219| ------ | ------ | ---- | ---- | ------------------------------------------ | 220| right | number | Yes | Yes | Right boundary of the rectangle, in vp. The value must be an integer.| 221| top | number | Yes | Yes | Top boundary of the rectangle, in vp. The value must be an integer.| 222| width | number | Yes | Yes | Width of the rectangle, in vp. The value must be an integer. | 223| height | number | Yes | Yes | Height of the rectangle, in vp. The value must be an integer. | 224 225## window.createWindow<sup>9+</sup> 226 227createWindow(config: Configuration, callback: AsyncCallback<Window>): void 228 229Creates a subwindow or system window. This API uses an asynchronous callback to return the result. 230 231**System capability**: SystemCapability.WindowManager.WindowManager.Core 232 233**Parameters** 234 235| Name| Type| Mandatory| Description| 236| -------- | -------------------------------------- | -- | --------------------------------- | 237| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window. | 238| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the window created.| 239 240**Error codes** 241 242For details about the error codes, see [Window Error Codes](errorcode-window.md). 243 244| ID| Error Message| 245| ------- | -------------------------------- | 246| 1300001 | Repeated operation. | 247| 1300006 | This window context is abnormal. | 248| 1300008 | The operation is on invalid display. | 249| 1300009 | The parent window is invalid. | 250 251**Example** 252 253```ts 254import { BusinessError } from '@ohos.base'; 255 256let windowClass: window.Window | undefined = undefined; 257let config: window.Configuration = { 258 name: "test", 259 windowType: window.WindowType.TYPE_DIALOG, 260 ctx: this.context 261}; 262try { 263 window.createWindow(config, (err: BusinessError, data) => { 264 const errCode: number = err.code; 265 if (errCode) { 266 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 267 return; 268 } 269 windowClass = data; 270 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 271 windowClass.resize(500, 1000); 272 }); 273} catch (exception) { 274 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 275} 276``` 277 278## window.createWindow<sup>9+</sup> 279 280createWindow(config: Configuration): Promise<Window> 281 282Creates a subwindow or system window. This API uses a promise to return the result. 283 284**System capability**: SystemCapability.WindowManager.WindowManager.Core 285 286**Parameters** 287 288| Name| Type| Mandatory| Description| 289| ------ | -------------------------------- | -- | ------------------ | 290| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window.| 291 292**Return value** 293 294| Type| Description| 295| -------------------------------- | ------------------------------------ | 296| Promise<[Window](#window)> | Promise used to return the window created.| 297 298**Error codes** 299 300For details about the error codes, see [Window Error Codes](errorcode-window.md). 301 302| ID| Error Message| 303| ------- | -------------------------------- | 304| 1300001 | Repeated operation. | 305| 1300006 | This window context is abnormal. | 306| 1300008 | The operation is on invalid display. | 307| 1300009 | The parent window is invalid. | 308 309**Example** 310 311```ts 312import { BusinessError } from '@ohos.base'; 313 314let windowClass: window.Window | undefined = undefined; 315let config: window.Configuration = { 316 name: "test", 317 windowType: window.WindowType.TYPE_DIALOG, 318 ctx: this.context 319}; 320try { 321 let promise = window.createWindow(config); 322 promise.then((data) => { 323 windowClass = data; 324 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 325 }).catch((err: BusinessError) => { 326 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 327 }); 328} catch (exception) { 329 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 330} 331``` 332 333## window.findWindow<sup>9+</sup> 334 335findWindow(name: string): Window 336 337Finds a window based on the name. 338 339**System capability**: SystemCapability.WindowManager.WindowManager.Core 340 341**Parameters** 342 343| Name| Type | Mandatory| Description | 344| ------ | ------ | ---- | -------- | 345| name | string | Yes | Window ID.| 346 347**Return value** 348 349| Type| Description| 350| ----------------- | ------------------- | 351| [Window](#window) | Window found.| 352 353**Error codes** 354 355For details about the error codes, see [Window Error Codes](errorcode-window.md). 356 357| ID| Error Message| 358| ------- | -------------------------------- | 359| 1300002 | This window state is abnormal. | 360 361**Example** 362 363```ts 364let windowClass: window.Window | undefined = undefined; 365try { 366 windowClass = window.findWindow('test'); 367} catch (exception) { 368 console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception)); 369} 370``` 371 372## window.getLastWindow<sup>9+</sup> 373 374getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 375 376Obtains the top window of the current application. This API uses an asynchronous callback to return the result. If no subwindow is available, the main window of the application is returned. 377 378**System capability**: SystemCapability.WindowManager.WindowManager.Core 379 380**Parameters** 381 382| Name| Type| Mandatory| Description| 383| -------- | -------------------------------------- | -- | ---------------------------------------- | 384| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Current application context.| 385| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the top window obtained.| 386 387**Error codes** 388 389For details about the error codes, see [Window Error Codes](errorcode-window.md). 390 391| ID| Error Message| 392| ------- | -------------------------------- | 393| 1300002 | This window state is abnormal. | 394| 1300006 | This window context is abnormal. | 395 396**Example** 397 398```ts 399import UIAbility from '@ohos.app.ability.UIAbility'; 400import window from '@ohos.window'; 401import { BusinessError } from '@ohos.base'; 402 403export default class EntryAbility extends UIAbility { 404 // ... 405 onWindowStageCreate(windowStage: window.WindowStage) { 406 console.info('onWindowStageCreate'); 407 let windowClass: window.Window | undefined = undefined; 408 try { 409 window.getLastWindow(this.context, (err: BusinessError, data) => { 410 const errCode: number = err.code; 411 if (errCode) { 412 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 413 return; 414 } 415 windowClass = data; 416 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 417 }); 418 } catch (exception) { 419 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 420 } 421 } 422} 423``` 424 425## window.getLastWindow<sup>9+</sup> 426 427getLastWindow(ctx: BaseContext): Promise<Window> 428 429Obtains the top window of the current application. This API uses a promise to return the result. If no subwindow is available, the main window of the application is returned. 430 431**System capability**: SystemCapability.WindowManager.WindowManager.Core 432 433**Parameters** 434 435| Name| Type| Mandatory| Description| 436| ------ | ----------- | ---- | ------------------------------------------------------------ | 437| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 438 439**Return value** 440 441| Type| Description| 442| -------------------------------- | ------------------------------------------- | 443| Promise<[Window](#window)> | Promise used to return the top window obtained.| 444 445**Error codes** 446 447For details about the error codes, see [Window Error Codes](errorcode-window.md). 448 449| ID| Error Message| 450| ------- | -------------------------------- | 451| 1300002 | This window state is abnormal. | 452| 1300006 | This window context is abnormal. | 453 454**Example** 455 456```ts 457import UIAbility from '@ohos.app.ability.UIAbility'; 458import window from '@ohos.window'; 459import { BusinessError } from '@ohos.base'; 460 461export default class EntryAbility extends UIAbility { 462 // ... 463 onWindowStageCreate(windowStage: window.WindowStage) { 464 console.info('onWindowStageCreate'); 465 let windowClass: window.Window | undefined = undefined; 466 try { 467 let promise = window.getLastWindow(this.context); 468 promise.then((data) => { 469 windowClass = data; 470 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 471 }).catch((err: BusinessError) => { 472 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 473 }); 474 } catch (exception) { 475 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 476 } 477 } 478} 479``` 480 481## window.shiftAppWindowFocus<sup>11+</sup> 482shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise<void> 483 484Shifts 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 subwindow. 485 486**System capability**: SystemCapability.Window.SessionManager 487 488**Parameters** 489 490| Name | Type | Mandatory | Description | 491| -------------- | ------ | ----- | ----------------------- | 492| sourceWindowId | number | Yes | ID of the source window, which is having the focus.| 493| targetWindowId | number | Yes | ID of the target window. | 494 495**Return value** 496 497| Type | Description | 498| ------------------- | ------------------------- | 499| Promise<void> | Promise that returns no value.| 500 501**Error codes** 502 503For details about the error codes, see [Window Error Codes](errorcode-window.md). 504 505| ID| Error Message | 506| ------- | --------------------------------------------- | 507| 1300002 | This window state is abnormal. | 508| 1300003 | This window manager service works abnormally. | 509| 1300004 | Unauthorized operation. | 510 511**Example** 512 513```ts 514import { BusinessError } from '@ohos.base'; 515 516try { 517 let sourceWindowId: number = 40; 518 let targetWindowId: number = 41; 519 let promise = window.shiftAppWindowFocus(sourceWindowId, targetWindowId); 520 promise.then(() => { 521 console.info('Succeeded in shifting app window focus'); 522 }).catch((err: BusinessError) => { 523 console.error('Failed to shift app window focus. Cause:' + JSON.stringify(err)); 524 }); 525} catch (exception) { 526 console.error('Failed to shift app window focus. Cause:' + JSON.stringify(exception)); 527} 528``` 529 530## window.create<sup>(deprecated)</sup> 531 532create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 533 534Creates a subwindow. This API uses an asynchronous callback to return the result. 535 536> **NOTE** 537> 538> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 539 540**Model restriction**: This API can be used only in the FA model. 541 542**System capability**: SystemCapability.WindowManager.WindowManager.Core 543 544**Parameters** 545 546| Name | Type | Mandatory| Description | 547| -------- | -------------------------------------- | ---- | ------------------------------------ | 548| id | string | Yes | Window ID. | 549| type | [WindowType](#windowtype7) | Yes | Window type. | 550| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created.| 551 552**Example** 553 554```ts 555import { BusinessError } from '@ohos.base'; 556 557let windowClass: window.Window | undefined = undefined; 558window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 559 const errCode: number = err.code; 560 if (errCode) { 561 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 562 return; 563 } 564 windowClass = data; 565 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 566}); 567``` 568 569## window.create<sup>(deprecated)</sup> 570 571create(id: string, type: WindowType): Promise<Window> 572 573Creates a subwindow. This API uses a promise to return the result. 574 575> **NOTE** 576> 577> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 578 579**Model restriction**: This API can be used only in the FA model. 580 581**System capability**: SystemCapability.WindowManager.WindowManager.Core 582 583**Parameters** 584 585| Name| Type | Mandatory| Description | 586| ------ | ------------------------- | ---- | ---------- | 587| id | string | Yes | Window ID. | 588| type | [WindowType](#windowtype7) | Yes | Window type.| 589 590**Return value** 591 592| Type | Description | 593| -------------------------------- | --------------------------------------- | 594| Promise<[Window](#window)> | Promise used to return the subwindow created.| 595 596**Example** 597 598```ts 599import { BusinessError } from '@ohos.base'; 600 601let windowClass: window.Window | undefined = undefined; 602let promise = window.create('test', window.WindowType.TYPE_APP); 603promise.then((data) => { 604 windowClass = data; 605 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 606}).catch((err: BusinessError) => { 607 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 608}); 609``` 610 611## window.create<sup>(deprecated)</sup> 612 613create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 614 615Creates a system window. This API uses an asynchronous callback to return the result. 616 617> **NOTE** 618> 619> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 620 621**System capability**: SystemCapability.WindowManager.WindowManager.Core 622 623**Parameters** 624 625| Name | Type | Mandatory| Description | 626| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 627| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context. | 628| id | string | Yes | Window ID. | 629| type | [WindowType](#windowtype7) | Yes | Window type. | 630| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created.| 631 632**Example** 633 634```ts 635import { BusinessError } from '@ohos.base'; 636 637let windowClass: window.Window | undefined = undefined; 638window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 639 const errCode: number = err.code; 640 if (errCode) { 641 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 642 return; 643 } 644 windowClass = data; 645 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 646 windowClass.resetSize(500, 1000); 647}); 648``` 649 650## window.create<sup>(deprecated)</sup> 651 652create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 653 654Creates a system window. This API uses a promise to return the result. 655 656> **NOTE** 657> 658> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 659 660**System capability**: SystemCapability.WindowManager.WindowManager.Core 661 662**Parameters** 663 664| Name| Type | Mandatory| Description | 665| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 666| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 667| id | string | Yes | Window ID. | 668| type | [WindowType](#windowtype7) | Yes | Window type. | 669 670**Return value** 671 672| Type | Description | 673| -------------------------------- | --------------------------------------- | 674| Promise<[Window](#window)> | Promise used to return the subwindow created.| 675 676**Example** 677 678```ts 679import { BusinessError } from '@ohos.base'; 680 681let windowClass: window.Window | undefined = undefined; 682let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 683promise.then((data) => { 684 windowClass = data; 685 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 686}).catch((err: BusinessError) => { 687 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 688}); 689``` 690 691## window.find<sup>(deprecated)</sup> 692 693find(id: string, callback: AsyncCallback<Window>): void 694 695Finds a window based on the ID. This API uses an asynchronous callback to return the result. 696 697> **NOTE** 698> 699> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 700 701**System capability**: SystemCapability.WindowManager.WindowManager.Core 702 703**Parameters** 704 705| Name | Type | Mandatory| Description | 706| -------- | -------------------------------------- | ---- | ------------------------------------ | 707| id | string | Yes | Window ID. | 708| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the window found.| 709 710**Example** 711 712```ts 713import { BusinessError } from '@ohos.base'; 714 715let windowClass: window.Window | undefined = undefined; 716window.find('test', (err: BusinessError, data) => { 717 const errCode: number = err.code; 718 if (errCode) { 719 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 720 return; 721 } 722 windowClass = data; 723 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 724}); 725``` 726 727## window.find<sup>(deprecated)</sup> 728 729find(id: string): Promise<Window> 730 731Finds a window based on the ID. This API uses a promise to return the result. 732 733> **NOTE** 734> 735> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 736 737**System capability**: SystemCapability.WindowManager.WindowManager.Core 738 739**Parameters** 740 741| Name| Type | Mandatory| Description | 742| ------ | ------ | ---- | -------- | 743| id | string | Yes | Window ID.| 744 745**Return value** 746 747| Type | Description | 748| -------------------------------- | ------------------------------------- | 749| Promise<[Window](#window)> | Promise used to return the window found.| 750 751**Example** 752 753```ts 754import { BusinessError } from '@ohos.base'; 755 756let windowClass: window.Window | undefined = undefined; 757let promise = window.find('test'); 758promise.then((data) => { 759 windowClass = data; 760 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 761}).catch((err: BusinessError) => { 762 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 763}); 764``` 765 766## window.getTopWindow<sup>(deprecated)</sup> 767 768getTopWindow(callback: AsyncCallback<Window>): void 769 770Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 771 772> **NOTE** 773> 774> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 775 776**Model restriction**: This API can be used only in the FA model. 777 778**System capability**: SystemCapability.WindowManager.WindowManager.Core 779 780**Parameters** 781 782| Name | Type | Mandatory| Description | 783| -------- | -------------------------------------- | ---- | -------------------------------------------- | 784| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained.| 785 786**Example** 787 788```ts 789import { BusinessError } from '@ohos.base'; 790 791let windowClass: window.Window | undefined = undefined; 792window.getTopWindow((err: BusinessError, data) => { 793 const errCode: number = err.code; 794 if (errCode) { 795 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 796 return; 797 } 798 windowClass = data; 799 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 800}); 801``` 802 803## window.getTopWindow<sup>(deprecated)</sup> 804 805getTopWindow(): Promise<Window> 806 807Obtains the top window of the current application. This API uses a promise to return the result. 808 809> **NOTE** 810> 811> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 812 813**Model restriction**: This API can be used only in the FA model. 814 815**System capability**: SystemCapability.WindowManager.WindowManager.Core 816 817**Return value** 818 819| Type | Description | 820| -------------------------------- | ----------------------------------------------- | 821| Promise<[Window](#window)> | Promise used to return the top window obtained.| 822 823**Example** 824 825```ts 826import { BusinessError } from '@ohos.base'; 827 828let windowClass: window.Window | undefined = undefined; 829let promise = window.getTopWindow(); 830promise.then((data)=> { 831 windowClass = data; 832 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 833}).catch((err: BusinessError)=>{ 834 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 835}); 836``` 837 838## window.getTopWindow<sup>(deprecated)</sup> 839 840getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 841 842Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 843 844> **NOTE** 845> 846> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 847 848**System capability**: SystemCapability.WindowManager.WindowManager.Core 849 850**Parameters** 851 852| Name | Type | Mandatory| Description | 853| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 854| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 855| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained. | 856 857**Example** 858 859```ts 860import { BusinessError } from '@ohos.base'; 861 862export default class EntryAbility extends UIAbility { 863 onWindowStageCreate(windowStage:window.WindowStage){ 864 console.info('onWindowStageCreate'); 865 let windowClass: window.Window | undefined = undefined; 866 try { 867 window.getTopWindow(this.context, (err: BusinessError, data) => { 868 const errCode: number = err.code; 869 if(errCode){ 870 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 871 return ; 872 } 873 windowClass = data; 874 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 875 }); 876 } catch(error){ 877 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 878 } 879 } 880} 881``` 882 883## window.getTopWindow<sup>(deprecated)</sup> 884 885getTopWindow(ctx: BaseContext): Promise<Window> 886 887Obtains the top window of the current application. This API uses a promise to return the result. 888 889> **NOTE** 890> 891> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 892 893**System capability**: SystemCapability.WindowManager.WindowManager.Core 894 895**Parameters** 896 897| Name| Type | Mandatory| Description | 898| ------ | ----------- | ---- | ------------------------------------------------------------ | 899| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Current application context.| 900 901**Return value** 902 903| Type | Description | 904| -------------------------------- | ----------------------------------------------- | 905| Promise<[Window](#window)> | Promise used to return the top window obtained.| 906 907**Example** 908 909```ts 910import { BusinessError } from '@ohos.base'; 911 912export default class EntryAbility extends UIAbility { 913 onWindowStageCreate(windowStage:window.WindowStage) { 914 console.info('onWindowStageCreate'); 915 let windowClass: window.Window | undefined = undefined; 916 let promise = window.getTopWindow(this.context); 917 promise.then((data) => { 918 windowClass = data; 919 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 920 }).catch((error: BusinessError) => { 921 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 922 }); 923 } 924} 925``` 926 927## SpecificSystemBar<sup>11+</sup> 928 929Enumerates the types of system bars that can be displayed or hidden. 930 931**System capability**: SystemCapability.Window.SessionManager 932 933| Name | Type | Description | 934|---------------------|----------|--------| 935| status | string | Status bar. | 936| navigation | string | Navigation bar. | 937| navigationIndicator | string | Bottom navigation bar.| 938 939## Window 940 941Represents the current window instance, which is the basic unit managed by the window manager. 942 943In 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. 944 945### showWindow<sup>9+</sup> 946 947showWindow(callback: AsyncCallback<void>): void 948 949Shows this window. This API uses an asynchronous callback to return the result. 950 951**System capability**: SystemCapability.WindowManager.WindowManager.Core 952 953**Parameters** 954 955| Name| Type| Mandatory| Description| 956| -------- | ------------------------- | -- | --------- | 957| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 958 959**Error codes** 960 961For details about the error codes, see [Window Error Codes](errorcode-window.md). 962 963| ID| Error Message| 964| ------- | ------------------------------ | 965| 1300002 | This window state is abnormal. | 966 967**Example** 968 969```ts 970import { BusinessError } from '@ohos.base'; 971 972windowClass.showWindow((err: BusinessError) => { 973 const errCode: number = err.code; 974 if (errCode) { 975 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 976 return; 977 } 978 console.info('Succeeded in showing the window.'); 979}); 980``` 981 982### showWindow<sup>9+</sup> 983 984showWindow(): Promise<void> 985 986Shows this window. This API uses a promise to return the result. 987 988**System capability**: SystemCapability.WindowManager.WindowManager.Core 989 990**Return value** 991 992| Type| Description| 993| ------------------- | ----------------------- | 994| Promise<void> | Promise that returns no value.| 995 996**Error codes** 997 998For details about the error codes, see [Window Error Codes](errorcode-window.md). 999 1000| ID| Error Message| 1001| ------- | ------------------------------ | 1002| 1300002 | This window state is abnormal. | 1003 1004**Example** 1005 1006```ts 1007import { BusinessError } from '@ohos.base'; 1008 1009let promise = windowClass.showWindow(); 1010promise.then(() => { 1011 console.info('Succeeded in showing the window.'); 1012}).catch((err: BusinessError) => { 1013 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1014}); 1015``` 1016 1017### destroyWindow<sup>9+</sup> 1018 1019destroyWindow(callback: AsyncCallback<void>): void 1020 1021Destroys this window. This API uses an asynchronous callback to return the result. 1022 1023**System capability**: SystemCapability.WindowManager.WindowManager.Core 1024 1025**Parameters** 1026 1027| Name| Type| Mandatory| Description| 1028| -------- | ------------------------- | -- | --------- | 1029| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1030 1031**Error codes** 1032 1033For details about the error codes, see [Window Error Codes](errorcode-window.md). 1034 1035| ID| Error Message| 1036| ------- | -------------------------------------------- | 1037| 1300002 | This window state is abnormal. | 1038| 1300003 | This window manager service works abnormally. | 1039 1040**Example** 1041 1042```ts 1043import { BusinessError } from '@ohos.base'; 1044 1045windowClass.destroyWindow((err) => { 1046 const errCode: number = err.code; 1047 if (errCode) { 1048 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 1049 return; 1050 } 1051 console.info('Succeeded in destroying the window.'); 1052}); 1053``` 1054 1055### destroyWindow<sup>9+</sup> 1056 1057destroyWindow(): Promise<void> 1058 1059Destroys this window. This API uses a promise to return the result. 1060 1061**System capability**: SystemCapability.WindowManager.WindowManager.Core 1062 1063**Return value** 1064 1065| Type| Description| 1066| ------------------- | ------------------------ | 1067| Promise<void> | Promise that returns no value.| 1068 1069**Error codes** 1070 1071For details about the error codes, see [Window Error Codes](errorcode-window.md). 1072 1073| ID| Error Message| 1074| ------- | -------------------------------------------- | 1075| 1300002 | This window state is abnormal. | 1076| 1300003 | This window manager service works abnormally. | 1077 1078**Example** 1079 1080```ts 1081import { BusinessError } from '@ohos.base'; 1082 1083let promise = windowClass.destroyWindow(); 1084promise.then(() => { 1085 console.info('Succeeded in destroying the window.'); 1086}).catch((err: BusinessError) => { 1087 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 1088}); 1089``` 1090 1091### moveWindowTo<sup>9+</sup> 1092 1093moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1094 1095Moves this window. This API uses an asynchronous callback to return the result. 1096 1097This operation is not supported in a window in full-screen mode. 1098 1099**System capability**: SystemCapability.WindowManager.WindowManager.Core 1100 1101**Parameters** 1102 1103| Name| Type| Mandatory| Description| 1104| -------- | ------------------------- | -- | --------------------------------------------- | 1105| 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.| 1106| 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.| 1107| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 1108 1109**Error codes** 1110 1111For details about the error codes, see [Window Error Codes](errorcode-window.md). 1112 1113| ID| Error Message| 1114| ------- | -------------------------------------------- | 1115| 1300002 | This window state is abnormal. | 1116| 1300003 | This window manager service works abnormally. | 1117 1118**Example** 1119 1120```ts 1121import { BusinessError } from '@ohos.base'; 1122 1123try { 1124 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 1125 const errCode: number = err.code; 1126 if (errCode) { 1127 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 1128 return; 1129 } 1130 console.info('Succeeded in moving the window.'); 1131 }); 1132} catch (exception) { 1133 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 1134} 1135``` 1136 1137### moveWindowTo<sup>9+</sup> 1138 1139moveWindowTo(x: number, y: number): Promise<void> 1140 1141Moves this window. This API uses a promise to return the result. 1142 1143This operation is not supported in a window in full-screen mode. 1144 1145**System capability**: SystemCapability.WindowManager.WindowManager.Core 1146 1147**Parameters** 1148 1149| Name| Type| Mandatory| Description| 1150| -- | ----- | -- | --------------------------------------------- | 1151| 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.| 1152| 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.| 1153 1154**Return value** 1155 1156| Type| Description| 1157| ------------------- | ------------------------ | 1158| Promise<void> | Promise that returns no value.| 1159 1160**Error codes** 1161 1162For details about the error codes, see [Window Error Codes](errorcode-window.md). 1163 1164| ID| Error Message| 1165| ------- | -------------------------------------------- | 1166| 1300002 | This window state is abnormal. | 1167| 1300003 | This window manager service works abnormally. | 1168 1169**Example** 1170 1171```ts 1172import { BusinessError } from '@ohos.base'; 1173 1174try { 1175 let promise = windowClass.moveWindowTo(300, 300); 1176 promise.then(() => { 1177 console.info('Succeeded in moving the window.'); 1178 }).catch((err: BusinessError) => { 1179 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 1180 }); 1181} catch (exception) { 1182 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 1183} 1184``` 1185 1186### resize<sup>9+</sup> 1187 1188resize(width: number, height: number, callback: AsyncCallback<void>): void 1189 1190Changes the size of this window. This API uses an asynchronous callback to return the result. 1191 1192The main window and subwindow have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 1193 1194The minimum width and height of the main window and subwindow of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 1195 1196The system window has the following size limits: [0, 1920] in width and [0, 1920] in height, both in units of vp. 1197 1198The window width and height you set must meet the limits. The rules are as follows: 1199- 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. 1200- 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. 1201 1202This operation is not supported in a window in full-screen mode. 1203 1204**System capability**: SystemCapability.WindowManager.WindowManager.Core 1205 1206**Parameters** 1207 1208| Name| Type| Mandatory| Description| 1209| -------- | ------------------------- | -- | ------------------------ | 1210| width | number | Yes| New width of the window, in px. The value must be an integer. A negative value is invalid.| 1211| height | number | Yes| New height of the window, in px. The value must be an integer. A negative value is invalid.| 1212| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 1213 1214**Error codes** 1215 1216For details about the error codes, see [Window Error Codes](errorcode-window.md). 1217 1218| ID| Error Message| 1219| ------- | -------------------------------------------- | 1220| 1300002 | This window state is abnormal. | 1221| 1300003 | This window manager service works abnormally. | 1222 1223**Example** 1224 1225```ts 1226import { BusinessError } from '@ohos.base'; 1227 1228try { 1229 windowClass.resize(500, 1000, (err: BusinessError) => { 1230 const errCode: number = err.code; 1231 if (errCode) { 1232 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 1233 return; 1234 } 1235 console.info('Succeeded in changing the window size.'); 1236 }); 1237} catch (exception) { 1238 console.error('Failed to change the window size. Cause:' + JSON.stringify(exception)); 1239} 1240``` 1241 1242### resize<sup>9+</sup> 1243 1244resize(width: number, height: number): Promise<void> 1245 1246Changes the size of this window. This API uses a promise to return the result. 1247 1248The main window and subwindow have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 1249 1250The minimum width and height of the main window and subwindow of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 1251 1252The system window has the following size limits: [0, 1920] in width and [0, 1920] in height, both in units of vp. 1253 1254The window width and height you set must meet the limits. The rules are as follows: 1255- 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. 1256- 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. 1257 1258This operation is not supported in a window in full-screen mode. 1259 1260**System capability**: SystemCapability.WindowManager.WindowManager.Core 1261 1262**Parameters** 1263 1264| Name| Type| Mandatory| Description| 1265| ------ | ------ | -- | ------------------------ | 1266| width | number | Yes| New width of the window, in px. The value must be an integer. A negative value is invalid.| 1267| height | number | Yes| New height of the window, in px. The value must be an integer. A negative value is invalid.| 1268 1269**Return value** 1270 1271| Type| Description| 1272| ------------------- | ------------------------ | 1273| Promise<void> | Promise that returns no value.| 1274 1275**Error codes** 1276 1277For details about the error codes, see [Window Error Codes](errorcode-window.md). 1278 1279| ID| Error Message| 1280| ------- | -------------------------------------------- | 1281| 1300002 | This window state is abnormal. | 1282| 1300003 | This window manager service works abnormally. | 1283 1284**Example** 1285 1286```ts 1287import { BusinessError } from '@ohos.base'; 1288 1289try { 1290 let promise = windowClass.resize(500, 1000); 1291 promise.then(() => { 1292 console.info('Succeeded in changing the window size.'); 1293 }).catch((err: BusinessError) => { 1294 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 1295 }); 1296} catch (exception) { 1297 console.error('Failed to change the window size. Cause: ' + JSON.stringify(exception)); 1298} 1299``` 1300 1301### getWindowProperties<sup>9+</sup> 1302 1303getWindowProperties(): WindowProperties 1304 1305Obtains the properties of this window. 1306 1307**System capability**: SystemCapability.WindowManager.WindowManager.Core 1308 1309**Return value** 1310 1311| Type| Description| 1312| ------------------------------------- | ------------- | 1313| [WindowProperties](#windowproperties) | Window properties obtained.| 1314 1315**Error codes** 1316 1317For details about the error codes, see [Window Error Codes](errorcode-window.md). 1318 1319| ID| Error Message| 1320| ------- | ------------------------------ | 1321| 1300002 | This window state is abnormal. | 1322 1323**Example** 1324 1325```ts 1326try { 1327 let properties = windowClass.getWindowProperties(); 1328} catch (exception) { 1329 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); 1330} 1331``` 1332 1333### getWindowAvoidArea<sup>9+</sup> 1334 1335getWindowAvoidArea(type: AvoidAreaType): AvoidArea 1336 1337Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. 1338 1339**System capability**: SystemCapability.WindowManager.WindowManager.Core 1340 1341**Parameters** 1342 1343| Name| Type| Mandatory| Description| 1344| ---- |----------------------------------| -- | ------------------------------------------------------------ | 1345| type | [AvoidAreaType](#avoidareatype7) | Yes| Type of the area.| 1346 1347**Return value** 1348 1349| Type| Description| 1350|--------------------------| ----------------- | 1351| [AvoidArea](#avoidarea7) | Area where the window cannot be displayed.| 1352 1353**Error codes** 1354 1355For details about the error codes, see [Window Error Codes](errorcode-window.md). 1356 1357| ID| Error Message| 1358| ------- | ------------------------------ | 1359| 1300002 | This window state is abnormal. | 1360 1361**Example** 1362 1363```ts 1364let type = window.AvoidAreaType.TYPE_SYSTEM; 1365try { 1366 let avoidArea = windowClass.getWindowAvoidArea(type); 1367} catch (exception) { 1368 console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception)); 1369} 1370``` 1371 1372### setWindowLayoutFullScreen<sup>9+</sup> 1373 1374setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 1375 1376Sets whether the window layout is immersive. This API uses an asynchronous callback to return the result. 1377An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 1378A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 1379 1380**System capability**: SystemCapability.WindowManager.WindowManager.Core 1381 1382**Parameters** 1383 1384| Name| Type| Mandatory| Description| 1385| ------------------ | ------------------------- | -- | --------- | 1386| 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.| 1387| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1388 1389**Error codes** 1390 1391For details about the error codes, see [Window Error Codes](errorcode-window.md). 1392 1393| ID| Error Message| 1394| ------- | -------------------------------------------- | 1395| 1300002 | This window state is abnormal. | 1396| 1300003 | This window manager service works abnormally. | 1397 1398**Example** 1399 1400```ts 1401import { BusinessError } from '@ohos.base'; 1402 1403let isLayoutFullScreen = true; 1404try { 1405 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 1406 const errCode: number = err.code; 1407 if (errCode) { 1408 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 1409 return; 1410 } 1411 console.info('Succeeded in setting the window layout to full-screen mode.'); 1412 }); 1413} catch (exception) { 1414 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 1415} 1416``` 1417 1418### setWindowLayoutFullScreen<sup>9+</sup> 1419 1420setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 1421 1422Sets whether the window layout is immersive. This API uses a promise to return the result. 1423An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 1424A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 1425 1426**System capability**: SystemCapability.WindowManager.WindowManager.Core 1427 1428**Parameters** 1429 1430| Name| Type| Mandatory| Description| 1431| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 1432| 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.| 1433 1434**Return value** 1435 1436| Type| Description| 1437| ------------------- | ------------------------ | 1438| Promise<void> | Promise that returns no value.| 1439 1440**Error codes** 1441 1442For details about the error codes, see [Window Error Codes](errorcode-window.md). 1443 1444| ID| Error Message| 1445| ------- | -------------------------------------------- | 1446| 1300002 | This window state is abnormal. | 1447| 1300003 | This window manager service works abnormally. | 1448 1449**Example** 1450 1451```ts 1452import { BusinessError } from '@ohos.base'; 1453 1454let isLayoutFullScreen = true; 1455try { 1456 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 1457 promise.then(() => { 1458 console.info('Succeeded in setting the window layout to full-screen mode.'); 1459 }).catch((err: BusinessError) => { 1460 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 1461 }); 1462} catch (exception) { 1463 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 1464} 1465``` 1466 1467### setWindowSystemBarEnable<sup>9+</sup> 1468 1469setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 1470 1471Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 1472 1473**System capability**: SystemCapability.WindowManager.WindowManager.Core 1474 1475**Parameters** 1476 1477| Name| Type| Mandatory| Description| 1478| -------- | ---------------------------- | -- | --------- | 1479| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 1480| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1481 1482**Error codes** 1483 1484For details about the error codes, see [Window Error Codes](errorcode-window.md). 1485 1486| ID| Error Message| 1487| ------- | -------------------------------------------- | 1488| 1300002 | This window state is abnormal. | 1489| 1300003 | This window manager service works abnormally. | 1490 1491**Example** 1492 1493```ts 1494// In this example, the status bar and navigation bar are not displayed. 1495import { BusinessError } from '@ohos.base'; 1496 1497let names: Array<'status' | 'navigation'> = []; 1498try { 1499 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 1500 const errCode: number = err.code; 1501 if (errCode) { 1502 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 1503 return; 1504 } 1505 console.info('Succeeded in setting the system bar to be invisible.'); 1506 }); 1507} catch (exception) { 1508 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 1509} 1510``` 1511 1512### setWindowSystemBarEnable<sup>9+</sup> 1513 1514setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 1515 1516Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 1517 1518**System capability**: SystemCapability.WindowManager.WindowManager.Core 1519 1520**Parameters** 1521 1522| Name| Type | Mandatory| Description| 1523| ----- | ---------------------------- | -- | --------------------------------- | 1524| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 1525 1526**Return value** 1527 1528| Type| Description| 1529| ------------------- | ------------------------ | 1530| Promise<void> | Promise that returns no value.| 1531 1532**Error codes** 1533 1534For details about the error codes, see [Window Error Codes](errorcode-window.md). 1535 1536| ID| Error Message| 1537| ------- | -------------------------------------------- | 1538| 1300002 | This window state is abnormal. | 1539| 1300003 | This window manager service works abnormally. | 1540 1541**Example** 1542 1543```ts 1544// In this example, the status bar and navigation bar are not displayed. 1545import { BusinessError } from '@ohos.base'; 1546 1547let names: Array<'status' | 'navigation'> = []; 1548try { 1549 let promise = windowClass.setWindowSystemBarEnable(names); 1550 promise.then(() => { 1551 console.info('Succeeded in setting the system bar to be invisible.'); 1552 }).catch((err: BusinessError) => { 1553 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 1554 }); 1555} catch (exception) { 1556 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 1557} 1558``` 1559 1560### setSpecificSystemBarEnabled<sup>11+</sup> 1561 1562setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean): Promise<void> 1563 1564Sets whether to show the navigation bar, status bar, or bottom navigation bar in full-screen mode. This API uses a promise to return the result. 1565 1566**System capability**: SystemCapability.Window.SessionManager 1567 1568**Parameters** 1569 1570| Name| Type | Mandatory| Description| 1571| ----- | ---------------------------- | -- | --------------------------------- | 1572| name | [SpecificSystemBar](#specificsystembar11) | Yes| Type of the system bar to be shown or hidden.| 1573| enable | boolean | Yes| Whether to show the status bar, navigation bar, or bottom navigation bar. The value **true** means to show them, and **false** means to hide them.| 1574 1575**Return value** 1576 1577| Type| Description| 1578| ------------------- | ------------------------ | 1579| Promise<void> | Promise that returns no value.| 1580 1581**Error codes** 1582 1583For details about the error codes, see [Window Error Codes](errorcode-window.md). 1584 1585| ID| Error Message| 1586| ------- | -------------------------------------------- | 1587| 1300002 | This window state is abnormal. | 1588| 1300003 | This window manager service works abnormally. | 1589 1590**Example** 1591 1592```ts 1593// Hide the bottom navigation bar. 1594import { BusinessError } from '@ohos.base'; 1595 1596try { 1597 let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); 1598 promise.then(() => { 1599 console.info('Succeeded in setting the system bar to be invisible.'); 1600 }).catch((err: BusinessError) => { 1601 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 1602 }); 1603} catch (exception) { 1604 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 1605} 1606``` 1607 1608### setWindowSystemBarProperties<sup>9+</sup> 1609 1610setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 1611 1612Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 1613 1614**System capability**: SystemCapability.WindowManager.WindowManager.Core 1615 1616**Parameters** 1617 1618| Name | Type | Mandatory| Description | 1619| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1620| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 1621| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1622 1623**Error codes** 1624 1625For details about the error codes, see [Window Error Codes](errorcode-window.md). 1626 1627| ID| Error Message| 1628| ------- | -------------------------------------------- | 1629| 1300002 | This window state is abnormal. | 1630| 1300003 | This window manager service works abnormally. | 1631 1632**Example** 1633 1634```ts 1635import { BusinessError } from '@ohos.base'; 1636 1637let SystemBarProperties: window.SystemBarProperties = { 1638 statusBarColor: '#ff00ff', 1639 navigationBarColor: '#00ff00', 1640 // The following properties are supported since API version 8. 1641 statusBarContentColor: '#ffffff', 1642 navigationBarContentColor: '#00ffff' 1643}; 1644try { 1645 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 1646 const errCode: number = err.code; 1647 if (errCode) { 1648 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 1649 return; 1650 } 1651 console.info('Succeeded in setting the system bar properties.'); 1652 }); 1653} catch (exception) { 1654 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 1655} 1656``` 1657 1658### setWindowSystemBarProperties<sup>9+</sup> 1659 1660setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 1661 1662Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 1663 1664**System capability**: SystemCapability.WindowManager.WindowManager.Core 1665 1666**Parameters** 1667 1668| Name | Type | Mandatory| Description | 1669| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1670| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 1671 1672**Return value** 1673 1674| Type | Description | 1675| ------------------- | ------------------------- | 1676| Promise<void> | Promise that returns no value.| 1677 1678**Error codes** 1679 1680For details about the error codes, see [Window Error Codes](errorcode-window.md). 1681 1682| ID| Error Message| 1683| ------- | -------------------------------------------- | 1684| 1300002 | This window state is abnormal. | 1685| 1300003 | This window manager service works abnormally. | 1686 1687**Example** 1688 1689```ts 1690import { BusinessError } from '@ohos.base'; 1691 1692let SystemBarProperties: window.SystemBarProperties = { 1693 statusBarColor: '#ff00ff', 1694 navigationBarColor: '#00ff00', 1695 // The following properties are supported since API version 8. 1696 statusBarContentColor: '#ffffff', 1697 navigationBarContentColor: '#00ffff' 1698}; 1699try { 1700 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 1701 promise.then(() => { 1702 console.info('Succeeded in setting the system bar properties.'); 1703 }).catch((err: BusinessError) => { 1704 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 1705 }); 1706} catch (exception) { 1707 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 1708} 1709``` 1710 1711### setPreferredOrientation<sup>9+</sup> 1712 1713setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 1714 1715Sets the preferred orientation for this window. This API uses an asynchronous callback to return the result. 1716 1717**System capability**: SystemCapability.WindowManager.WindowManager.Core 1718 1719**Parameters** 1720 1721| Name | Type | Mandatory| Description | 1722| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1723| Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 1724| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1725 1726**Error codes** 1727 1728For details about the error codes, see [Window Error Codes](errorcode-window.md). 1729 1730| ID| Error Message| 1731| ------- | ------------------------------ | 1732| 1300002 | This window state is abnormal. | 1733 1734**Example** 1735 1736```ts 1737import { BusinessError } from '@ohos.base'; 1738 1739let orientation = window.Orientation.AUTO_ROTATION; 1740try { 1741 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 1742 const errCode: number = err.code; 1743 if (errCode) { 1744 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); 1745 return; 1746 } 1747 console.info('Succeeded in setting window orientation.'); 1748 }); 1749} catch (exception) { 1750 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 1751} 1752``` 1753 1754### setPreferredOrientation<sup>9+</sup> 1755 1756setPreferredOrientation(orientation: Orientation): Promise<void> 1757 1758Sets the preferred orientation for this window. This API uses a promise to return the result. 1759 1760**System capability**: SystemCapability.WindowManager.WindowManager.Core 1761 1762**Parameters** 1763 1764| Name | Type | Mandatory| Description | 1765| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1766| Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 1767 1768**Return value** 1769 1770| Type | Description | 1771| ------------------- | ------------------------- | 1772| Promise<void> | Promise that returns no value.| 1773 1774**Error codes** 1775 1776For details about the error codes, see [Window Error Codes](errorcode-window.md). 1777 1778| ID| Error Message| 1779| ------- | ------------------------------ | 1780| 1300002 | This window state is abnormal. | 1781 1782**Example** 1783 1784```ts 1785import { BusinessError } from '@ohos.base'; 1786 1787let orientation = window.Orientation.AUTO_ROTATION; 1788try { 1789 let promise = windowClass.setPreferredOrientation(orientation); 1790 promise.then(() => { 1791 console.info('Succeeded in setting the window orientation.'); 1792 }).catch((err: BusinessError) => { 1793 console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); 1794 }); 1795} catch (exception) { 1796 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 1797} 1798``` 1799 1800### getUIContext<sup>10+</sup> 1801 1802getUIContext(): UIContext 1803 1804Obtain a **UIContext** instance. 1805 1806**Model restriction**: This API can be used only in the stage model. 1807 1808**System capability**: SystemCapability.WindowManager.WindowManager.Core 1809 1810**Return value** 1811 1812| Type | Description | 1813| ---------- | ---------------------- | 1814| [UIContext](js-apis-arkui-UIContext.md#uicontext) | **UIContext** instance obtained.| 1815 1816**Error codes** 1817 1818For details about the error codes, see [Window Error Codes](errorcode-window.md). 1819 1820| ID| Error Message| 1821| ------- | ------------------------------ | 1822| 1300002 | This window state is abnormal. | 1823 1824**Example** 1825 1826```ts 1827import UIAbility from '@ohos.app.ability.UIAbility'; 1828import window from '@ohos.window'; 1829import { BusinessError } from '@ohos.base'; 1830import { UIContext } from '@ohos.arkui.UIContext'; 1831 1832export default class EntryAbility extends UIAbility { 1833 onWindowStageCreate(windowStage: window.WindowStage) { 1834 // Load content for the main window. 1835 windowStage.loadContent("pages/page2", (err: BusinessError) => { 1836 let errCode: number = err.code; 1837 if (errCode) { 1838 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 1839 return; 1840 } 1841 console.info('Succeeded in loading the content.'); 1842 // Obtain the main window. 1843 let windowClass: window.Window | undefined = undefined; 1844 windowStage.getMainWindow((err: BusinessError, data) => { 1845 let errCode: number = err.code; 1846 if (errCode) { 1847 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 1848 return; 1849 } 1850 windowClass = data; 1851 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 1852 // Obtain a UIContext instance. 1853 let uiContext: UIContext | null = null; 1854 uiContext = windowClass.getUIContext(); 1855 }) 1856 }); 1857 } 1858}; 1859``` 1860 1861### setUIContent<sup>9+</sup> 1862 1863setUIContent(path: string, callback: AsyncCallback<void>): void 1864 1865Loads 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. 1866 1867**System capability**: SystemCapability.WindowManager.WindowManager.Core 1868 1869**Parameters** 1870 1871| Name| Type| Mandatory| Description| 1872| -------- | ------------------------- | -- | -------------------- | 1873| 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.| 1874| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 1875 1876**Error codes** 1877 1878For details about the error codes, see [Window Error Codes](errorcode-window.md). 1879 1880| ID| Error Message| 1881| ------- | -------------------------------------------- | 1882| 1300002 | This window state is abnormal. | 1883| 1300003 | This window manager service works abnormally. | 1884 1885**Example** 1886 1887```ts 1888import { BusinessError } from '@ohos.base'; 1889 1890try { 1891 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 1892 const errCode: number = err.code; 1893 if (errCode) { 1894 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 1895 return; 1896 } 1897 console.info('Succeeded in loading the content.'); 1898 }); 1899} catch (exception) { 1900 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 1901} 1902``` 1903 1904### setUIContent<sup>9+</sup> 1905 1906setUIContent(path: string): Promise<void> 1907 1908Loads 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. 1909 1910**System capability**: SystemCapability.WindowManager.WindowManager.Core 1911 1912**Parameters** 1913 1914| Name| Type| Mandatory| Description| 1915| ---- | ------ | -- | ------------------ | 1916| 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.| 1917 1918**Return value** 1919 1920| Type| Description| 1921| ------------------- | ------------------------ | 1922| Promise<void> | Promise that returns no value.| 1923 1924**Error codes** 1925 1926For details about the error codes, see [Window Error Codes](errorcode-window.md). 1927 1928| ID| Error Message| 1929| ------- | -------------------------------------------- | 1930| 1300002 | This window state is abnormal. | 1931| 1300003 | This window manager service works abnormally. | 1932 1933**Example** 1934 1935```ts 1936import { BusinessError } from '@ohos.base'; 1937 1938try { 1939 let promise = windowClass.setUIContent('pages/page2/page3'); 1940 promise.then(() => { 1941 console.info('Succeeded in loading the content.'); 1942 }).catch((err: BusinessError) => { 1943 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 1944 }); 1945} catch (exception) { 1946 console.error('Failed to load the content. Cause: ' + JSON.stringify(exception)); 1947} 1948``` 1949 1950### loadContent<sup>9+</sup> 1951 1952loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 1953 1954Loads 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. 1955 1956**Model restriction**: This API can be used only in the stage model. 1957 1958**System capability**: SystemCapability.WindowManager.WindowManager.Core 1959 1960**Parameters** 1961 1962| Name | Type | Mandatory| Description | 1963| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 1964| 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.| 1965| 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.| 1966| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1967 1968**Error codes** 1969 1970For details about the error codes, see [Window Error Codes](errorcode-window.md). 1971 1972| ID| Error Message| 1973| ------- | -------------------------------------------- | 1974| 1300002 | This window state is abnormal. | 1975| 1300003 | This window manager service works abnormally. | 1976 1977**Example** 1978 1979```ts 1980import UIAbility from '@ohos.app.ability.UIAbility'; 1981import window from '@ohos.window'; 1982import { BusinessError } from '@ohos.base'; 1983 1984export default class EntryAbility extends UIAbility { 1985 // ... 1986 1987 onWindowStageCreate(windowStage: window.WindowStage) { 1988 console.info('onWindowStageCreate'); 1989 let storage: LocalStorage = new LocalStorage(); 1990 storage.setOrCreate('storageSimpleProp', 121); 1991 try { 1992 if (!windowClass) { 1993 console.info('Failed to load the content. Cause: windowClass is null'); 1994 } 1995 else { 1996 (windowClass as window.Window).loadContent('pages/page2', storage, (err: BusinessError) => { 1997 const errCode: number = err.code; 1998 if (errCode) { 1999 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2000 return; 2001 } 2002 console.info('Succeeded in loading the content.'); 2003 }); 2004 } 2005 } catch (exception) { 2006 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2007 } 2008 } 2009}; 2010``` 2011 2012### loadContent<sup>9+</sup> 2013 2014loadContent(path: string, storage: LocalStorage): Promise<void> 2015 2016Loads the content of a page, with its path in the current project specified, to this window, and transfers the status attribute to the page through a local storage. This API uses a promise to return the result. 2017 2018**Model restriction**: This API can be used only in the stage model. 2019 2020**System capability**: SystemCapability.WindowManager.WindowManager.Core 2021 2022**Parameters** 2023 2024| Name | Type | Mandatory| Description | 2025| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2026| 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.| 2027| 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.| 2028 2029**Return value** 2030 2031| Type | Description | 2032| ------------------- | ------------------------- | 2033| Promise<void> | Promise that returns no value.| 2034 2035**Error codes** 2036 2037For details about the error codes, see [Window Error Codes](errorcode-window.md). 2038 2039| ID| Error Message| 2040| ------- | -------------------------------------------- | 2041| 1300002 | This window state is abnormal. | 2042| 1300003 | This window manager service works abnormally. | 2043 2044**Example** 2045 2046```ts 2047import UIAbility from '@ohos.app.ability.UIAbility'; 2048import window from '@ohos.window'; 2049import { BusinessError } from '@ohos.base'; 2050 2051export default class EntryAbility extends UIAbility { 2052 // ... 2053 2054 onWindowStageCreate(windowStage: window.WindowStage) { 2055 console.info('onWindowStageCreate'); 2056 let storage: LocalStorage = new LocalStorage(); 2057 storage.setOrCreate('storageSimpleProp', 121); 2058 try { 2059 if (!windowClass) { 2060 console.info('Failed to load the content. Cause: windowClass is null'); 2061 } 2062 else { 2063 let promise = (windowClass as window.Window).loadContent('pages/page2', storage); 2064 promise.then(() => { 2065 console.info('Succeeded in loading the content.'); 2066 }).catch((err: BusinessError) => { 2067 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2068 }); 2069 } 2070 } catch (exception) { 2071 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2072 } 2073 } 2074}; 2075``` 2076 2077### loadContentByName<sup>11+</sup> 2078 2079loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2080 2081Loads 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. 2082 2083**Model restriction**: This API can be used only in the stage model. 2084 2085**System capability**: SystemCapability.WindowManager.WindowManager.Core 2086 2087**Parameters** 2088 2089| Name | Type | Mandatory| Description | 2090| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2091| name | string | Yes | Name of the named route page. | 2092| 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.| 2093| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2094 2095**Error codes** 2096 2097For details about the error codes, see [Window Error Codes](errorcode-window.md). 2098 2099| ID| Error Message | 2100| -------- | --------------------------------------------- | 2101| 1300002 | This window state is abnormal. | 2102| 1300003 | This window manager service works abnormally. | 2103 2104**Example** 2105 2106```ts 2107// ets/entryability/EntryAbility.ets 2108import UIAbility from '@ohos.app.ability.UIAbility'; 2109import window from '@ohos.window'; 2110import { BusinessError } from '@ohos.base'; 2111import * as Index from '../pages/Index'; // Import the named route page. 2112 2113export default class EntryAbility extends UIAbility { 2114 // ... 2115 2116 onWindowStageCreate(windowStage: window.WindowStage) { 2117 console.info('onWindowStageCreate'); 2118 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 2119 let storage: LocalStorage = new LocalStorage(); 2120 storage.setOrCreate('storageSimpleProp', 121); 2121 try { 2122 if (!windowClass) { 2123 console.info('Failed to load the content. Cause: windowClass is null'); 2124 } else { 2125 (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => { 2126 const errCode: number = err.code; 2127 if (errCode) { 2128 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2129 return; 2130 } 2131 console.info('Succeeded in loading the content.'); 2132 }); 2133 } 2134 } catch (exception) { 2135 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2136 } 2137 } 2138}; 2139``` 2140```ts 2141// ets/pages/Index.ets 2142export const entryName : string = 'Index'; 2143@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 2144@Component 2145export struct Index { 2146 @State message: string = 'Hello World' 2147 build() { 2148 Row() { 2149 Column() { 2150 Text(this.message) 2151 .fontSize(50) 2152 .fontWeight(FontWeight.Bold) 2153 } 2154 .width('100%') 2155 } 2156 .height('100%') 2157 } 2158} 2159``` 2160 2161### loadContentByName<sup>11+</sup> 2162 2163loadContentByName(name: string, callback: AsyncCallback<void>): void 2164 2165Loads 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. 2166 2167**Model restriction**: This API can be used only in the stage model. 2168 2169**System capability**: SystemCapability.WindowManager.WindowManager.Core 2170 2171**Parameters** 2172 2173| Name | Type | Mandatory| Description | 2174| -------- | ------------------------- | ---- | ---------------- | 2175| name | string | Yes | Name of the named route page.| 2176| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2177 2178**Error codes** 2179 2180For details about the error codes, see [Window Error Codes](errorcode-window.md). 2181 2182| ID| Error Message | 2183| -------- | --------------------------------------------- | 2184| 1300002 | This window state is abnormal. | 2185| 1300003 | This window manager service works abnormally. | 2186 2187**Example** 2188 2189```ts 2190// ets/entryability/EntryAbility.ets 2191import UIAbility from '@ohos.app.ability.UIAbility'; 2192import window from '@ohos.window'; 2193import { BusinessError } from '@ohos.base'; 2194import * as Index from '../pages/Index'; // Import the named route page. 2195 2196export default class EntryAbility extends UIAbility { 2197 // ... 2198 2199 onWindowStageCreate(windowStage: window.WindowStage) { 2200 console.info('onWindowStageCreate'); 2201 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 2202 try { 2203 if (!windowClass) { 2204 console.info('Failed to load the content. Cause: windowClass is null'); 2205 } else { 2206 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 2207 const errCode: number = err.code; 2208 if (errCode) { 2209 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2210 return; 2211 } 2212 console.info('Succeeded in loading the content.'); 2213 }); 2214 } 2215 } catch (exception) { 2216 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2217 } 2218 } 2219}; 2220``` 2221```ts 2222// ets/pages/Index.ets 2223export const entryName : string = 'Index'; 2224@Entry({routeName: entryName}) 2225@Component 2226export struct Index { 2227 @State message: string = 'Hello World' 2228 build() { 2229 Row() { 2230 Column() { 2231 Text(this.message) 2232 .fontSize(50) 2233 .fontWeight(FontWeight.Bold) 2234 } 2235 .width('100%') 2236 } 2237 .height('100%') 2238 } 2239} 2240``` 2241 2242### loadContentByName<sup>11+</sup> 2243 2244loadContentByName(name: string, storage?: LocalStorage): Promise<void> 2245 2246Loads 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. 2247 2248**Model restriction**: This API can be used only in the stage model. 2249 2250**System capability**: SystemCapability.WindowManager.WindowManager.Core 2251 2252**Parameters** 2253 2254| Name | Type | Mandatory| Description | 2255| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2256| name | string | Yes | Name of the named route page. | 2257| 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.| 2258 2259**Return value** 2260 2261| Type | Description | 2262| ------------------- | ------------------------- | 2263| Promise<void> | Promise that returns no value.| 2264 2265**Error codes** 2266 2267For details about the error codes, see [Window Error Codes](errorcode-window.md). 2268 2269| ID| Error Message | 2270| -------- | --------------------------------------------- | 2271| 1300002 | This window state is abnormal. | 2272| 1300003 | This window manager service works abnormally. | 2273 2274**Example** 2275 2276```ts 2277// ets/entryability/EntryAbility.ets 2278import UIAbility from '@ohos.app.ability.UIAbility'; 2279import window from '@ohos.window'; 2280import { BusinessError } from '@ohos.base'; 2281import * as Index from '../pages/Index'; // Import the named route page. 2282 2283export default class EntryAbility extends UIAbility { 2284 // ... 2285 2286 onWindowStageCreate(windowStage: window.WindowStage) { 2287 console.info('onWindowStageCreate'); 2288 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 2289 let storage: LocalStorage = new LocalStorage(); 2290 storage.setOrCreate('storageSimpleProp', 121); 2291 try { 2292 if (!windowClass) { 2293 console.info('Failed to load the content. Cause: windowClass is null'); 2294 } else { 2295 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 2296 promise.then(() => { 2297 console.info('Succeeded in loading the content.'); 2298 }).catch((err: BusinessError) => { 2299 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2300 }); 2301 } 2302 } catch (exception) { 2303 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2304 } 2305 } 2306}; 2307``` 2308```ts 2309// ets/pages/Index.ets 2310export const entryName : string = 'Index'; 2311@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 2312@Component 2313export struct Index { 2314 @State message: string = 'Hello World' 2315 build() { 2316 Row() { 2317 Column() { 2318 Text(this.message) 2319 .fontSize(50) 2320 .fontWeight(FontWeight.Bold) 2321 } 2322 .width('100%') 2323 } 2324 .height('100%') 2325 } 2326} 2327``` 2328 2329### isWindowShowing<sup>9+</sup> 2330 2331isWindowShowing(): boolean 2332 2333Checks whether this window is displayed. 2334 2335**System capability**: SystemCapability.WindowManager.WindowManager.Core 2336 2337**Return value** 2338 2339| Type| Description| 2340| ------- | ------------------------------------------------------------------ | 2341| boolean | Whether the window is displayed. The value **true** means that the window is displayed, and **false** means the opposite.| 2342 2343**Error codes** 2344 2345For details about the error codes, see [Window Error Codes](errorcode-window.md). 2346 2347| ID| Error Message| 2348| ------- | ------------------------------ | 2349| 1300002 | This window state is abnormal. | 2350 2351**Example** 2352 2353```ts 2354try { 2355 let data = windowClass.isWindowShowing(); 2356 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 2357} catch (exception) { 2358 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(exception)); 2359} 2360``` 2361 2362### on('windowSizeChange')<sup>7+</sup> 2363 2364on(type: 'windowSizeChange', callback: Callback<Size>): void 2365 2366Subscribes to the window size change event. 2367 2368**System capability**: SystemCapability.WindowManager.WindowManager.Core 2369 2370**Parameters** 2371 2372| Name | Type | Mandatory| Description | 2373| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 2374| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 2375| callback | Callback<[Size](#size7)> | Yes | Callback used to return the window size. | 2376 2377**Example** 2378 2379```ts 2380try { 2381 windowClass.on('windowSizeChange', (data) => { 2382 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 2383 }); 2384} catch (exception) { 2385 console.error('Failed to enable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 2386} 2387``` 2388 2389### off('windowSizeChange')<sup>7+</sup> 2390 2391off(type: 'windowSizeChange', callback?: Callback<Size>): void 2392 2393Unsubscribes from the window size change event. 2394 2395**System capability**: SystemCapability.WindowManager.WindowManager.Core 2396 2397**Parameters** 2398 2399| Name | Type | Mandatory| Description | 2400| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 2401| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 2402| 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. | 2403 2404**Example** 2405 2406```ts 2407try { 2408 windowClass.off('windowSizeChange'); 2409} catch (exception) { 2410 console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 2411} 2412``` 2413 2414### on('avoidAreaChange')<sup>9+</sup> 2415 2416on(type: 'avoidAreaChange', callback: Callback<{ type: AvoidAreaType, area: AvoidArea}>): void 2417 2418Subscribes to the event indicating changes to the area where the window cannot be displayed. 2419 2420**System capability**: SystemCapability.WindowManager.WindowManager.Core 2421 2422**Parameters** 2423 2424| Name | Type | Mandatory| Description | 2425| -------- |------------------------------------------------------------------| ---- |--------------------------------------| 2426| 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.| 2427| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | Yes | Callback used to return the area and area type.| 2428 2429**Example** 2430 2431```ts 2432try { 2433 windowClass.on('avoidAreaChange', (data) => { 2434 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 2435 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 2436 }); 2437} catch (exception) { 2438 console.error('Failed to enable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 2439} 2440``` 2441 2442### off('avoidAreaChange')<sup>9+</sup> 2443 2444off(type: 'avoidAreaChange', callback?: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void 2445 2446Unsubscribes from the event indicating changes to the area where the window cannot be displayed. 2447 2448**System capability**: SystemCapability.WindowManager.WindowManager.Core 2449 2450**Parameters** 2451 2452| Name | Type | Mandatory | Description | 2453| -------- |-----------------------------------------------------------------------------|-----|------------------------------------| 2454| 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.| 2455| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | 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.| 2456 2457**Example** 2458 2459```ts 2460try { 2461 windowClass.off('avoidAreaChange'); 2462} catch (exception) { 2463 console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 2464} 2465``` 2466 2467### on('keyboardHeightChange')<sup>7+</sup> 2468 2469on(type: 'keyboardHeightChange', callback: Callback<number>): void 2470 2471Subscribes to the event indicating soft keyboard height changes in the input method panel in fixed state. Since API version 10, the input method panel can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 2472 2473**System capability**: SystemCapability.WindowManager.WindowManager.Core 2474 2475**Parameters** 2476 2477| Name | Type | Mandatory| Description | 2478| -------- | ------------------- | ---- |-------------------------------------------| 2479| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 2480| callback | Callback<number> | Yes | Callback used to return the current keyboard height, which is an integer, in px. | 2481 2482**Example** 2483 2484```ts 2485try { 2486 windowClass.on('keyboardHeightChange', (data) => { 2487 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 2488 }); 2489} catch (exception) { 2490 console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 2491} 2492``` 2493 2494### off('keyboardHeightChange')<sup>7+</sup> 2495 2496off(type: 'keyboardHeightChange', callback?: Callback<number>): void 2497 2498Unsubscribes from the event indicating soft keyboard height changes in the input method panel in fixed state. Since API version 10, the input method panel can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 2499 2500**System capability**: SystemCapability.WindowManager.WindowManager.Core 2501 2502**Parameters** 2503 2504| Name | Type | Mandatory| Description | 2505| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2506| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 2507| 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. | 2508 2509**Example** 2510 2511```ts 2512try { 2513 windowClass.off('keyboardHeightChange'); 2514} catch (exception) { 2515 console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 2516} 2517``` 2518 2519### on('touchOutside')<sup>11+</sup> 2520 2521on(type: 'touchOutside', callback: Callback<void>): void 2522 2523Subscribes to the click event outside this window. 2524 2525**System capability**: SystemCapability.WindowManager.WindowManager.Core 2526 2527**Parameters** 2528 2529| Name | Type | Mandatory| Description | 2530| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2531| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the click event outside this window.| 2532| callback | Callback<void> | Yes | Callback used to return the click event outside this window. | 2533 2534**Example** 2535 2536```ts 2537try { 2538 windowClass.on('touchOutside', () => { 2539 console.info('touch outside'); 2540 }); 2541} catch (exception) { 2542 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2543} 2544``` 2545 2546### off('touchOutside')<sup>11+</sup> 2547 2548off(type: 'touchOutside', callback?: Callback<void>): void 2549 2550Unsubscribes from the click event outside this window. 2551 2552**System capability**: SystemCapability.WindowManager.WindowManager.Core 2553 2554**Parameters** 2555 2556| Name | Type | Mandatory| Description | 2557| -------- |----------------------| ---- |--------------------------------------| 2558| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the click event outside this window.| 2559| callback | Callback<void> | No | Callback used to return the click 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. | 2560 2561**Example** 2562 2563```ts 2564try { 2565 windowClass.off('touchOutside'); 2566} catch (exception) { 2567 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2568} 2569``` 2570 2571### on('screenshot')<sup>9+</sup> 2572 2573on(type: 'screenshot', callback: Callback<void>): void 2574 2575Subscribes to the screenshot event. 2576 2577**System capability**: SystemCapability.WindowManager.WindowManager.Core 2578 2579**Parameters** 2580 2581| Name | Type | Mandatory| Description | 2582| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2583| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 2584| callback | Callback<void> | Yes | Callback invoked when a screenshot event occurs. | 2585 2586**Example** 2587 2588```ts 2589try { 2590 windowClass.on('screenshot', () => { 2591 console.info('screenshot happened'); 2592 }); 2593} catch (exception) { 2594 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2595} 2596``` 2597 2598### off('screenshot')<sup>9+</sup> 2599 2600off(type: 'screenshot', callback?: Callback<void>): void 2601 2602Unsubscribes from the screenshot event. 2603 2604**System capability**: SystemCapability.WindowManager.WindowManager.Core 2605 2606**Parameters** 2607 2608| Name | Type | Mandatory| Description | 2609| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2610| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 2611| 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.| 2612 2613**Example** 2614 2615```ts 2616let callback = () => { 2617 console.info('screenshot happened'); 2618}; 2619try { 2620 windowClass.on('screenshot', callback); 2621} catch (exception) { 2622 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2623} 2624try { 2625 windowClass.off('screenshot', callback); 2626 // If multiple callbacks are enabled in on(), they will all be disabled. 2627 windowClass.off('screenshot'); 2628} catch (exception) { 2629 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2630} 2631``` 2632 2633### on('dialogTargetTouch')<sup>10+</sup> 2634 2635on(type: 'dialogTargetTouch', callback: Callback<void>): void 2636 2637Subscribes to the click event of the target window in the modal window mode. 2638 2639**System capability**: SystemCapability.WindowManager.WindowManager.Core 2640 2641**Parameters** 2642 2643| Name | Type | Mandatory| Description | 2644| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2645| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| 2646| callback | Callback<void>| Yes | Callback invoked when the click event occurs in the target window of the modal window mode.| 2647 2648**Example** 2649 2650```ts 2651try { 2652 windowClass.on('dialogTargetTouch', () => { 2653 console.info('touch dialog target'); 2654 }); 2655} catch (exception) { 2656 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2657} 2658``` 2659 2660### off('dialogTargetTouch')<sup>10+</sup> 2661 2662off(type: 'dialogTargetTouch', callback?: Callback<void>): void 2663 2664Unsubscribes from the click event of the target window in the modal window mode. 2665 2666**System capability**: SystemCapability.WindowManager.WindowManager.Core 2667 2668**Parameters** 2669 2670| Name | Type | Mandatory| Description | 2671| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2672| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| 2673| callback | Callback<void> | No | Callback invoked when the click 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.| 2674 2675**Example** 2676 2677```ts 2678try { 2679 windowClass.off('dialogTargetTouch'); 2680} catch (exception) { 2681 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2682} 2683``` 2684 2685### on('windowEvent')<sup>10+</sup> 2686 2687on(type: 'windowEvent', callback: Callback<WindowEventType>): void 2688 2689Subscribes to the window lifecycle change event. 2690 2691**System capability**: SystemCapability.WindowManager.WindowManager.Core 2692 2693**Parameters** 2694 2695| Name | Type | Mandatory| Description | 2696| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2697| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 2698| callback | Callback<[WindowEventType](#windoweventtype10)> | Yes | Callback used to return the window lifecycle state. | 2699 2700**Example** 2701 2702```ts 2703try { 2704 windowClass.on('windowEvent', (data) => { 2705 console.info('Window event happened. Event:' + JSON.stringify(data)); 2706 }); 2707} catch (exception) { 2708 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2709} 2710``` 2711 2712### off('windowEvent')<sup>10+</sup> 2713 2714off(type: 'windowEvent', callback?: Callback<WindowEventType >): void 2715 2716Unsubscribes from the window lifecycle change event. 2717 2718**System capability**: SystemCapability.WindowManager.WindowManager.Core 2719 2720**Parameters** 2721 2722| Name | Type | Mandatory| Description | 2723| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2724| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 2725| 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. | 2726 2727**Example** 2728 2729```ts 2730try { 2731 windowClass.off('windowEvent'); 2732} catch (exception) { 2733 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2734} 2735``` 2736 2737### on('windowVisibilityChange')<sup>11+</sup> 2738 2739on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 2740 2741Subscribes to the visibility status change event of this window. 2742 2743**System capability**: SystemCapability.Window.SessionManager 2744 2745**Parameters** 2746 2747| Name | Type | Mandatory| Description | 2748| -------- | --------------------------| ---- | ------------------------------------------------------------ | 2749| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 2750| 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. | 2751 2752**Error codes** 2753 2754For details about the error codes, see [Window Error Codes](errorcode-window.md). 2755 2756| ID| Error Message| 2757| ------- | ------------------------------ | 2758| 1300002 | This window state is abnormal. | 2759| 1300003 | This window manager service works abnormally. | 2760 2761**Example** 2762 2763```ts 2764try { 2765 windowClass.on('windowVisibilityChange', (boolean) => { 2766 console.info('Window visibility changed, isVisible=' + boolean); 2767 }); 2768} catch (exception) { 2769 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2770} 2771``` 2772 2773### off('windowVisibilityChange')<sup>11+</sup> 2774 2775off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 2776 2777Unsubscribes from the visibility status change event of this window. 2778 2779**System capability**: SystemCapability.Window.SessionManager 2780 2781**Parameters** 2782 2783| Name | Type | Mandatory| Description | 2784| -------- |----------------------------| ---- |--------------------------------------| 2785| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 2786| 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. | 2787 2788**Error codes** 2789 2790For details about the error codes, see [Window Error Codes](errorcode-window.md). 2791 2792| ID| Error Message| 2793| ------- | ------------------------------ | 2794| 1300002 | This window state is abnormal. | 2795| 1300003 | This window manager service works abnormally. | 2796 2797**Example** 2798 2799```ts 2800try { 2801 windowClass.off('windowVisibilityChange'); 2802} catch (exception) { 2803 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2804} 2805``` 2806 2807### on('windowStatusChange')<sup>11+</sup> 2808 2809on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 2810 2811Subscribes to the window status change event. 2812 2813**System capability**: SystemCapability.Window.SessionManager 2814 2815**Parameters** 2816 2817| Name | Type | Mandatory| Description | 2818| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 2819| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 2820| callback | Callback<[WindowStatusType](#windowstatustype11)> | Yes | Callback used to return the window status. | 2821 2822**Example** 2823 2824```ts 2825try { 2826 windowClass.on('windowStatusChange', (WindowStatusType) => { 2827 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 2828 }); 2829} catch (exception) { 2830 console.error('Failed to enable the listener for window status changes. Cause: ' + JSON.stringify(exception)); 2831} 2832``` 2833 2834### off('windowStatusChange')<sup>11+</sup> 2835 2836off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 2837 2838Unsubscribes from the window status change event. 2839 2840**System capability**: SystemCapability.Window.SessionManager 2841 2842**Parameters** 2843 2844| Name | Type | Mandatory| Description | 2845| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 2846| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 2847| 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. | 2848 2849**Example** 2850 2851```ts 2852try { 2853 windowClass.off('windowStatusChange'); 2854} catch (exception) { 2855 console.error('Failed to disable the listener for window status changes. Cause: ' + JSON.stringify(exception)); 2856} 2857``` 2858 2859### on('windowTitleButtonRectChange')<sup>11+</sup> 2860 2861on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 2862 2863Subscribes to the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar. 2864 2865**System capability**: SystemCapability.Window.SessionManager 2866 2867**Parameters** 2868 2869| Name | Type | Mandatory| Description | 2870| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2871| 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.| 2872| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | Yes | Callback used to return the new rectangle.| 2873 2874**Error codes** 2875 2876For details about the error codes, see [Window Error Codes](errorcode-window.md). 2877 2878| ID| Error Message | 2879| -------- | ------------------------------ | 2880| 1300002 | This window state is abnormal. | 2881 2882**Example** 2883 2884```ts 2885try { 2886 windowClass.on('windowTitleButtonRectChange', (titleButtonRect) => { 2887 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 2888 }); 2889} catch (exception) { 2890 console.error('Failed to enable the listener for window title buttons area changes. Cause: ' + JSON.stringify(exception)); 2891} 2892``` 2893 2894### off('windowTitleButtonRectChange')<sup>11+</sup> 2895 2896off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 2897 2898Unsubscribes from the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar. 2899 2900**System capability**: SystemCapability.Window.SessionManager 2901 2902**Parameters** 2903 2904| Name | Type | Mandatory| Description | 2905| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2906| 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.| 2907| 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.| 2908 2909**Error codes** 2910 2911For details about the error codes, see [Window Error Codes](errorcode-window.md). 2912 2913| ID| Error Message | 2914| -------- | ------------------------------ | 2915| 1300002 | This window state is abnormal. | 2916 2917**Example** 2918 2919```ts 2920try { 2921 windowClass.off('windowTitleButtonRectChange'); 2922} catch (exception) { 2923 console.error('Failed to disable the listener for window title buttons area changes. Cause: ' + JSON.stringify(exception)); 2924} 2925``` 2926 2927### isWindowSupportWideGamut<sup>9+</sup> 2928 2929isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 2930 2931Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 2932 2933**System capability**: SystemCapability.WindowManager.WindowManager.Core 2934 2935**Parameters** 2936 2937| Name| Type| Mandatory| Description| 2938| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 2939| 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.| 2940 2941**Error codes** 2942 2943For details about the error codes, see [Window Error Codes](errorcode-window.md). 2944 2945| ID| Error Message| 2946| ------- | ------------------------------ | 2947| 1300002 | This window state is abnormal. | 2948 2949**Example** 2950 2951```ts 2952import { BusinessError } from '@ohos.base'; 2953 2954windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 2955 const errCode: number = err.code; 2956 if (errCode) { 2957 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 2958 return; 2959 } 2960 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 2961}); 2962``` 2963 2964### isWindowSupportWideGamut<sup>9+</sup> 2965 2966isWindowSupportWideGamut(): Promise<boolean> 2967 2968Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 2969 2970**System capability**: SystemCapability.WindowManager.WindowManager.Core 2971 2972**Return value** 2973 2974| Type| Description| 2975| ---------------------- | ------------------------------------------------------------------------------------ | 2976| 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.| 2977 2978**Error codes** 2979 2980For details about the error codes, see [Window Error Codes](errorcode-window.md). 2981 2982| ID| Error Message| 2983| ------- | ------------------------------ | 2984| 1300002 | This window state is abnormal. | 2985 2986**Example** 2987 2988```ts 2989import { BusinessError } from '@ohos.base'; 2990 2991let promise = windowClass.isWindowSupportWideGamut(); 2992promise.then((data) => { 2993 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 2994}).catch((err: BusinessError) => { 2995 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 2996}); 2997``` 2998 2999### setWindowColorSpace<sup>9+</sup> 3000 3001setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 3002 3003Sets a color space for this window. This API uses an asynchronous callback to return the result. 3004 3005**System capability**: SystemCapability.WindowManager.WindowManager.Core 3006 3007**Parameters** 3008 3009| Name| Type| Mandatory| Description| 3010| ---------- | ------------------------- | -- | ----------- | 3011| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 3012| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3013 3014**Error codes** 3015 3016For details about the error codes, see [Window Error Codes](errorcode-window.md). 3017 3018| ID| Error Message| 3019| ------- | ------------------------------ | 3020| 1300002 | This window state is abnormal. | 3021 3022**Example** 3023 3024```ts 3025import { BusinessError } from '@ohos.base'; 3026 3027try { 3028 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 3029 const errCode: number = err.code; 3030 if (errCode) { 3031 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 3032 return; 3033 } 3034 console.info('Succeeded in setting window colorspace.'); 3035 }); 3036} catch (exception) { 3037 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3038} 3039``` 3040 3041### setWindowColorSpace<sup>9+</sup> 3042 3043setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 3044 3045Sets a color space for this window. This API uses a promise to return the result. 3046 3047**System capability**: SystemCapability.WindowManager.WindowManager.Core 3048 3049**Parameters** 3050 3051| Name| Type| Mandatory| Description| 3052| ---------- | ------------------------- | -- | ------------- | 3053| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 3054 3055**Return value** 3056 3057| Type| Description| 3058| ------------------- | ------------------------ | 3059| Promise<void> | Promise that returns no value.| 3060 3061**Error codes** 3062 3063For details about the error codes, see [Window Error Codes](errorcode-window.md). 3064 3065| ID| Error Message| 3066| ------- | ------------------------------ | 3067| 1300002 | This window state is abnormal. | 3068 3069**Example** 3070 3071```ts 3072import { BusinessError } from '@ohos.base'; 3073 3074try { 3075 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 3076 promise.then(() => { 3077 console.info('Succeeded in setting window colorspace.'); 3078 }).catch((err: BusinessError) => { 3079 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 3080 }); 3081} catch (exception) { 3082 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3083} 3084``` 3085 3086### getWindowColorSpace<sup>9+</sup> 3087 3088getWindowColorSpace(): ColorSpace 3089 3090Obtains the color space of this window. 3091 3092**System capability**: SystemCapability.WindowManager.WindowManager.Core 3093 3094**Return value** 3095 3096| Type| Description| 3097| ------------------------- | ------------- | 3098| [ColorSpace](#colorspace8) | Color space obtained.| 3099 3100**Error codes** 3101 3102For details about the error codes, see [Window Error Codes](errorcode-window.md). 3103 3104| ID| Error Message| 3105| ------- | ------------------------------ | 3106| 1300002 | This window state is abnormal. | 3107 3108**Example** 3109 3110```ts 3111let colorSpace = windowClass.getWindowColorSpace(); 3112``` 3113 3114### setWindowBackgroundColor<sup>9+</sup> 3115 3116setWindowBackgroundColor(color: string): void 3117 3118Sets 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. 3119 3120**System capability**: SystemCapability.WindowManager.WindowManager.Core 3121 3122**Parameters** 3123 3124| Name| Type| Mandatory| Description| 3125| ----- | ------ | -- | ----------------------------------------------------------------------- | 3126| 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**.| 3127 3128**Error codes** 3129 3130For details about the error codes, see [Window Error Codes](errorcode-window.md). 3131 3132| ID| Error Message| 3133| ------- | ------------------------------ | 3134| 1300002 | This window state is abnormal. | 3135 3136**Example** 3137 3138```ts 3139import { BusinessError } from '@ohos.base'; 3140 3141private SetUIContent(windowClass: window.Window) { 3142 windowClass.setUIContent("pages/ButtonWindow",(err: BusinessError) => { 3143 if (err.code) { 3144 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 3145 return; 3146 } 3147 console.info('Succeeded in loading the content.'); 3148 let color: string = '#00ff33'; 3149 try { 3150 windowClass.setWindowBackgroundColor(color); 3151 } catch (exception) { 3152 console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception)); 3153 }; 3154 }); 3155} 3156``` 3157 3158### setWindowBrightness<sup>9+</sup> 3159 3160setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 3161 3162Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 3163 3164When 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. 3165 3166**System capability**: SystemCapability.WindowManager.WindowManager.Core 3167 3168**Parameters** 3169 3170| Name| Type| Mandatory| Description | 3171| ---------- | ------------------------- | -- |-------------------------------------------| 3172| 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.| 3173| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3174 3175**Error codes** 3176 3177For details about the error codes, see [Window Error Codes](errorcode-window.md). 3178 3179| ID| Error Message| 3180| ------- | -------------------------------------------- | 3181| 1300002 | This window state is abnormal. | 3182| 1300003 | This window manager service works abnormally. | 3183 3184**Example** 3185 3186```ts 3187import { BusinessError } from '@ohos.base'; 3188 3189let brightness: number = 1; 3190try { 3191 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 3192 const errCode: number = err.code; 3193 if (errCode) { 3194 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 3195 return; 3196 } 3197 console.info('Succeeded in setting the brightness.'); 3198 }); 3199} catch (exception) { 3200 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 3201} 3202``` 3203 3204### setWindowBrightness<sup>9+</sup> 3205 3206setWindowBrightness(brightness: number): Promise<void> 3207 3208Sets the screen brightness for this window. This API uses a promise to return the result. 3209 3210When 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. 3211 3212**System capability**: SystemCapability.WindowManager.WindowManager.Core 3213 3214**Parameters** 3215 3216| Name| Type| Mandatory| Description | 3217| ---------- | ------ | -- |----------------------------------------| 3218| 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.| 3219 3220**Return value** 3221 3222| Type| Description| 3223| ------------------- | ------------------------ | 3224| Promise<void> | Promise that returns no value.| 3225 3226**Error codes** 3227 3228For details about the error codes, see [Window Error Codes](errorcode-window.md). 3229 3230| ID| Error Message| 3231| ------- | -------------------------------------------- | 3232| 1300002 | This window state is abnormal. | 3233| 1300003 | This window manager service works abnormally. | 3234 3235**Example** 3236 3237```ts 3238import { BusinessError } from '@ohos.base'; 3239 3240let brightness: number = 1; 3241try { 3242 let promise = windowClass.setWindowBrightness(brightness); 3243 promise.then(() => { 3244 console.info('Succeeded in setting the brightness.'); 3245 }).catch((err: BusinessError) => { 3246 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 3247 }); 3248} catch (exception) { 3249 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 3250} 3251``` 3252 3253### setWindowFocusable<sup>9+</sup> 3254 3255setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 3256 3257Sets whether this window can gain focus. This API uses an asynchronous callback to return the result. 3258 3259**System capability**: SystemCapability.WindowManager.WindowManager.Core 3260 3261**Parameters** 3262 3263| Name| Type| Mandatory| Description| 3264| ----------- | ------------------------- | -- | ------------------------------------------------------- | 3265| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite.| 3266| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3267 3268**Error codes** 3269 3270For details about the error codes, see [Window Error Codes](errorcode-window.md). 3271 3272| ID| Error Message| 3273| ------- | -------------------------------------------- | 3274| 1300002 | This window state is abnormal. | 3275| 1300003 | This window manager service works abnormally. | 3276 3277**Example** 3278 3279```ts 3280import { BusinessError } from '@ohos.base'; 3281 3282let isFocusable: boolean = true; 3283try { 3284 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 3285 const errCode: number = err.code; 3286 if (errCode) { 3287 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 3288 return; 3289 } 3290 console.info('Succeeded in setting the window to be focusable.'); 3291 }); 3292} catch (exception) { 3293 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 3294} 3295``` 3296 3297### setWindowFocusable<sup>9+</sup> 3298 3299setWindowFocusable(isFocusable: boolean): Promise<void> 3300 3301Sets whether this window can gain focus. This API uses a promise to return the result. 3302 3303**System capability**: SystemCapability.WindowManager.WindowManager.Core 3304 3305**Parameters** 3306 3307| Name| Type| Mandatory| Description| 3308| ----------- | ------- | -- | -------------------------------------------------------- | 3309| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 3310 3311**Return value** 3312 3313| Type| Description| 3314| ------------------- | ------------------------ | 3315| Promise<void> | Promise that returns no value.| 3316 3317**Error codes** 3318 3319For details about the error codes, see [Window Error Codes](errorcode-window.md). 3320 3321| ID| Error Message| 3322| ------- | -------------------------------------------- | 3323| 1300002 | This window state is abnormal. | 3324| 1300003 | This window manager service works abnormally. | 3325 3326**Example** 3327 3328```ts 3329import { BusinessError } from '@ohos.base'; 3330 3331let isFocusable: boolean = true; 3332try { 3333 let promise = windowClass.setWindowFocusable(isFocusable); 3334 promise.then(() => { 3335 console.info('Succeeded in setting the window to be focusable.'); 3336 }).catch((err: BusinessError) => { 3337 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 3338 }); 3339} catch (exception) { 3340 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 3341} 3342``` 3343 3344### setWindowKeepScreenOn<sup>9+</sup> 3345 3346setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 3347 3348Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 3349 3350**System capability**: SystemCapability.WindowManager.WindowManager.Core 3351 3352**Parameters** 3353 3354| Name| Type| Mandatory| Description| 3355| -------------- | ------------------------- | -- | ---------------------------------------------------- | 3356| 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. | 3357| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3358 3359**Error codes** 3360 3361For details about the error codes, see [Window Error Codes](errorcode-window.md). 3362 3363| ID| Error Message| 3364| ------- | -------------------------------------------- | 3365| 1300002 | This window state is abnormal. | 3366| 1300003 | This window manager service works abnormally. | 3367 3368**Example** 3369 3370```ts 3371import { BusinessError } from '@ohos.base'; 3372 3373let isKeepScreenOn: boolean = true; 3374try { 3375 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 3376 const errCode: number = err.code; 3377 if (errCode) { 3378 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 3379 return; 3380 } 3381 console.info('Succeeded in setting the screen to be always on.'); 3382 }); 3383} catch (exception) { 3384 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 3385} 3386``` 3387 3388### setWindowKeepScreenOn<sup>9+</sup> 3389 3390setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 3391 3392Sets whether to keep the screen always on. This API uses a promise to return the result. 3393 3394**System capability**: SystemCapability.WindowManager.WindowManager.Core 3395 3396**Parameters** 3397 3398| Name| Type| Mandatory| Description| 3399| -------------- | ------- | -- | --------------------------------------------------- | 3400| 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.| 3401 3402**Return value** 3403 3404| Type| Description| 3405| ------------------- | ------------------------ | 3406| Promise<void> | Promise that returns no value.| 3407 3408**Error codes** 3409 3410For details about the error codes, see [Window Error Codes](errorcode-window.md). 3411 3412| ID| Error Message| 3413| ------- | -------------------------------------------- | 3414| 1300002 | This window state is abnormal. | 3415| 1300003 | This window manager service works abnormally. | 3416 3417**Example** 3418 3419```ts 3420import { BusinessError } from '@ohos.base'; 3421 3422let isKeepScreenOn: boolean = true; 3423try { 3424 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 3425 promise.then(() => { 3426 console.info('Succeeded in setting the screen to be always on.'); 3427 }).catch((err: BusinessError) => { 3428 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 3429 }); 3430} catch (exception) { 3431 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 3432} 3433``` 3434 3435### setWindowPrivacyMode<sup>9+</sup> 3436 3437setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 3438 3439Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 3440 3441A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 3442 3443**System capability**: SystemCapability.WindowManager.WindowManager.Core 3444 3445**Required permissions**: ohos.permission.PRIVACY_WINDOW 3446 3447**Parameters** 3448 3449| Name| Type| Mandatory| Description| 3450| ------------- | ------------------------- | -- | ------------------------------------------------------ | 3451| 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. | 3452| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3453 3454**Error codes** 3455 3456For details about the error codes, see [Window Error Codes](errorcode-window.md). 3457 3458| ID| Error Message| 3459| ------- | ------------------------------ | 3460| 1300002 | This window state is abnormal. | 3461 3462**Example** 3463 3464```ts 3465import { BusinessError } from '@ohos.base'; 3466 3467let isPrivacyMode: boolean = true; 3468try { 3469 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 3470 const errCode: number = err.code; 3471 if (errCode) { 3472 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 3473 return; 3474 } 3475 console.info('Succeeded in setting the window to privacy mode.'); 3476 }); 3477} catch (exception) { 3478 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 3479} 3480``` 3481 3482### setWindowPrivacyMode<sup>9+</sup> 3483 3484setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 3485 3486Sets whether this window is in privacy mode. This API uses a promise to return the result. 3487 3488A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 3489 3490**System capability**: SystemCapability.WindowManager.WindowManager.Core 3491 3492**Required permissions**: ohos.permission.PRIVACY_WINDOW 3493 3494**Parameters** 3495 3496| Name| Type| Mandatory| Description| 3497| ------------- | ------- | -- | ----------------------------------------------------- | 3498| 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.| 3499 3500**Return value** 3501 3502| Type| Description| 3503| ------------------- | ------------------------ | 3504| Promise<void> | Promise that returns no value.| 3505 3506**Error codes** 3507 3508For details about the error codes, see [Window Error Codes](errorcode-window.md). 3509 3510| ID| Error Message| 3511| ------- | ------------------------------ | 3512| 1300002 | This window state is abnormal. | 3513 3514**Example** 3515 3516```ts 3517import { BusinessError } from '@ohos.base'; 3518 3519let isPrivacyMode: boolean = true; 3520try { 3521 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 3522 promise.then(() => { 3523 console.info('Succeeded in setting the window to privacy mode.'); 3524 }).catch((err: BusinessError) => { 3525 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 3526 }); 3527} catch (exception) { 3528 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 3529} 3530``` 3531 3532### setWindowTouchable<sup>9+</sup> 3533 3534setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 3535 3536Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 3537 3538**System capability**: SystemCapability.WindowManager.WindowManager.Core 3539 3540**Parameters** 3541 3542| Name| Type| Mandatory| Description| 3543| ----------- | ------------------------- | -- | ----------------------------------------------- | 3544| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 3545| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3546 3547**Error codes** 3548 3549For details about the error codes, see [Window Error Codes](errorcode-window.md). 3550 3551| ID| Error Message| 3552| ------- | -------------------------------------------- | 3553| 1300002 | This window state is abnormal. | 3554| 1300003 | This window manager service works abnormally. | 3555 3556**Example** 3557 3558```ts 3559import { BusinessError } from '@ohos.base'; 3560 3561let isTouchable = true; 3562try { 3563 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 3564 const errCode: number = err.code; 3565 if (errCode) { 3566 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 3567 return; 3568 } 3569 console.info('Succeeded in setting the window to be touchable.'); 3570 }); 3571} catch (exception) { 3572 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 3573} 3574``` 3575 3576### setWindowTouchable<sup>9+</sup> 3577 3578setWindowTouchable(isTouchable: boolean): Promise<void> 3579 3580Sets whether this window is touchable. This API uses a promise to return the result. 3581 3582**System capability**: SystemCapability.WindowManager.WindowManager.Core 3583 3584**Parameters** 3585 3586| Name| Type| Mandatory| Description| 3587| ----------- | ------- | -- | ----------------------------------------------- | 3588| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 3589 3590**Return value** 3591 3592| Type| Description| 3593| ------------------- | ------------------------- | 3594| Promise<void> | Promise that returns no value.| 3595 3596**Error codes** 3597 3598For details about the error codes, see [Window Error Codes](errorcode-window.md). 3599 3600| ID| Error Message| 3601| ------- | -------------------------------------------- | 3602| 1300002 | This window state is abnormal. | 3603| 1300003 | This window manager service works abnormally. | 3604 3605**Example** 3606 3607```ts 3608import { BusinessError } from '@ohos.base'; 3609 3610let isTouchable: boolean = true; 3611try { 3612 let promise = windowClass.setWindowTouchable(isTouchable); 3613 promise.then(() => { 3614 console.info('Succeeded in setting the window to be touchable.'); 3615 }).catch((err: BusinessError) => { 3616 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 3617 }); 3618} catch (exception) { 3619 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 3620} 3621``` 3622 3623### snapshot<sup>9+</sup> 3624 3625snapshot(callback: AsyncCallback<image.PixelMap>): void 3626 3627Captures this window. This API uses an asynchronous callback to return the result. 3628 3629**System capability**: SystemCapability.WindowManager.WindowManager.Core 3630 3631**Parameters** 3632 3633| Name | Type | Mandatory| Description | 3634| ----------- | ------------------------- | ---- | -------------------- | 3635| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the result. | 3636 3637**Error codes** 3638 3639For details about the error codes, see [Window Error Codes](errorcode-window.md). 3640 3641| ID| Error Message| 3642| ------- | ------------------------------ | 3643| 1300002 | This window state is abnormal. | 3644 3645**Example** 3646 3647```ts 3648import { BusinessError } from '@ohos.base'; 3649import image from '@ohos.multimedia.image'; 3650 3651windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 3652 const errCode: number = err.code; 3653 if (errCode) { 3654 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 3655 return; 3656 } 3657 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 3658 pixelMap.release(); // Release the memory in time after the PixelMap is used. 3659}); 3660``` 3661 3662### snapshot<sup>9+</sup> 3663 3664snapshot(): Promise<image.PixelMap> 3665 3666Captures this window. This API uses a promise to return the result. 3667 3668**System capability**: SystemCapability.WindowManager.WindowManager.Core 3669 3670**Return value** 3671 3672| Type | Description | 3673| ------------------- | ------------------------- | 3674| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the window screenshot.| 3675 3676**Error codes** 3677 3678For details about the error codes, see [Window Error Codes](errorcode-window.md). 3679 3680| ID| Error Message| 3681| ------- | ------------------------------ | 3682| 1300002 | This window state is abnormal. | 3683 3684**Example** 3685 3686```ts 3687import { BusinessError } from '@ohos.base'; 3688import image from '@ohos.multimedia.image'; 3689 3690let promise = windowClass.snapshot(); 3691promise.then((pixelMap: image.PixelMap) => { 3692 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 3693 pixelMap.release(); // Release the memory in time after the PixelMap is used. 3694}).catch((err: BusinessError) => { 3695 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 3696}); 3697``` 3698 3699### setAspectRatio<sup>10+</sup> 3700 3701setAspectRatio(ratio: number): Promise<void> 3702 3703Sets the aspect ratio of the window content layout. This API uses a promise to return the result. 3704 3705This API is available only for the main window of the application. The aspect ratio will be saved permanently and takes effect even after the application is closed or the device is restarted. 3706 3707**System capability**: SystemCapability.WindowManager.WindowManager.Core 3708 3709**Parameters** 3710 3711| Name | Type | Mandatory| Description | 3712| ------------------ | ------- | ---- |-------------------------------------------| 3713| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number greater than or equal to 0.0.| 3714 3715**Return value** 3716 3717| Type | Description | 3718| ------------------- | ------------------------- | 3719| Promise<void> | Promise that returns no value.| 3720 3721**Error codes** 3722 3723For details about the error codes, see [Window Error Codes](errorcode-window.md). 3724 3725| ID| Error Message| 3726| ------- | -------------------------------------------- | 3727| 1300002 | This window state is abnormal. | 3728| 1300004 | Unauthorized operation. | 3729 3730**Example** 3731 3732```ts 3733import { BusinessError } from '@ohos.base'; 3734 3735try { 3736 let ratio = 1.0; 3737 let promise = windowClass.setAspectRatio(ratio); 3738 promise.then(() => { 3739 console.info('Succeeded in setting aspect ratio of window.'); 3740 }).catch((err: BusinessError) => { 3741 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 3742 }); 3743} catch (exception) { 3744 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 3745} 3746``` 3747 3748### setAspectRatio<sup>10+</sup> 3749 3750setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 3751 3752Sets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 3753 3754This API is available only for the main window of the application. The aspect ratio will be saved permanently and takes effect even after the application is closed or the device is restarted. 3755 3756**System capability**: SystemCapability.WindowManager.WindowManager.Core 3757 3758**Parameters** 3759 3760| Name | Type | Mandatory| Description | 3761| ------------------ | ------- | ---- |--------------------------------------------| 3762| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number greater than or equal to 0.0.| 3763| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 3764 3765**Error codes** 3766 3767For details about the error codes, see [Window Error Codes](errorcode-window.md). 3768 3769| ID| Error Message| 3770| ------- | -------------------------------------------- | 3771| 1300002 | This window state is abnormal. | 3772| 1300004 | Unauthorized operation. | 3773 3774**Example** 3775 3776```ts 3777import { BusinessError } from '@ohos.base'; 3778 3779try { 3780 let ratio = 1.0; 3781 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 3782 const errCode: number = err.code; 3783 if (errCode) { 3784 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 3785 return; 3786 } 3787 console.info('Succeeded in setting the aspect ratio of window.'); 3788 }); 3789} catch (exception) { 3790 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 3791} 3792``` 3793 3794### resetAspectRatio<sup>10+</sup> 3795 3796resetAspectRatio(): Promise<void> 3797 3798Resets the aspect ratio of the window content layout. This API uses a promise to return the result. 3799 3800This API is available only for the main window of the application. After this API is called, the persistently stored aspect ratio is cleared. 3801 3802**System capability**: SystemCapability.WindowManager.WindowManager.Core 3803 3804**Return value** 3805 3806| Type | Description | 3807| ------------------- | ------------------------- | 3808| Promise<void> | Promise that returns no value.| 3809 3810**Error codes** 3811 3812For details about the error codes, see [Window Error Codes](errorcode-window.md). 3813 3814| ID| Error Message| 3815| ------- | -------------------------------------------- | 3816| 1300002 | This window state is abnormal. | 3817| 1300004 | Unauthorized operation. | 3818 3819**Example** 3820 3821```ts 3822import { BusinessError } from '@ohos.base'; 3823 3824try { 3825 let promise = windowClass.resetAspectRatio(); 3826 promise.then(() => { 3827 console.info('Succeeded in resetting aspect ratio of window.'); 3828 }).catch((err: BusinessError) => { 3829 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 3830 }); 3831} catch (exception) { 3832 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 3833} 3834``` 3835 3836### resetAspectRatio<sup>10+</sup> 3837 3838resetAspectRatio(callback: AsyncCallback<void>): void 3839 3840Resets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 3841 3842This API is available only for the main window of the application. After this API is called, the persistently stored aspect ratio is cleared. 3843 3844**System capability**: SystemCapability.WindowManager.WindowManager.Core 3845 3846**Parameters** 3847 3848| Name | Type | Mandatory| Description | 3849| ------------------ | ------- | ---- | ------------------------------------------------------------ | 3850| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 3851 3852**Error codes** 3853 3854For details about the error codes, see [Window Error Codes](errorcode-window.md). 3855 3856| ID| Error Message| 3857| ------- | -------------------------------------------- | 3858| 1300002 | This window state is abnormal. | 3859| 1300004 | Unauthorized operation. | 3860 3861**Example** 3862 3863```ts 3864import { BusinessError } from '@ohos.base'; 3865 3866try { 3867 windowClass.resetAspectRatio((err: BusinessError) => { 3868 const errCode: number = err.code; 3869 if (errCode) { 3870 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 3871 return; 3872 } 3873 console.info('Succeeded in resetting aspect ratio of window.'); 3874 }); 3875} catch (exception) { 3876 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 3877} 3878``` 3879 3880### minimize<sup>11+</sup> 3881 3882minimize(callback: AsyncCallback<void>): void 3883 3884Implements different functionalities based on the caller: 3885 3886Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. 3887 3888Hides the subwindow if the caller is a subwindow. The subwindow cannot be restored in the dock bar. 3889 3890This API uses an asynchronous callback to return the result. 3891 3892**System capability**: SystemCapability.Window.SessionManager 3893 3894**Parameters** 3895 3896| Name | Type | Mandatory| Description | 3897| -------- | ------------------------- | ---- | ---------- | 3898| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3899 3900**Error codes** 3901 3902For details about the error codes, see [Window Error Codes](errorcode-window.md). 3903 3904| ID| Error Message| 3905| ------- | ------------------------------ | 3906| 1300002 | This window state is abnormal. | 3907| 1300003 | This window manager service works abnormally. | 3908 3909**Example** 3910 3911```js 3912import { BusinessError } from '@ohos.base'; 3913 3914windowClass.minimize((err: BusinessError) => { 3915 const errCode: number = err.code; 3916 if (errCode) { 3917 console.error('Failed to minimize the window. Cause: ' + JSON.stringify(err)); 3918 return; 3919 } 3920 console.info('Succeeded in minimizing the window.'); 3921}); 3922``` 3923 3924### minimize<sup>11+</sup> 3925 3926minimize(): Promise<void> 3927 3928Implements different functionalities based on the caller: 3929 3930Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. 3931 3932Hides the subwindow if the caller is a subwindow. The subwindow cannot be restored in the dock bar. 3933 3934This API uses a promise to return the result. 3935 3936**System capability**: SystemCapability.Window.SessionManager 3937 3938**Return value** 3939 3940| Type | Description | 3941| ------------------- | ------------------------- | 3942| Promise<void> | Promise that returns no value.| 3943 3944**Error codes** 3945 3946For details about the error codes, see [Window Error Codes](errorcode-window.md). 3947 3948| ID| Error Message| 3949| ------- | ------------------------------ | 3950| 1300002 | This window state is abnormal. | 3951| 1300003 | This window manager service works abnormally. | 3952 3953**Example** 3954 3955```js 3956import { BusinessError } from '@ohos.base'; 3957 3958let promise = windowClass.minimize(); 3959promise.then(() => { 3960 console.info('Succeeded in minimizing the window.'); 3961}).catch((err: BusinessError) => { 3962 console.error('Failed to minimize the window. Cause: ' + JSON.stringify(err)); 3963}); 3964``` 3965 3966### recover<sup>11+</sup> 3967 3968recover(): Promise<void> 3969 3970Restores 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 for certain device types. 3971 3972**System capability**: SystemCapability.Window.SessionManager 3973 3974**Return value** 3975 3976| Type | Description | 3977| ------------------- | ------------------------- | 3978| Promise<void> | Promise that returns no value.| 3979 3980**Error codes** 3981 3982For details about the error codes, see [Window Error Codes](errorcode-window.md). 3983 3984| ID| Error Message| 3985| ------- | ------------------------------ | 3986| 1300001 | Repeated operation. | 3987| 1300002 | This window state is abnormal. | 3988 3989**Example** 3990 3991```ts 3992import { BusinessError } from '@ohos.base'; 3993 3994let promise = windowClass.recover(); 3995promise.then(() => { 3996 console.info('Succeeded in recovering the window.'); 3997}).catch((err: BusinessError) => { 3998 console.error('Failed to recover the window. Cause: ' + JSON.stringify(err)); 3999}); 4000``` 4001 4002 4003### getWindowLimits<sup>11+</sup> 4004 4005getWindowLimits(): WindowLimits 4006 4007Obtains the size limits of this window. 4008 4009**System capability**: SystemCapability.Window.SessionManager 4010 4011**Return value** 4012 4013| Type | Description | 4014| ----------------------------- | ------------------ | 4015| [WindowLimits](#windowlimits11) | Window size limits.| 4016 4017**Error codes** 4018 4019For details about the error codes, see [Window Error Codes](errorcode-window.md). 4020 4021| ID| Error Message | 4022| :------- | :----------------------------- | 4023| 1300002 | This window state is abnormal. | 4024 4025**Example** 4026 4027```ts 4028try { 4029 let windowLimits = windowClass.getWindowLimits(); 4030} catch (exception) { 4031 console.error('Failed to obtain the window limits of window. Cause: ' + JSON.stringify(exception)); 4032} 4033``` 4034 4035### setWindowLimits<sup>11+</sup> 4036 4037setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 4038 4039Sets the size limits for this window. This API uses a promise to return the result. 4040 4041**System capability**: SystemCapability.Window.SessionManager 4042 4043**Parameters** 4044 4045| Name | Type | Mandatory| Description | 4046| :----------- | :---------------------------- | :--- | :----------------------------- | 4047| windowLimits | [WindowLimits](#windowlimits11) | Yes | Target size limits, in px.| 4048 4049**Return value** 4050 4051| Type | Description | 4052| :------------------------------------------- | :---------------------------------- | 4053| Promise<[WindowLimits](#windowlimits11)> | Promise used to return the new size limits.| 4054 4055**Error codes** 4056 4057For details about the error codes, see [Window Error Codes](errorcode-window.md). 4058 4059| ID| Error Message | 4060| :------- | :-------------------------------------------- | 4061| 1300002 | This window state is abnormal. | 4062| 1300003 | This window manager service works abnormally. | 4063| 1300004 | Unauthorized operation. | 4064 4065**Example** 4066 4067```ts 4068import { BusinessError } from '@ohos.base'; 4069try { 4070 let windowLimits: window.WindowLimits = { 4071 maxWidth: 1500, 4072 maxHeight: 1000, 4073 minWidth: 500, 4074 minHeight: 400 4075 }; 4076 let promise = windowClass.setWindowLimits(windowLimits); 4077 promise.then((data) => { 4078 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 4079 }).catch((err: BusinessError) => { 4080 console.error('Failed to change the window limits. Cause: ' + JSON.stringify(err)); 4081 }); 4082} catch (exception) { 4083 console.error('Failed to change the window limits. Cause:' + JSON.stringify(exception)); 4084} 4085``` 4086 4087### keepKeyboardOnFocus<sup>11+</sup> 4088 4089keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 4090 4091Sets 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 subwindow. 4092 4093**System capability**: SystemCapability.Window.SessionManager 4094 4095**Parameters** 4096 4097| Name | Type | Mandatory| Description | 4098| ---------------- | ------- | ---- | ------------------------------------------------------------ | 4099| 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.| 4100 4101**Error codes** 4102 4103For details about the error codes, see [Window Error Codes](errorcode-window.md). 4104 4105| ID| Error Message| 4106| ------- | ---------------------------------------- | 4107| 1300002 | This window state is abnormal. | 4108| 1300004 | Unauthorized operation. | 4109 4110**Example** 4111 4112```ts 4113try { 4114 windowClass.keepKeyboardOnFocus(true); 4115} catch (exception) { 4116 console.error('Failed to keep keyboard onFocus. Cause: ' + JSON.stringify(exception)); 4117} 4118``` 4119 4120### setWindowDecorVisible<sup>11+</sup> 4121 4122setWindowDecorVisible(isVisible: boolean): void 4123 4124Sets whether the title bar is visible in the main window. 4125 4126**System capability**: SystemCapability.Window.SessionManager 4127 4128**Parameters** 4129 4130| Name | Type | Mandatory| Description | 4131| --------- | ------- | ---- | --------------------------------------------- | 4132| isVisible | boolean | Yes | Whether the title bar is visible. The value **true** means that the title bar is visible and **false** means the opposite.| 4133 4134**Error codes** 4135 4136For details about the error codes, see [Window Error Codes](errorcode-window.md). 4137 4138| ID| Error Message | 4139| -------- | ------------------------------ | 4140| 1300002 | This window state is abnormal. | 4141| 1300004 | Unauthorized operation. | 4142 4143**Example** 4144 4145```ts 4146import UIAbility from '@ohos.app.ability.UIAbility'; 4147import { BusinessError } from '@ohos.base'; 4148 4149export default class EntryAbility extends UIAbility { 4150 onWindowStageCreate(windowStage: window.WindowStage) { 4151 // Load content for the main window. 4152 windowStage.loadContent("pages/page2", (err: BusinessError) => { 4153 let errCode: number = err.code; 4154 if (errCode) { 4155 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 4156 return; 4157 } 4158 console.info('Succeeded in loading the content.'); 4159 // Obtain the main window. 4160 let mainWindow: window.Window | undefined = undefined; 4161 windowStage.getMainWindow((err: BusinessError, data) => { 4162 let errCode: number = err.code; 4163 if (errCode) { 4164 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 4165 return; 4166 } 4167 mainWindow = data; 4168 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 4169 let isVisible = false; 4170 // Call setWindowDecorVisible. 4171 try { 4172 mainWindow.setWindowDecorVisible(isVisible); 4173 } catch (exception) { 4174 console.error('Failed to set the visibility of window decor. Cause: ' + JSON.stringify(exception)); 4175 } 4176 }) 4177 }); 4178 } 4179}; 4180``` 4181 4182### setWindowDecorHeight<sup>11+</sup> 4183 4184setWindowDecorHeight(height: number): void 4185 4186Sets the height of the title bar for this window. 4187 4188**System capability**: SystemCapability.Window.SessionManager 4189 4190**Parameters** 4191 4192| Name| Type | Mandatory| Description | 4193| ------ | ------ | ---- | ------------------------------------------------------------ | 4194| height | number | Yes | Height of the title bar. The value is an integer in the range [48,112]. The unit is vp.| 4195 4196**Error codes** 4197 4198For details about the error codes, see [Window Error Codes](errorcode-window.md). 4199 4200| ID| Error Message | 4201| -------- | ------------------------------ | 4202| 1300002 | This window state is abnormal. | 4203 4204**Example** 4205 4206```ts 4207let height: number = 50; 4208try { 4209 windowClass.setWindowDecorHeight(height); 4210} catch (exception) { 4211 console.error('Failed to set the height of window decor. Cause: ' + JSON.stringify(exception)); 4212} 4213``` 4214 4215### getWindowDecorHeight<sup>11+</sup> 4216 4217getWindowDecorHeight(): number 4218 4219Obtains the height of the title bar of this window. 4220 4221**System capability**: SystemCapability.Window.SessionManager 4222 4223**Return value** 4224 4225| Type | Description | 4226| ------ | ------------------------------------------------------------ | 4227| number | Height of the title bar. The value is an integer in the range [48,112]. The unit is vp.| 4228 4229**Error codes** 4230 4231For details about the error codes, see [Window Error Codes](errorcode-window.md). 4232 4233| ID| Error Message | 4234| -------- | ------------------------------ | 4235| 1300002 | This window state is abnormal. | 4236 4237**Example** 4238 4239```ts 4240try { 4241 let height = windowClass.getWindowDecorHeight(); 4242} catch (exception) { 4243 console.error('Failed to get the height of window decor. Cause: ' + JSON.stringify(exception)); 4244} 4245``` 4246 4247### getTitleButtonRect<sup>11+</sup> 4248 4249getTitleButtonRect(): TitleButtonRect 4250 4251Obtains the rectangle that holds the minimize, maximize, and close buttons on the title bar. 4252 4253**System capability**: SystemCapability.Window.SessionManager 4254 4255**Return value** 4256 4257| Type | Description | 4258| ------------------------------------- | ------------------------------------------------------------ | 4259| [TitleButtonRect](#titlebuttonrect11) | Rectangle obtained, which is located in the upper right corner of the window.| 4260 4261**Error codes** 4262 4263For details about the error codes, see [Window Error Codes](errorcode-window.md). 4264 4265| ID| Error Message | 4266| -------- | ------------------------------ | 4267| 1300002 | This window state is abnormal. | 4268 4269**Example** 4270 4271```ts 4272try { 4273 let titleButtonArea = windowClass.getTitleButtonRect(); 4274 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 4275} catch (exception) { 4276 console.error('Failed to get the area of title buttons. Cause: ' + JSON.stringify(exception)); 4277} 4278``` 4279 4280### show<sup>(deprecated)</sup> 4281 4282show(callback: AsyncCallback<void>): void 4283 4284Shows this window. This API uses an asynchronous callback to return the result. 4285 4286> **NOTE** 4287> 4288> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9) instead. 4289 4290**System capability**: SystemCapability.WindowManager.WindowManager.Core 4291 4292**Parameters** 4293 4294| Name | Type | Mandatory| Description | 4295| -------- | ------------------------- | ---- | ---------- | 4296| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 4297 4298**Example** 4299 4300```ts 4301import { BusinessError } from '@ohos.base'; 4302 4303windowClass.show((err: BusinessError) => { 4304 const errCode: number = err.code; 4305 if (errCode) { 4306 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 4307 return; 4308 } 4309 console.info('Succeeded in showing the window.'); 4310}); 4311``` 4312 4313### show<sup>(deprecated)</sup> 4314 4315show(): Promise<void> 4316 4317Shows this window. This API uses a promise to return the result. 4318 4319> **NOTE** 4320> 4321> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9-1) instead. 4322 4323**System capability**: SystemCapability.WindowManager.WindowManager.Core 4324 4325**Return value** 4326 4327| Type | Description | 4328| ------------------- | ------------------------- | 4329| Promise<void> | Promise that returns no value.| 4330 4331**Example** 4332 4333```ts 4334import { BusinessError } from '@ohos.base'; 4335 4336let promise = windowClass.show(); 4337promise.then(() => { 4338 console.info('Succeeded in showing the window.'); 4339}).catch((err: BusinessError) => { 4340 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 4341}); 4342``` 4343 4344### destroy<sup>(deprecated)</sup> 4345 4346destroy(callback: AsyncCallback<void>): void 4347 4348Destroys this window. This API uses an asynchronous callback to return the result. 4349 4350> **NOTE** 4351> 4352> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9) instead. 4353 4354**System capability**: SystemCapability.WindowManager.WindowManager.Core 4355 4356**Parameters** 4357 4358| Name | Type | Mandatory| Description | 4359| -------- | ------------------------- | ---- | ---------- | 4360| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 4361 4362**Example** 4363 4364```ts 4365import { BusinessError } from '@ohos.base'; 4366 4367windowClass.destroy((err: BusinessError) => { 4368 const errCode: number = err.code; 4369 if (err.code) { 4370 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 4371 return; 4372 } 4373 console.info('Succeeded in destroying the window.'); 4374}); 4375``` 4376 4377### destroy<sup>(deprecated)</sup> 4378 4379destroy(): Promise<void> 4380 4381Destroys this window. This API uses a promise to return the result. 4382 4383> **NOTE** 4384> 4385> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9-1) instead. 4386 4387**System capability**: SystemCapability.WindowManager.WindowManager.Core 4388 4389**Return value** 4390 4391| Type | Description | 4392| ------------------- | ------------------------- | 4393| Promise<void> | Promise that returns no value.| 4394 4395**Example** 4396 4397```ts 4398import { BusinessError } from '@ohos.base'; 4399 4400let promise = windowClass.destroy(); 4401promise.then(() => { 4402 console.info('Succeeded in destroying the window.'); 4403}).catch((err: BusinessError) => { 4404 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 4405}); 4406``` 4407 4408### moveTo<sup>(deprecated)</sup> 4409 4410moveTo(x: number, y: number, callback: AsyncCallback<void>): void 4411 4412Moves this window. This API uses an asynchronous callback to return the result. 4413 4414This operation is not supported in a window in full-screen mode. 4415 4416> **NOTE** 4417> 4418> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9) instead. 4419 4420**System capability**: SystemCapability.WindowManager.WindowManager.Core 4421 4422**Parameters** 4423 4424| Name | Type | Mandatory| Description | 4425| -------- | ------------------------- | ---- | ------------------------------------------------- | 4426| 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.| 4427| 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.| 4428| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4429 4430**Example** 4431 4432```ts 4433import { BusinessError } from '@ohos.base'; 4434 4435windowClass.moveTo(300, 300, (err: BusinessError) => { 4436 const errCode: number = err.code; 4437 if (errCode) { 4438 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 4439 return; 4440 } 4441 console.info('Succeeded in moving the window.'); 4442}); 4443``` 4444 4445### moveTo<sup>(deprecated)</sup> 4446 4447moveTo(x: number, y: number): Promise<void> 4448 4449Moves this window. This API uses a promise to return the result. 4450 4451This operation is not supported in a window in full-screen mode. 4452 4453> **NOTE** 4454> 4455> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9-1) instead. 4456 4457**System capability**: SystemCapability.WindowManager.WindowManager.Core 4458 4459**Parameters** 4460 4461| Name| Type | Mandatory| Description | 4462| ------ | ------ | ---- | ------------------------------------------------- | 4463| 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.| 4464| 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.| 4465 4466**Return value** 4467 4468| Type | Description | 4469| ------------------- | ------------------------- | 4470| Promise<void> | Promise that returns no value.| 4471 4472**Example** 4473 4474```ts 4475import { BusinessError } from '@ohos.base'; 4476 4477let promise = windowClass.moveTo(300, 300); 4478promise.then(() => { 4479 console.info('Succeeded in moving the window.'); 4480}).catch((err: BusinessError) => { 4481 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 4482}); 4483``` 4484 4485### resetSize<sup>(deprecated)</sup> 4486 4487resetSize(width: number, height: number, callback: AsyncCallback<void>): void 4488 4489Changes the size of this window. This API uses an asynchronous callback to return the result. 4490 4491The main window and subwindow have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 4492The minimum width and height of the main window and subwindow of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 4493 4494The system window has the following size limits: [0, 1920] in width and [0, 1920] in height, both in units of vp. 4495 4496The window width and height you set must meet the limits. The rules are as follows: 4497- 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. 4498- 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. 4499 4500This operation is not supported in a window in full-screen mode. 4501 4502> **NOTE** 4503> 4504> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9) instead. 4505 4506**System capability**: SystemCapability.WindowManager.WindowManager.Core 4507 4508**Parameters** 4509 4510| Name | Type | Mandatory| Description | 4511| -------- | ------------------------- | ---- | -------------------------- | 4512| width | number | Yes | New width of the window, in px. The value must be an integer. A negative value is invalid.| 4513| height | number | Yes | New height of the window, in px. The value must be an integer. A negative value is invalid.| 4514| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4515 4516**Example** 4517 4518```ts 4519import { BusinessError } from '@ohos.base'; 4520 4521windowClass.resetSize(500, 1000, (err: BusinessError) => { 4522 const errCode: number = err.code; 4523 if (errCode) { 4524 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 4525 return; 4526 } 4527 console.info('Succeeded in changing the window size.'); 4528}); 4529``` 4530 4531### resetSize<sup>(deprecated)</sup> 4532 4533resetSize(width: number, height: number): Promise<void> 4534 4535Changes the size of this window. This API uses a promise to return the result. 4536 4537The main window and subwindow have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 4538The minimum width and height of the main window and subwindow of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 4539 4540The system window has the following size limits: [0, 1920] in width and [0, 1920] in height, both in units of vp. 4541 4542The window width and height you set must meet the limits. The rules are as follows: 4543- 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. 4544- 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. 4545 4546This operation is not supported in a window in full-screen mode. 4547 4548> **NOTE** 4549> 4550> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9-1) instead. 4551 4552**System capability**: SystemCapability.WindowManager.WindowManager.Core 4553 4554**Parameters** 4555 4556| Name| Type | Mandatory| Description | 4557| ------ | ------ | ---- | -------------------------- | 4558| width | number | Yes | New width of the window, in px. The value must be an integer. A negative value is invalid.| 4559| height | number | Yes | New height of the window, in px. The value must be an integer. A negative value is invalid.| 4560 4561**Return value** 4562 4563| Type | Description | 4564| ------------------- | ------------------------- | 4565| Promise<void> | Promise that returns no value.| 4566 4567**Example** 4568 4569```ts 4570import { BusinessError } from '@ohos.base'; 4571 4572let promise = windowClass.resetSize(500, 1000); 4573promise.then(() => { 4574 console.info('Succeeded in changing the window size.'); 4575}).catch((err: BusinessError) => { 4576 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 4577}); 4578``` 4579 4580### getProperties<sup>(deprecated)</sup> 4581 4582getProperties(callback: AsyncCallback<WindowProperties>): void 4583 4584Obtains the properties of this window. This API uses an asynchronous callback to return the result. 4585 4586> **NOTE** 4587> 4588> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 4589 4590**System capability**: SystemCapability.WindowManager.WindowManager.Core 4591 4592**Parameters** 4593 4594| Name | Type | Mandatory| Description | 4595| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 4596| callback | AsyncCallback<[WindowProperties](#windowproperties)> | Yes | Callback used to return the window properties.| 4597 4598**Example** 4599 4600```ts 4601import { BusinessError } from '@ohos.base'; 4602 4603windowClass.getProperties((err: BusinessError, data) => { 4604 const errCode: number = err.code; 4605 if (errCode) { 4606 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 4607 return; 4608 } 4609 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 4610}); 4611``` 4612 4613### getProperties<sup>(deprecated)</sup> 4614 4615getProperties(): Promise<WindowProperties> 4616 4617Obtains the properties of this window. This API uses a promise to return the result. 4618 4619> **NOTE** 4620> 4621> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 4622 4623**System capability**: SystemCapability.WindowManager.WindowManager.Core 4624 4625**Return value** 4626 4627| Type | Description | 4628| ---------------------------------------------------- | ------------------------------- | 4629| Promise<[WindowProperties](#windowproperties)> | Promise used to return the window properties.| 4630 4631**Example** 4632 4633```ts 4634import { BusinessError } from '@ohos.base'; 4635 4636let promise = windowClass.getProperties(); 4637promise.then((data) => { 4638 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 4639}).catch((err: BusinessError) => { 4640 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 4641}); 4642``` 4643 4644### getAvoidArea<sup>(deprecated)</sup> 4645 4646getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 4647 4648Obtains 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. 4649 4650> **NOTE** 4651> 4652> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 4653 4654**System capability**: SystemCapability.WindowManager.WindowManager.Core 4655 4656**Parameters** 4657 4658| Name | Type | Mandatory| Description | 4659| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 4660| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area.| 4661| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 4662 4663**Example** 4664 4665```ts 4666import { BusinessError } from '@ohos.base'; 4667 4668let type = window.AvoidAreaType.TYPE_SYSTEM; 4669windowClass.getAvoidArea(type, (err: BusinessError, data) => { 4670 const errCode: number = err.code; 4671 if (errCode) { 4672 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 4673 return; 4674 } 4675 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 4676}); 4677``` 4678 4679### getAvoidArea<sup>(deprecated)</sup> 4680 4681getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 4682 4683Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. This API uses a promise to return the result. 4684 4685> **NOTE** 4686> 4687> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 4688 4689**System capability**: SystemCapability.WindowManager.WindowManager.Core 4690 4691**Parameters** 4692 4693| Name| Type | Mandatory| Description | 4694| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 4695| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area.| 4696 4697**Return value** 4698 4699| Type | Description | 4700|-----------------------------------------| ----------------------------------- | 4701| Promise<[AvoidArea](#avoidarea7)> | Promise used to return the area.| 4702 4703**Example** 4704 4705```ts 4706import { BusinessError } from '@ohos.base'; 4707 4708let type = window.AvoidAreaType.TYPE_SYSTEM; 4709let promise = windowClass.getAvoidArea(type); 4710promise.then((data) => { 4711 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 4712}).catch((err: BusinessError) => { 4713 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 4714}); 4715``` 4716 4717### setFullScreen<sup>(deprecated)</sup> 4718 4719setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 4720 4721Sets whether the window is in full-screen mode. This API uses an asynchronous callback to return the result. 4722In full-screen mode, the window is displayed in full screen, and the status bar and navigation bar are not displayed. 4723In non-full-screen mode, the status bar and navigation bar are displayed, and the window size does not overlap the positions of the status bar and navigation bar. 4724 4725> **NOTE** 4726> 4727> 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. 4728 4729**System capability**: SystemCapability.WindowManager.WindowManager.Core 4730 4731**Parameters** 4732 4733| Name | Type | Mandatory| Description | 4734| ------------ | ------------------------- | ---- | ---------------------------------------------- | 4735| 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.| 4736| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4737 4738**Example** 4739 4740```ts 4741import { BusinessError } from '@ohos.base'; 4742 4743let isFullScreen: boolean = true; 4744windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 4745 const errCode: number = err.code; 4746 if (errCode) { 4747 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 4748 return; 4749 } 4750 console.info('Succeeded in enabling the full-screen mode.'); 4751}); 4752``` 4753 4754### setFullScreen<sup>(deprecated)</sup> 4755 4756setFullScreen(isFullScreen: boolean): Promise<void> 4757 4758Sets whether the window is in full-screen mode. This API uses a promise to return the result. 4759In full-screen mode, the window is displayed in full screen, and the status bar and navigation bar are not displayed. 4760In non-full-screen mode, the status bar and navigation bar are displayed, and the window size does not overlap the positions of the status bar and navigation bar. 4761 4762> **NOTE** 4763> 4764> 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. 4765 4766**System capability**: SystemCapability.WindowManager.WindowManager.Core 4767 4768**Parameters** 4769 4770| Name | Type | Mandatory| Description | 4771| ------------ | ------- | ---- | ---------------------------------------------- | 4772| 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.| 4773 4774**Return value** 4775 4776| Type | Description | 4777| ------------------- | ------------------------- | 4778| Promise<void> | Promise that returns no value.| 4779 4780**Example** 4781 4782```ts 4783import { BusinessError } from '@ohos.base'; 4784 4785let isFullScreen: boolean = true; 4786let promise = windowClass.setFullScreen(isFullScreen); 4787promise.then(() => { 4788 console.info('Succeeded in enabling the full-screen mode.'); 4789}).catch((err: BusinessError) => { 4790 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 4791}); 4792``` 4793 4794### setLayoutFullScreen<sup>(deprecated)</sup> 4795 4796setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 4797 4798Sets whether the window layout is immersive. This API uses an asynchronous callback to return the result. 4799An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 4800A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 4801 4802> **NOTE** 4803> 4804> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) instead. 4805 4806**System capability**: SystemCapability.WindowManager.WindowManager.Core 4807 4808**Parameters** 4809 4810| Name | Type | Mandatory| Description | 4811| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 4812| 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.| 4813| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4814 4815**Example** 4816 4817```ts 4818import { BusinessError } from '@ohos.base'; 4819 4820let isLayoutFullScreen: boolean = true; 4821windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 4822 const errCode: number = err.code; 4823 if (errCode) { 4824 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 4825 return; 4826 } 4827 console.info('Succeeded in setting the window layout to full-screen mode.'); 4828}); 4829``` 4830 4831### setLayoutFullScreen<sup>(deprecated)</sup> 4832 4833setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 4834 4835Sets whether the window layout is immersive. This API uses a promise to return the result. 4836An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 4837A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 4838 4839> **NOTE** 4840> 4841> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1) instead. 4842 4843**System capability**: SystemCapability.WindowManager.WindowManager.Core 4844 4845**Parameters** 4846 4847| Name | Type | Mandatory| Description | 4848| ------------------ | ------- | ---- | ------------------------------------------------------------ | 4849| 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.| 4850 4851**Return value** 4852 4853| Type | Description | 4854| ------------------- | ------------------------- | 4855| Promise<void> | Promise that returns no value.| 4856 4857**Example** 4858 4859```ts 4860import { BusinessError } from '@ohos.base'; 4861 4862let isLayoutFullScreen: boolean = true; 4863let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 4864promise.then(() => { 4865 console.info('Succeeded in setting the window layout to full-screen mode.'); 4866}).catch((err: BusinessError) => { 4867 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 4868}); 4869``` 4870 4871### setSystemBarEnable<sup>(deprecated)</sup> 4872 4873setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 4874 4875Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 4876 4877> **NOTE** 4878> 4879> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) instead. 4880 4881**System capability**: SystemCapability.WindowManager.WindowManager.Core 4882 4883**Parameters** 4884 4885| Name | Type | Mandatory| Description | 4886| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 4887| names | Array<'status'\|'navigation'> | Yes | Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 4888| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4889 4890**Example** 4891 4892```ts 4893// In this example, the status bar and navigation bar are not displayed. 4894import { BusinessError } from '@ohos.base'; 4895 4896let names: Array<'status' | 'navigation'> = []; 4897windowClass.setSystemBarEnable(names, (err: BusinessError) => { 4898 const errCode: number = err.code; 4899 if (errCode) { 4900 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 4901 return; 4902 } 4903 console.info('Succeeded in setting the system bar to be invisible.'); 4904}); 4905``` 4906 4907### setSystemBarEnable<sup>(deprecated)</sup> 4908 4909setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 4910 4911Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 4912 4913> **NOTE** 4914> 4915> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9-1) instead. 4916 4917**System capability**: SystemCapability.WindowManager.WindowManager.Core 4918 4919**Parameters** 4920 4921| Name| Type | Mandatory| Description | 4922| ------ | ---------------------------- | ---- | ------------------------ | 4923| names | Array<'status'\|'navigation'> | Yes | Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 4924 4925**Return value** 4926 4927| Type | Description | 4928| ------------------- | ------------------------- | 4929| Promise<void> | Promise that returns no value.| 4930 4931**Example** 4932 4933```ts 4934// In this example, the status bar and navigation bar are not displayed. 4935import { BusinessError } from '@ohos.base'; 4936 4937let names: Array<'status' | 'navigation'> = []; 4938let promise = windowClass.setSystemBarEnable(names); 4939promise.then(() => { 4940 console.info('Succeeded in setting the system bar to be invisible.'); 4941}).catch((err: BusinessError) => { 4942 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 4943}); 4944``` 4945 4946### setSystemBarProperties<sup>(deprecated)</sup> 4947 4948setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 4949 4950Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 4951 4952> **NOTE** 4953> 4954> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9) instead. 4955 4956**System capability**: SystemCapability.WindowManager.WindowManager.Core 4957 4958**Parameters** 4959 4960| Name | Type | Mandatory| Description | 4961| ------------------- | ------------------------------------------- | ---- | ---------------------- | 4962| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 4963| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4964 4965**Example** 4966 4967```ts 4968import { BusinessError } from '@ohos.base'; 4969 4970let SystemBarProperties: window.SystemBarProperties = { 4971 statusBarColor: '#ff00ff', 4972 navigationBarColor: '#00ff00', 4973 // The following properties are supported since API version 8. 4974 statusBarContentColor: '#ffffff', 4975 navigationBarContentColor: '#00ffff' 4976}; 4977windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 4978 const errCode: number = err.code; 4979 if (errCode) { 4980 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 4981 return; 4982 } 4983 console.info('Succeeded in setting the system bar properties.'); 4984}); 4985``` 4986 4987### setSystemBarProperties<sup>(deprecated)</sup> 4988 4989setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 4990 4991Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 4992 4993> **NOTE** 4994> 4995> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9-1) instead. 4996 4997**System capability**: SystemCapability.WindowManager.WindowManager.Core 4998 4999**Parameters** 5000 5001| Name | Type | Mandatory| Description | 5002| ------------------- | ------------------------------------------- | ---- | ---------------------- | 5003| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 5004 5005**Return value** 5006 5007| Type | Description | 5008| ------------------- | ------------------------- | 5009| Promise<void> | Promise that returns no value.| 5010 5011**Example** 5012 5013```ts 5014import { BusinessError } from '@ohos.base'; 5015 5016let SystemBarProperties: window.SystemBarProperties = { 5017 statusBarColor: '#ff00ff', 5018 navigationBarColor: '#00ff00', 5019 // The following properties are supported since API version 8. 5020 statusBarContentColor: '#ffffff', 5021 navigationBarContentColor: '#00ffff' 5022}; 5023let promise = windowClass.setSystemBarProperties(SystemBarProperties); 5024promise.then(() => { 5025 console.info('Succeeded in setting the system bar properties.'); 5026}).catch((err: BusinessError) => { 5027 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 5028}); 5029``` 5030 5031### loadContent<sup>(deprecated)</sup> 5032 5033loadContent(path: string, callback: AsyncCallback<void>): void 5034 5035Loads content from a page to this window. This API uses an asynchronous callback to return the result. 5036 5037> **NOTE** 5038> 5039> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9) instead. 5040 5041**System capability**: SystemCapability.WindowManager.WindowManager.Core 5042 5043**Parameters** 5044 5045| Name | Type | Mandatory| Description | 5046| -------- | ------------------------- | ---- | -------------------- | 5047| 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.| 5048| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5049 5050**Example** 5051 5052```ts 5053import { BusinessError } from '@ohos.base'; 5054 5055windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 5056 const errCode: number = err.code; 5057 if (errCode) { 5058 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5059 return; 5060 } 5061 console.info('Succeeded in loading the content.'); 5062}); 5063``` 5064 5065### loadContent<sup>(deprecated)</sup> 5066 5067loadContent(path: string): Promise<void> 5068 5069Loads content from a page to this window. This API uses a promise to return the result. 5070 5071> **NOTE** 5072> 5073> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9-1) instead. 5074 5075**System capability**: SystemCapability.WindowManager.WindowManager.Core 5076 5077**Parameters** 5078 5079| Name| Type | Mandatory| Description | 5080| ------ | ------ | ---- | -------------------- | 5081| 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.| 5082 5083**Return value** 5084 5085| Type | Description | 5086| ------------------- | ------------------------- | 5087| Promise<void> | Promise that returns no value.| 5088 5089**Example** 5090 5091```ts 5092import { BusinessError } from '@ohos.base'; 5093 5094let promise = windowClass.loadContent('pages/page2/page3'); 5095promise.then(() => { 5096 console.info('Succeeded in loading the content.'); 5097}).catch((err: BusinessError) => { 5098 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 5099}); 5100``` 5101 5102### isShowing<sup>(deprecated)</sup> 5103 5104isShowing(callback: AsyncCallback<boolean>): void 5105 5106Checks whether this window is displayed. This API uses an asynchronous callback to return the result. 5107 5108> **NOTE** 5109> 5110> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 5111 5112**System capability**: SystemCapability.WindowManager.WindowManager.Core 5113 5114**Parameters** 5115 5116| Name | Type | Mandatory| Description | 5117| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 5118| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the window is displayed, and **false** means the opposite.| 5119 5120**Example** 5121 5122```ts 5123import { BusinessError } from '@ohos.base'; 5124 5125windowClass.isShowing((err: BusinessError, data) => { 5126 const errCode: number = err.code; 5127 if (errCode) { 5128 console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err)); 5129 return; 5130 } 5131 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 5132}); 5133``` 5134 5135### isShowing<sup>(deprecated)</sup> 5136 5137isShowing(): Promise<boolean> 5138 5139Checks whether this window is displayed. This API uses a promise to return the result. 5140 5141> **NOTE** 5142> 5143> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 5144 5145**System capability**: SystemCapability.WindowManager.WindowManager.Core 5146 5147**Return value** 5148 5149| Type | Description | 5150| ---------------------- | ------------------------------------------------------------ | 5151| Promise<boolean> | Promise used to return the result. The value **true** means that the window is displayed, and **false** means the opposite.| 5152 5153**Example** 5154 5155```ts 5156import { BusinessError } from '@ohos.base'; 5157 5158let promise = windowClass.isShowing(); 5159promise.then((data) => { 5160 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 5161}).catch((err: BusinessError) => { 5162 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err)); 5163}); 5164``` 5165 5166### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 5167 5168on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 5169 5170Subscribes to the event indicating changes to the area where the window cannot be displayed. 5171 5172> **NOTE** 5173> 5174> This API is supported since API version 7 and deprecated since API version 9. Use [on('avoidAreaChange')](#onavoidareachange9) instead. 5175 5176**System capability**: SystemCapability.WindowManager.WindowManager.Core 5177 5178**Parameters** 5179 5180| Name | Type | Mandatory| Description | 5181| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 5182| 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.| 5183| callback | Callback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 5184 5185**Example** 5186 5187```ts 5188windowClass.on('systemAvoidAreaChange', (data) => { 5189 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 5190}); 5191``` 5192 5193### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 5194 5195off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 5196 5197Unsubscribes from the event indicating changes to the area where the window cannot be displayed. 5198 5199> **NOTE** 5200> 5201> This API is supported since API version 7 and deprecated since API version 9. Use [off('avoidAreaChange')](#offavoidareachange9) instead. 5202 5203**System capability**: SystemCapability.WindowManager.WindowManager.Core 5204 5205**Parameters** 5206 5207| Name | Type | Mandatory| Description | 5208| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 5209| 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.| 5210| 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. | 5211 5212**Example** 5213 5214```ts 5215windowClass.off('systemAvoidAreaChange'); 5216``` 5217 5218### isSupportWideGamut<sup>(deprecated)</sup> 5219 5220isSupportWideGamut(callback: AsyncCallback<boolean>): void 5221 5222Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 5223 5224> **NOTE** 5225> 5226> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9) instead. 5227 5228**System capability**: SystemCapability.WindowManager.WindowManager.Core 5229 5230**Parameters** 5231 5232| Name | Type | Mandatory| Description | 5233| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 5234| 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.| 5235 5236**Example** 5237 5238```ts 5239import { BusinessError } from '@ohos.base'; 5240 5241windowClass.isSupportWideGamut((err: BusinessError, data) => { 5242 const errCode: number = err.code; 5243 if (errCode) { 5244 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 5245 return; 5246 } 5247 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 5248}); 5249``` 5250 5251### isSupportWideGamut<sup>(deprecated)</sup> 5252 5253isSupportWideGamut(): Promise<boolean> 5254 5255Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 5256 5257> **NOTE** 5258> 5259> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1) instead. 5260 5261**System capability**: SystemCapability.WindowManager.WindowManager.Core 5262 5263**Return value** 5264 5265| Type | Description | 5266| ---------------------- | ------------------------------------------------------------ | 5267| 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.| 5268 5269**Example** 5270 5271```ts 5272import { BusinessError } from '@ohos.base'; 5273 5274let promise = windowClass.isSupportWideGamut(); 5275promise.then((data) => { 5276 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 5277}).catch((err: BusinessError) => { 5278 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 5279}); 5280``` 5281 5282### setColorSpace<sup>(deprecated)</sup> 5283 5284setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5285 5286Sets a color space for this window. This API uses an asynchronous callback to return the result. 5287 5288> **NOTE** 5289> 5290> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9) instead. 5291 5292**System capability**: SystemCapability.WindowManager.WindowManager.Core 5293 5294**Parameters** 5295 5296| Name | Type | Mandatory| Description | 5297| ---------- | ------------------------- | ---- | ------------ | 5298| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set.| 5299| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5300 5301**Example** 5302 5303```ts 5304import { BusinessError } from '@ohos.base'; 5305 5306windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 5307 const errCode: number = err.code; 5308 if (errCode) { 5309 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 5310 return; 5311 } 5312 console.info('Succeeded in setting window colorspace.'); 5313}); 5314``` 5315 5316### setColorSpace<sup>(deprecated)</sup> 5317 5318setColorSpace(colorSpace:ColorSpace): Promise<void> 5319 5320Sets a color space for this window. This API uses a promise to return the result. 5321 5322> **NOTE** 5323> 5324> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9-1) instead. 5325 5326**System capability**: SystemCapability.WindowManager.WindowManager.Core 5327 5328**Parameters** 5329 5330| Name | Type | Mandatory| Description | 5331| ---------- | ------------------------- | ---- | -------------- | 5332| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set.| 5333 5334**Return value** 5335 5336| Type | Description | 5337| ------------------- | ------------------------- | 5338| Promise<void> | Promise that returns no value.| 5339 5340**Example** 5341 5342```ts 5343import { BusinessError } from '@ohos.base'; 5344 5345let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 5346promise.then(() => { 5347 console.info('Succeeded in setting window colorspace.'); 5348}).catch((err: BusinessError) => { 5349 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 5350}); 5351``` 5352 5353### getColorSpace<sup>(deprecated)</sup> 5354 5355getColorSpace(callback: AsyncCallback<ColorSpace>): void 5356 5357Obtains the color space of this window. This API uses an asynchronous callback to return the result. 5358 5359> **NOTE** 5360> 5361> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 5362 5363**System capability**: SystemCapability.WindowManager.WindowManager.Core 5364 5365**Parameters** 5366 5367| Name | Type | Mandatory| Description | 5368| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 5369| 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.| 5370 5371**Example** 5372 5373```ts 5374import { BusinessError } from '@ohos.base'; 5375 5376windowClass.getColorSpace((err: BusinessError, data) => { 5377 const errCode: number = err.code; 5378 if (errCode) { 5379 console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err)); 5380 return; 5381 } 5382 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 5383}); 5384``` 5385 5386### getColorSpace<sup>(deprecated)</sup> 5387 5388getColorSpace(): Promise<ColorSpace> 5389 5390Obtains the color space of this window. This API uses a promise to return the result. 5391 5392> **NOTE** 5393> 5394> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 5395 5396**System capability**: SystemCapability.WindowManager.WindowManager.Core 5397 5398**Return value** 5399 5400| Type | Description | 5401| ---------------------------------------- | ------------------------------- | 5402| Promise<[ColorSpace](#colorspace8)> | Promise used to return the current color space.| 5403 5404**Example** 5405 5406```ts 5407import { BusinessError } from '@ohos.base'; 5408 5409let promise = windowClass.getColorSpace(); 5410promise.then((data) => { 5411 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 5412}).catch((err: BusinessError) => { 5413 console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err)); 5414}); 5415``` 5416 5417### setBackgroundColor<sup>(deprecated)</sup> 5418 5419setBackgroundColor(color: string, callback: AsyncCallback<void>): void 5420 5421Sets 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. 5422 5423> **NOTE** 5424> 5425> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 5426 5427**System capability**: SystemCapability.WindowManager.WindowManager.Core 5428 5429**Parameters** 5430 5431| Name | Type | Mandatory| Description | 5432| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 5433| 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**.| 5434| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5435 5436**Example** 5437 5438```ts 5439import { BusinessError } from '@ohos.base'; 5440 5441let color: string = '#00ff33'; 5442windowClass.setBackgroundColor(color, (err: BusinessError) => { 5443 const errCode: number = err.code; 5444 if (errCode) { 5445 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 5446 return; 5447 } 5448 console.info('Succeeded in setting the background color.'); 5449}); 5450``` 5451 5452### setBackgroundColor<sup>(deprecated)</sup> 5453 5454setBackgroundColor(color: string): Promise<void> 5455 5456Sets 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. 5457 5458> **NOTE** 5459> 5460> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 5461 5462**System capability**: SystemCapability.WindowManager.WindowManager.Core 5463 5464**Parameters** 5465 5466| Name| Type | Mandatory| Description | 5467| ------ | ------ | ---- | ------------------------------------------------------------ | 5468| 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**.| 5469 5470**Return value** 5471 5472| Type | Description | 5473| ------------------- | ------------------------- | 5474| Promise<void> | Promise that returns no value.| 5475 5476**Example** 5477 5478```ts 5479import { BusinessError } from '@ohos.base'; 5480 5481let color: string = '#00ff33'; 5482let promise = windowClass.setBackgroundColor(color); 5483promise.then(() => { 5484 console.info('Succeeded in setting the background color.'); 5485}).catch((err: BusinessError) => { 5486 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 5487}); 5488``` 5489 5490### setBrightness<sup>(deprecated)</sup> 5491 5492setBrightness(brightness: number, callback: AsyncCallback<void>): void 5493 5494Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 5495 5496When 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. 5497 5498> **NOTE** 5499> 5500> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9) instead. 5501 5502**System capability**: SystemCapability.WindowManager.WindowManager.Core 5503 5504**Parameters** 5505 5506| Name | Type | Mandatory| Description | 5507| ---------- | ------------------------- | ---- |---------------------------------------| 5508| 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.| 5509| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5510 5511**Example** 5512 5513```ts 5514import { BusinessError } from '@ohos.base'; 5515 5516let brightness: number = 1; 5517windowClass.setBrightness(brightness, (err: BusinessError) => { 5518 const errCode: number = err.code; 5519 if (errCode) { 5520 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 5521 return; 5522 } 5523 console.info('Succeeded in setting the brightness.'); 5524}); 5525``` 5526 5527### setBrightness<sup>(deprecated)</sup> 5528 5529setBrightness(brightness: number): Promise<void> 5530 5531Sets the screen brightness for this window. This API uses a promise to return the result. 5532 5533When 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. 5534 5535> **NOTE** 5536> 5537> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9-1) instead. 5538 5539**System capability**: SystemCapability.WindowManager.WindowManager.Core 5540 5541**Parameters** 5542 5543| Name | Type | Mandatory| Description | 5544| ---------- | ------ | ---- |------------------------------------------| 5545| 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.| 5546 5547**Return value** 5548 5549| Type | Description | 5550| ------------------- | ------------------------- | 5551| Promise<void> | Promise that returns no value.| 5552 5553**Example** 5554 5555```ts 5556import { BusinessError } from '@ohos.base'; 5557 5558let brightness: number = 1; 5559let promise = windowClass.setBrightness(brightness); 5560promise.then(() => { 5561 console.info('Succeeded in setting the brightness.'); 5562}).catch((err: BusinessError) => { 5563 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 5564}); 5565``` 5566 5567### setDimBehind<sup>(deprecated)</sup> 5568 5569setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 5570 5571Sets the dimness of the window that is not on top. This API uses an asynchronous callback to return the result. 5572 5573> **NOTE** 5574> 5575> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 5576 5577**System capability**: SystemCapability.WindowManager.WindowManager.Core 5578 5579**Parameters** 5580 5581| Name | Type | Mandatory| Description | 5582| -------------- | ------------------------- | ---- |----------------------------------------| 5583| 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.| 5584| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5585 5586**Example** 5587 5588```ts 5589import { BusinessError } from '@ohos.base'; 5590 5591windowClass.setDimBehind(0.5, (err: BusinessError) => { 5592 const errCode: number = err.code; 5593 if (errCode) { 5594 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 5595 return; 5596 } 5597 console.info('Succeeded in setting the dimness.'); 5598}); 5599``` 5600 5601### setDimBehind<sup>(deprecated)</sup> 5602 5603setDimBehind(dimBehindValue: number): Promise<void> 5604 5605Sets the dimness of the window that is not on top. This API uses a promise to return the result. 5606 5607> **NOTE** 5608> 5609> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 5610 5611**System capability**: SystemCapability.WindowManager.WindowManager.Core 5612 5613**Parameters** 5614 5615| Name | Type | Mandatory| Description | 5616| -------------- | ------ | ---- | -------------------------------------------------- | 5617| dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value **1** indicates the dimmest.| 5618 5619**Return value** 5620 5621| Type | Description | 5622| ------------------- | ------------------------- | 5623| Promise<void> | Promise that returns no value.| 5624 5625**Example** 5626 5627```ts 5628import { BusinessError } from '@ohos.base'; 5629 5630let promise = windowClass.setDimBehind(0.5); 5631promise.then(() => { 5632 console.info('Succeeded in setting the dimness.'); 5633}).catch((err: BusinessError) => { 5634 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 5635}); 5636``` 5637 5638### setFocusable<sup>(deprecated)</sup> 5639 5640setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5641 5642Sets whether this window can gain focus. This API uses an asynchronous callback to return the result. 5643 5644> **NOTE** 5645> 5646> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9) instead. 5647 5648**System capability**: SystemCapability.WindowManager.WindowManager.Core 5649 5650**Parameters** 5651 5652| Name | Type | Mandatory| Description | 5653| ----------- | ------------------------- | ---- | ---------------------------- | 5654| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite.| 5655| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5656 5657**Example** 5658 5659```ts 5660import { BusinessError } from '@ohos.base'; 5661 5662let isFocusable: boolean = true; 5663windowClass.setFocusable(isFocusable, (err: BusinessError) => { 5664 const errCode: number = err.code; 5665 if (errCode) { 5666 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 5667 return; 5668 } 5669 console.info('Succeeded in setting the window to be focusable.'); 5670}); 5671``` 5672 5673### setFocusable<sup>(deprecated)</sup> 5674 5675setFocusable(isFocusable: boolean): Promise<void> 5676 5677Sets whether this window can gain focus. This API uses a promise to return the result. 5678 5679> **NOTE** 5680> 5681> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9-1) instead. 5682 5683**System capability**: SystemCapability.WindowManager.WindowManager.Core 5684 5685**Parameters** 5686 5687| Name | Type | Mandatory| Description | 5688| ----------- | ------- | ---- | ---------------------------- | 5689| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite.| 5690 5691**Return value** 5692 5693| Type | Description | 5694| ------------------- | ------------------------- | 5695| Promise<void> | Promise that returns no value.| 5696 5697**Example** 5698 5699```ts 5700import { BusinessError } from '@ohos.base'; 5701 5702let isFocusable: boolean = true; 5703let promise = windowClass.setFocusable(isFocusable); 5704promise.then(() => { 5705 console.info('Succeeded in setting the window to be focusable.'); 5706}).catch((err: BusinessError) => { 5707 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 5708}); 5709``` 5710 5711### setKeepScreenOn<sup>(deprecated)</sup> 5712 5713setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5714 5715Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 5716 5717> **NOTE** 5718> 5719> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9) instead. 5720 5721**System capability**: SystemCapability.WindowManager.WindowManager.Core 5722 5723**Parameters** 5724 5725| Name | Type | Mandatory| Description | 5726| -------------- | ------------------------- | ---- | ------------------------ | 5727| 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.| 5728| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5729 5730**Example** 5731 5732```ts 5733import { BusinessError } from '@ohos.base'; 5734 5735let isKeepScreenOn: boolean = true; 5736windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 5737 const errCode: number = err.code; 5738 if (errCode) { 5739 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 5740 return; 5741 } 5742 console.info('Succeeded in setting the screen to be always on.'); 5743}); 5744``` 5745 5746### setKeepScreenOn<sup>(deprecated)</sup> 5747 5748setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5749 5750Sets whether to keep the screen always on. This API uses a promise to return the result. 5751 5752> **NOTE** 5753> 5754> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9-1) instead. 5755 5756**System capability**: SystemCapability.WindowManager.WindowManager.Core 5757 5758**Parameters** 5759 5760| Name | Type | Mandatory| Description | 5761| -------------- | ------- | ---- | ------------------------ | 5762| 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.| 5763 5764**Return value** 5765 5766| Type | Description | 5767| ------------------- | ------------------------- | 5768| Promise<void> | Promise that returns no value.| 5769 5770**Example** 5771 5772```ts 5773import { BusinessError } from '@ohos.base'; 5774 5775let isKeepScreenOn: boolean = true; 5776let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 5777promise.then(() => { 5778 console.info('Succeeded in setting the screen to be always on.'); 5779}).catch((err: BusinessError) => { 5780 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 5781}); 5782``` 5783 5784### setOutsideTouchable<sup>(deprecated)</sup> 5785 5786setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 5787 5788Sets whether the area outside the subwindow is touchable. This API uses an asynchronous callback to return the result. 5789 5790> **NOTE** 5791> 5792> This API is supported since API version 7 and deprecated since API version 9. 5793> 5794> Since API version 9, the area outside the subwindow is touchable by default. This API is no longer supported and no substitute API is provided. 5795 5796**System capability**: SystemCapability.WindowManager.WindowManager.Core 5797 5798**Parameters** 5799 5800| Name | Type | Mandatory| Description | 5801| --------- | ------------------------- | ---- | ---------------- | 5802| touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value **true** means the area outside the subwindow is touchable, and **false** means the opposite.| 5803| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5804 5805**Example** 5806 5807```ts 5808import { BusinessError } from '@ohos.base'; 5809 5810if (!windowClass) { 5811 console.info('Failed to load the content. Cause: windowClass is null'); 5812} 5813else { 5814 (windowClass as window.Window).setOutsideTouchable(true, (err: BusinessError) => { 5815 const errCode: number = err.code; 5816 if (errCode) { 5817 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 5818 return; 5819 } 5820 console.info('Succeeded in setting the area to be touchable.'); 5821 }); 5822} 5823``` 5824 5825### setOutsideTouchable<sup>(deprecated)</sup> 5826 5827setOutsideTouchable(touchable: boolean): Promise<void> 5828 5829Sets whether the area outside the subwindow is touchable. This API uses a promise to return the result. 5830 5831> **NOTE** 5832> 5833> This API is supported since API version 7 and deprecated since API version 9. 5834> 5835> Since API version 9, the area outside the subwindow is touchable by default. This API is no longer supported and no substitute API is provided. 5836 5837**System capability**: SystemCapability.WindowManager.WindowManager.Core 5838 5839**Parameters** 5840 5841| Name | Type | Mandatory| Description | 5842| --------- | ------- | ---- | ---------------- | 5843| touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value **true** means the area outside the subwindow is touchable, and **false** means the opposite.| 5844 5845**Return value** 5846 5847| Type | Description | 5848| ------------------- | ------------------------- | 5849| Promise<void> | Promise that returns no value.| 5850 5851**Example** 5852 5853```ts 5854import { BusinessError } from '@ohos.base'; 5855 5856if (!windowClass) { 5857 console.info('Failed to load the content. Cause: windowClass is null'); 5858} 5859else { 5860let promise = (windowClass as window.Window).setOutsideTouchable(true); 5861promise.then(() => { 5862 console.info('Succeeded in setting the area to be touchable.'); 5863}).catch((err: BusinessError) => { 5864 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 5865}); 5866} 5867``` 5868 5869### setPrivacyMode<sup>(deprecated)</sup> 5870 5871setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 5872 5873Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 5874 5875A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5876 5877> **NOTE** 5878> 5879> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9) instead. 5880 5881**System capability**: SystemCapability.WindowManager.WindowManager.Core 5882 5883**Parameters** 5884 5885| Name | Type | Mandatory| Description | 5886| ------------- | ------------------------- | ---- | -------------------- | 5887| 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.| 5888| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5889 5890**Example** 5891 5892```ts 5893import { BusinessError } from '@ohos.base'; 5894 5895let isPrivacyMode: boolean = true; 5896windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 5897 const errCode: number = err.code; 5898 if (errCode) { 5899 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 5900 return; 5901 } 5902 console.info('Succeeded in setting the window to privacy mode.'); 5903}); 5904``` 5905 5906### setPrivacyMode<sup>(deprecated)</sup> 5907 5908setPrivacyMode(isPrivacyMode: boolean): Promise<void> 5909 5910Sets whether this window is in privacy mode. This API uses a promise to return the result. 5911 5912A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5913 5914> **NOTE** 5915> 5916> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9-1) instead. 5917 5918**System capability**: SystemCapability.WindowManager.WindowManager.Core 5919 5920**Parameters** 5921 5922| Name | Type | Mandatory| Description | 5923| ------------- | ------- | ---- | -------------------- | 5924| 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.| 5925 5926**Return value** 5927 5928| Type | Description | 5929| ------------------- | ------------------------- | 5930| Promise<void> | Promise that returns no value.| 5931 5932**Example** 5933 5934```ts 5935import { BusinessError } from '@ohos.base'; 5936 5937let isPrivacyMode: boolean = true; 5938let promise = windowClass.setPrivacyMode(isPrivacyMode); 5939promise.then(() => { 5940 console.info('Succeeded in setting the window to privacy mode.'); 5941}).catch((err: BusinessError) => { 5942 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 5943}); 5944``` 5945 5946### setTouchable<sup>(deprecated)</sup> 5947 5948setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 5949 5950Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 5951 5952> **NOTE** 5953> 5954> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9) instead. 5955 5956**System capability**: SystemCapability.WindowManager.WindowManager.Core 5957 5958**Parameters** 5959 5960| Name | Type | Mandatory| Description | 5961| ----------- | ------------------------- | ---- | -------------------- | 5962| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 5963| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5964 5965**Example** 5966 5967```ts 5968import { BusinessError } from '@ohos.base'; 5969 5970let isTouchable = true; 5971if (!windowClass) { 5972 console.info('Failed to load the content. Cause: windowClass is null'); 5973} 5974else { 5975 (windowClass as window.Window).setTouchable(isTouchable, (err: BusinessError) => { 5976 const errCode: number = err.code; 5977 if (errCode) { 5978 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 5979 return; 5980 } 5981 console.info('Succeeded in setting the window to be touchable.'); 5982 }); 5983} 5984``` 5985 5986### setTouchable<sup>(deprecated)</sup> 5987 5988setTouchable(isTouchable: boolean): Promise<void> 5989 5990Sets whether this window is touchable. This API uses a promise to return the result. 5991 5992> **NOTE** 5993> 5994> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9-1) instead. 5995 5996**System capability**: SystemCapability.WindowManager.WindowManager.Core 5997 5998**Parameters** 5999 6000| Name | Type | Mandatory| Description | 6001| ----------- | ------- | ---- | -------------------- | 6002| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 6003 6004**Return value** 6005 6006| Type | Description | 6007| ------------------- | ------------------------- | 6008| Promise<void> | Promise that returns no value.| 6009 6010**Example** 6011 6012```ts 6013import { BusinessError } from '@ohos.base'; 6014 6015let isTouchable = true; 6016let promise = windowClass.setTouchable(isTouchable); 6017promise.then(() => { 6018 console.info('Succeeded in setting the window to be touchable.'); 6019}).catch((err: BusinessError) => { 6020 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 6021}); 6022``` 6023 6024## WindowStageEventType<sup>9+</sup> 6025 6026Describes the lifecycle of a window stage. 6027 6028**Model restriction**: This API can be used only in the stage model. 6029 6030**System capability**: SystemCapability.WindowManager.WindowManager.Core 6031 6032| Name | Value| Description | 6033| ---------- | ------ | ---------- | 6034| SHOWN | 1 | The window stage is running in the foreground.| 6035| ACTIVE | 2 | The window stage gains focus.| 6036| INACTIVE | 3 | The window stage loses focus.| 6037| HIDDEN | 4 | The window stage is running in the background.| 6038| RESUMED<sup>11+</sup> | 5 | The window stage is interactive in the foreground. If the user opens the Recents screen when an application is running in the foreground, the application becomes non-interactive. When the user switches back to the application, the application becomes interactive.| 6039| PAUSED<sup>11+</sup> | 6 | The window stage is non-interactive in the foreground. If the user opens the Recents screen when an application is running in the foreground, the application becomes non-interactive. When the user switches back to the application, the application becomes interactive.| 6040 6041## SubWindowOptions<sup>11+</sup> 6042 6043Defines the parameters used for creating a subwindow. 6044 6045**System capability**: SystemCapability.Window.SessionManager 6046 6047| Name | Type | Readable| Writable| Description | 6048| ---------- | ---- | ---- | ---- | ----------- | 6049| title | string | No| Yes| Title of the subwindow. | 6050| decorEnabled | boolean | No| Yes| Whether to display decorations in the subwindow. The value **true** means to display decorations, and **false** means the opposite. | 6051 6052 6053## WindowStage<sup>9+</sup> 6054 6055Implements a window manager, which manages each basic window unit, that is, [Window](#window) instance. 6056 6057Before 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. 6058 6059### getMainWindow<sup>9+</sup> 6060 6061getMainWindow(callback: AsyncCallback<Window>): void 6062 6063Obtains the main window of this window stage. This API uses an asynchronous callback to return the result. 6064 6065**Model restriction**: This API can be used only in the stage model. 6066 6067**System capability**: SystemCapability.WindowManager.WindowManager.Core 6068 6069**Parameters** 6070 6071| Name | Type | Mandatory| Description | 6072| -------- | -------------------------------------- | ---- | --------------------------------------------- | 6073| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the main window.| 6074 6075**Error codes** 6076 6077For details about the error codes, see [Window Error Codes](errorcode-window.md). 6078 6079| ID| Error Message| 6080| ------- | ------------------------------ | 6081| 1300002 | This window state is abnormal. | 6082| 1300005 | This window stage is abnormal. | 6083 6084**Example** 6085 6086```ts 6087import UIAbility from '@ohos.app.ability.UIAbility'; 6088import window from '@ohos.window'; 6089import { BusinessError } from '@ohos.base'; 6090 6091export default class EntryAbility extends UIAbility { 6092 // ... 6093 6094 onWindowStageCreate(windowStage: window.WindowStage) { 6095 console.log('onWindowStageCreate'); 6096 let windowClass: window.Window | undefined = undefined; 6097 windowStage.getMainWindow((err: BusinessError, data) => { 6098 const errCode: number = err.code; 6099 if (errCode) { 6100 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 6101 return; 6102 } 6103 windowClass = data; 6104 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 6105 }); 6106 } 6107}; 6108``` 6109 6110### getMainWindow<sup>9+</sup> 6111 6112getMainWindow(): Promise<Window> 6113 6114Obtains the main window of this window stage. This API uses a promise to return the result. 6115 6116**Model restriction**: This API can be used only in the stage model. 6117 6118**System capability**: SystemCapability.WindowManager.WindowManager.Core 6119 6120**Return value** 6121 6122| Type | Description | 6123| -------------------------------- | ------------------------------------------------ | 6124| Promise<[Window](#window)> | Promise used to return the main window.| 6125 6126**Error codes** 6127 6128For details about the error codes, see [Window Error Codes](errorcode-window.md). 6129 6130| ID| Error Message| 6131| ------- | ------------------------------ | 6132| 1300002 | This window state is abnormal. | 6133| 1300005 | This window stage is abnormal. | 6134 6135**Example** 6136 6137```ts 6138import UIAbility from '@ohos.app.ability.UIAbility'; 6139import window from '@ohos.window'; 6140import { BusinessError } from '@ohos.base'; 6141 6142export default class EntryAbility extends UIAbility { 6143 // ... 6144 6145 onWindowStageCreate(windowStage: window.WindowStage) { 6146 console.log('onWindowStageCreate'); 6147 let windowClass: window.Window | undefined = undefined; 6148 let promise = windowStage.getMainWindow(); 6149 promise.then((data) => { 6150 windowClass = data; 6151 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 6152 }).catch((err: BusinessError) => { 6153 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 6154 }); 6155 } 6156}; 6157``` 6158 6159### getMainWindowSync<sup>9+</sup> 6160 6161getMainWindowSync(): Window 6162 6163Obtains the main window of this window stage. 6164 6165**Model restriction**: This API can be used only in the stage model. 6166 6167**System capability**: SystemCapability.WindowManager.WindowManager.Core 6168 6169**Return value** 6170 6171| Type| Description| 6172| ----------------- | --------------------------------- | 6173| [Window](#window) | return the main window.| 6174 6175**Error codes** 6176 6177For details about the error codes, see [Window Error Codes](errorcode-window.md). 6178 6179| ID| Error Message| 6180| ------- | ------------------------------ | 6181| 1300002 | This window state is abnormal. | 6182| 1300005 | This window stage is abnormal. | 6183 6184**Example** 6185 6186```ts 6187import UIAbility from '@ohos.app.ability.UIAbility'; 6188import window from '@ohos.window'; 6189 6190export default class EntryAbility extends UIAbility { 6191 // ... 6192 6193 onWindowStageCreate(windowStage: window.WindowStage) { 6194 console.log('onWindowStageCreate'); 6195 try { 6196 let windowClass = windowStage.getMainWindowSync(); 6197 } catch (exception) { 6198 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); 6199 } 6200 } 6201}; 6202``` 6203 6204### createSubWindow<sup>9+</sup> 6205 6206createSubWindow(name: string, callback: AsyncCallback<Window>): void 6207 6208Creates a subwindow for this window stage. This API uses an asynchronous callback to return the result. 6209 6210**Model restriction**: This API can be used only in the stage model. 6211 6212**System capability**: SystemCapability.WindowManager.WindowManager.Core 6213 6214**Parameters** 6215 6216| Name | Type | Mandatory| Description | 6217| -------- | -------------------------------------- | ---- | --------------------------------------------- | 6218| name | string | Yes | Name of the subwindow. | 6219| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow.| 6220 6221**Error codes** 6222 6223For details about the error codes, see [Window Error Codes](errorcode-window.md). 6224 6225| ID| Error Message| 6226| ------- | ------------------------------ | 6227| 1300002 | This window state is abnormal. | 6228| 1300005 | This window stage is abnormal. | 6229 6230**Example** 6231 6232```ts 6233import UIAbility from '@ohos.app.ability.UIAbility'; 6234import window from '@ohos.window'; 6235import { BusinessError } from '@ohos.base'; 6236 6237export default class EntryAbility extends UIAbility { 6238 // ... 6239 6240 onWindowStageCreate(windowStage: window.WindowStage) { 6241 console.log('onWindowStageCreate'); 6242 let windowClass: window.Window | undefined = undefined; 6243 try { 6244 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 6245 const errCode: number = err.code; 6246 if (errCode) { 6247 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 6248 return; 6249 } 6250 windowClass = data; 6251 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6252 if (!windowClass) { 6253 console.info('Failed to load the content. Cause: windowClass is null'); 6254 } 6255 else { 6256 (windowClass as window.Window).resize(500, 1000); 6257 } 6258 }); 6259 6260 } catch (exception) { 6261 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 6262 } 6263 } 6264}; 6265``` 6266### createSubWindow<sup>9+</sup> 6267 6268createSubWindow(name: string): Promise<Window> 6269 6270Creates a subwindow for this window stage. This API uses a promise to return the result. 6271 6272**Model restriction**: This API can be used only in the stage model. 6273 6274**System capability**: SystemCapability.WindowManager.WindowManager.Core 6275 6276**Parameters** 6277 6278| Name| Type | Mandatory| Description | 6279| ------ | ------ | ---- | -------------- | 6280| name | string | Yes | Name of the subwindow.| 6281 6282**Return value** 6283 6284| Type | Description | 6285| -------------------------------- | ------------------------------------------------ | 6286| Promise<[Window](#window)> | Promise used to return the subwindow.| 6287 6288**Error codes** 6289 6290For details about the error codes, see [Window Error Codes](errorcode-window.md). 6291 6292| ID| Error Message| 6293| ------- | ------------------------------ | 6294| 1300002 | This window state is abnormal. | 6295| 1300005 | This window stage is abnormal. | 6296 6297**Example** 6298 6299```ts 6300import UIAbility from '@ohos.app.ability.UIAbility'; 6301import window from '@ohos.window'; 6302import { BusinessError } from '@ohos.base'; 6303 6304export default class EntryAbility extends UIAbility { 6305 // ... 6306 6307 onWindowStageCreate(windowStage: window.WindowStage) { 6308 console.log('onWindowStageCreate'); 6309 let windowClass: window.Window | undefined = undefined; 6310 try { 6311 let promise = windowStage.createSubWindow('mySubWindow'); 6312 promise.then((data) => { 6313 windowClass = data; 6314 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6315 }).catch((err: BusinessError) => { 6316 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 6317 }); 6318 } catch (exception) { 6319 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 6320 } 6321 } 6322}; 6323``` 6324### createSubWindowWithOptions<sup>11+</sup> 6325 6326createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 6327 6328Creates a subwindow for this window stage. This API uses a promise to return the result. 6329 6330**Model restriction**: This API can be used only in the stage model. 6331 6332**System capability**: SystemCapability.Window.SessionManager 6333 6334**Parameters** 6335 6336| Name| Type | Mandatory| Description | 6337| ------ | ------ | ---- | -------------- | 6338| name | string | Yes | Name of the subwindow.| 6339| options | [SubWindowOptions](#subwindowoptions11) | Yes | Parameters used for creating the subwindow. | 6340 6341**Return value** 6342 6343| Type | Description | 6344| -------------------------------- | ------------------------------------------------ | 6345| Promise<[Window](#window)> | Promise used to return the subwindow created.| 6346 6347**Error codes** 6348 6349For details about the error codes, see [Window Error Codes](errorcode-window.md). 6350 6351| ID| Error Message| 6352| ------- | ------------------------------ | 6353| 1300002 | This window state is abnormal. | 6354| 1300005 | This window stage is abnormal. | 6355 6356**Example** 6357 6358```ts 6359import UIAbility from '@ohos.app.ability.UIAbility'; 6360import window from '@ohos.window'; 6361import { BusinessError } from '@ohos.base'; 6362 6363export default class EntryAbility extends UIAbility { 6364 // ... 6365 6366 onWindowStageCreate(windowStage: window.WindowStage) { 6367 console.info('onWindowStageCreate'); 6368 let windowClass: window.Window | undefined = undefined; 6369 try { 6370 let options : window.SubWindowOptions = { 6371 title: 'title', 6372 decorEnabled: true 6373 }; 6374 let promise = windowStage.createSubWindowWithOptions('mySubWindow', options); 6375 promise.then((data) => { 6376 windowClass = data; 6377 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6378 }).catch((err: BusinessError) => { 6379 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 6380 }); 6381 } catch (exception) { 6382 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 6383 } 6384 } 6385}; 6386``` 6387### getSubWindow<sup>9+</sup> 6388 6389getSubWindow(callback: AsyncCallback<Array<Window>>): void 6390 6391Obtains all the subwindows of this window stage. This API uses an asynchronous callback to return the result. 6392 6393**Model restriction**: This API can be used only in the stage model. 6394 6395**System capability**: SystemCapability.WindowManager.WindowManager.Core 6396 6397**Parameters** 6398 6399| Name | Type | Mandatory| Description | 6400| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 6401| callback | AsyncCallback<Array<[Window](#window)>> | Yes | Callback used to return all the subwindows.| 6402 6403**Error codes** 6404 6405For details about the error codes, see [Window Error Codes](errorcode-window.md). 6406 6407| ID| Error Message| 6408| ------- | ------------------------------ | 6409| 1300005 | This window stage is abnormal. | 6410 6411**Example** 6412 6413```ts 6414import UIAbility from '@ohos.app.ability.UIAbility'; 6415import window from '@ohos.window'; 6416import { BusinessError } from '@ohos.base'; 6417 6418export default class EntryAbility extends UIAbility { 6419 // ... 6420 6421 onWindowStageCreate(windowStage: window.WindowStage) { 6422 console.log('onWindowStageCreate'); 6423 let windowClass: window.Window[] = []; 6424 windowStage.getSubWindow((err: BusinessError, data) => { 6425 const errCode: number = err.code; 6426 if (errCode) { 6427 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 6428 return; 6429 } 6430 windowClass = data; 6431 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 6432 }); 6433 } 6434}; 6435``` 6436### getSubWindow<sup>9+</sup> 6437 6438getSubWindow(): Promise<Array<Window>> 6439 6440Obtains all the subwindows of this window stage. This API uses a promise to return the result. 6441 6442**Model restriction**: This API can be used only in the stage model. 6443 6444**System capability**: SystemCapability.WindowManager.WindowManager.Core 6445 6446**Return value** 6447 6448| Type | Description | 6449| --------------------------------------------- | ---------------------------------------------------- | 6450| Promise<Array<[Window](#window)>> | Promise used to return all the subwindows.| 6451 6452**Error codes** 6453 6454For details about the error codes, see [Window Error Codes](errorcode-window.md). 6455 6456| ID| Error Message| 6457| ------- | ------------------------------ | 6458| 1300005 | This window stage is abnormal. | 6459 6460**Example** 6461 6462```ts 6463import UIAbility from '@ohos.app.ability.UIAbility'; 6464import window from '@ohos.window'; 6465import { BusinessError } from '@ohos.base'; 6466 6467export default class EntryAbility extends UIAbility { 6468 // ... 6469 6470 onWindowStageCreate(windowStage: window.WindowStage) { 6471 console.log('onWindowStageCreate'); 6472 let windowClass: window.Window[] = []; 6473 let promise = windowStage.getSubWindow(); 6474 promise.then((data) => { 6475 windowClass = data; 6476 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 6477 }).catch((err: BusinessError) => { 6478 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 6479 }) 6480 } 6481}; 6482``` 6483### loadContent<sup>9+</sup> 6484 6485loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 6486 6487Loads the content of a page, with its path in the current project specified, to the main window of this window stage, and transfers the status attribute to the page through a local storage. This API uses an asynchronous callback to return the result. 6488 6489**Model restriction**: This API can be used only in the stage model. 6490 6491**System capability**: SystemCapability.WindowManager.WindowManager.Core 6492 6493**Parameters** 6494 6495| Name | Type | Mandatory| Description | 6496| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 6497| 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. | 6498| 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.| 6499| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6500 6501**Error codes** 6502 6503For details about the error codes, see [Window Error Codes](errorcode-window.md). 6504 6505| ID| Error Message| 6506| ------- | ------------------------------ | 6507| 1300002 | This window state is abnormal. | 6508| 1300005 | This window stage is abnormal. | 6509 6510**Example** 6511 6512```ts 6513import UIAbility from '@ohos.app.ability.UIAbility'; 6514import window from '@ohos.window'; 6515import { BusinessError } from '@ohos.base'; 6516 6517export default class EntryAbility extends UIAbility { 6518 // ... 6519 6520 storage: LocalStorage = new LocalStorage(); 6521 6522 onWindowStageCreate(windowStage: window.WindowStage) { 6523 this.storage.setOrCreate('storageSimpleProp', 121); 6524 console.log('onWindowStageCreate'); 6525 try { 6526 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 6527 const errCode: number = err.code; 6528 if (errCode) { 6529 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6530 return; 6531 } 6532 console.info('Succeeded in loading the content.'); 6533 }); 6534 } catch (exception) { 6535 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6536 } 6537 } 6538}; 6539``` 6540 6541### loadContent<sup>9+</sup> 6542 6543loadContent(path: string, storage?: LocalStorage): Promise<void> 6544 6545Loads the content of a page, with its path in the current project specified, to the main window of this window stage, and transfers the status attribute to the page through a local storage. This API uses a promise to return the result. 6546 6547**Model restriction**: This API can be used only in the stage model. 6548 6549**System capability**: SystemCapability.WindowManager.WindowManager.Core 6550 6551**Parameters** 6552 6553| Name | Type | Mandatory| Description | 6554| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 6555| 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.| 6556| 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.| 6557 6558**Return value** 6559 6560| Type | Description | 6561| ------------------- | ------------------------- | 6562| Promise<void> | Promise that returns no value.| 6563 6564**Error codes** 6565 6566For details about the error codes, see [Window Error Codes](errorcode-window.md). 6567 6568| ID| Error Message| 6569| ------- | ------------------------------ | 6570| 1300002 | This window state is abnormal. | 6571| 1300005 | This window stage is abnormal. | 6572 6573**Example** 6574 6575```ts 6576import UIAbility from '@ohos.app.ability.UIAbility'; 6577import window from '@ohos.window'; 6578import { BusinessError } from '@ohos.base'; 6579 6580export default class EntryAbility extends UIAbility { 6581 // ... 6582 6583 storage: LocalStorage = new LocalStorage(); 6584 6585 onWindowStageCreate(windowStage: window.WindowStage) { 6586 this.storage.setOrCreate('storageSimpleProp', 121); 6587 console.log('onWindowStageCreate'); 6588 try { 6589 let promise = windowStage.loadContent('pages/page2', this.storage); 6590 promise.then(() => { 6591 console.info('Succeeded in loading the content.'); 6592 }).catch((err: BusinessError) => { 6593 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6594 }); 6595 } catch (exception) { 6596 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6597 } 6598 ; 6599 } 6600}; 6601``` 6602 6603### loadContent<sup>9+</sup> 6604 6605loadContent(path: string, callback: AsyncCallback<void>): void 6606 6607Loads content from a page to this window stage. This API uses an asynchronous callback to return the result. 6608 6609**Model restriction**: This API can be used only in the stage model. 6610 6611**System capability**: SystemCapability.WindowManager.WindowManager.Core 6612 6613**Parameters** 6614 6615| Name | Type | Mandatory| Description | 6616| -------- | ------------------------- | ---- | -------------------- | 6617| 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.| 6618| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6619 6620**Error codes** 6621 6622For details about the error codes, see [Window Error Codes](errorcode-window.md). 6623 6624| ID| Error Message| 6625| ------- | ------------------------------ | 6626| 1300002 | This window state is abnormal. | 6627| 1300005 | This window stage is abnormal. | 6628 6629**Example** 6630 6631```ts 6632import UIAbility from '@ohos.app.ability.UIAbility'; 6633import window from '@ohos.window'; 6634import { BusinessError } from '@ohos.base'; 6635 6636export default class EntryAbility extends UIAbility { 6637 // ... 6638 6639 onWindowStageCreate(windowStage: window.WindowStage) { 6640 console.log('onWindowStageCreate'); 6641 try { 6642 windowStage.loadContent('pages/page2', (err: BusinessError) => { 6643 const errCode: number = err.code; 6644 if (errCode) { 6645 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6646 return; 6647 } 6648 console.info('Succeeded in loading the content.'); 6649 }); 6650 } catch (exception) { 6651 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6652 } 6653 } 6654}; 6655``` 6656 6657### loadContentByName<sup>11+</sup> 6658 6659loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 6660 6661Loads 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. 6662 6663**Model restriction**: This API can be used only in the stage model. 6664 6665**System capability**: SystemCapability.WindowManager.WindowManager.Core 6666 6667**Parameters** 6668 6669| Name | Type | Mandatory| Description | 6670| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 6671| name | string | Yes | Name of the named route page. | 6672| 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.| 6673| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6674 6675**Error codes** 6676 6677For details about the error codes, see [Window Error Codes](errorcode-window.md). 6678 6679| ID| Error Message | 6680| -------- | --------------------------------------------- | 6681| 1300002 | This window state is abnormal. | 6682| 1300003 | This window manager service works abnormally. | 6683 6684**Example** 6685 6686```ts 6687// ets/entryability/EntryAbility.ets 6688import UIAbility from '@ohos.app.ability.UIAbility'; 6689import window from '@ohos.window'; 6690import { BusinessError } from '@ohos.base'; 6691import * as Index from '../pages/Index'; // Import the named route page. 6692 6693export default class EntryAbility extends UIAbility { 6694 // ... 6695 6696 storage: LocalStorage = new LocalStorage(); 6697 6698 onWindowStageCreate(windowStage: window.WindowStage) { 6699 console.log('onWindowStageCreate'); 6700 this.storage.setOrCreate('storageSimpleProp', 121); 6701 try { 6702 windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => { 6703 const errCode: number = err.code; 6704 if (errCode) { 6705 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6706 return; 6707 } 6708 console.info('Succeeded in loading the content.'); 6709 }); 6710 } catch (exception) { 6711 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6712 } 6713 } 6714}; 6715``` 6716```ts 6717// ets/pages/Index.ets 6718export const entryName : string = 'Index'; 6719@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 6720@Component 6721export struct Index { 6722 @State message: string = 'Hello World' 6723 build() { 6724 Row() { 6725 Column() { 6726 Text(this.message) 6727 .fontSize(50) 6728 .fontWeight(FontWeight.Bold) 6729 } 6730 .width('100%') 6731 } 6732 .height('100%') 6733 } 6734} 6735``` 6736 6737### loadContentByName<sup>11+</sup> 6738 6739loadContentByName(name: string, callback: AsyncCallback<void>): void 6740 6741Loads 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. 6742 6743**Model restriction**: This API can be used only in the stage model. 6744 6745**System capability**: SystemCapability.WindowManager.WindowManager.Core 6746 6747**Parameters** 6748 6749| Name | Type | Mandatory| Description | 6750| -------- | ------------------------- | ---- | ---------------- | 6751| name | string | Yes | Name of the named route page.| 6752| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6753 6754**Error codes** 6755 6756For details about the error codes, see [Window Error Codes](errorcode-window.md). 6757 6758| ID| Error Message | 6759| -------- | --------------------------------------------- | 6760| 1300002 | This window state is abnormal. | 6761| 1300003 | This window manager service works abnormally. | 6762 6763**Example** 6764 6765```ts 6766// ets/entryability/EntryAbility.ets 6767import UIAbility from '@ohos.app.ability.UIAbility'; 6768import window from '@ohos.window'; 6769import { BusinessError } from '@ohos.base'; 6770import * as Index from '../pages/Index'; // Import the named route page. 6771 6772export default class EntryAbility extends UIAbility { 6773 // ... 6774 6775 onWindowStageCreate(windowStage: window.WindowStage) { 6776 console.log('onWindowStageCreate'); 6777 try { 6778 windowStage.loadContentByName(Index.entryName, (err: BusinessError) => { 6779 const errCode: number = err.code; 6780 if (errCode) { 6781 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6782 return; 6783 } 6784 console.info('Succeeded in loading the content.'); 6785 }); 6786 } catch (exception) { 6787 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6788 } 6789 } 6790}; 6791``` 6792```ts 6793// ets/pages/Index.ets 6794export const entryName : string = 'Index'; 6795@Entry({routeName: entryName}) 6796@Component 6797export struct Index { 6798 @State message: string = 'Hello World' 6799 build() { 6800 Row() { 6801 Column() { 6802 Text(this.message) 6803 .fontSize(50) 6804 .fontWeight(FontWeight.Bold) 6805 } 6806 .width('100%') 6807 } 6808 .height('100%') 6809 } 6810} 6811``` 6812 6813### loadContentByName<sup>11+</sup> 6814 6815loadContentByName(name: string, storage?: LocalStorage): Promise<void>; 6816 6817Loads 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. 6818 6819**Model restriction**: This API can be used only in the stage model. 6820 6821**System capability**: SystemCapability.WindowManager.WindowManager.Core 6822 6823**Parameters** 6824 6825| Name | Type | Mandatory| Description | 6826| ------- | ------------ | ---- | ------------------------------------------------------------ | 6827| name | string | Yes | Name of the named route page. | 6828| storage | LocalStorage | No | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 6829 6830**Error codes** 6831 6832For details about the error codes, see [Window Error Codes](errorcode-window.md). 6833 6834| ID| Error Message | 6835| -------- | --------------------------------------------- | 6836| 1300002 | This window state is abnormal. | 6837| 1300003 | This window manager service works abnormally. | 6838 6839**Example** 6840 6841```ts 6842// ets/entryability/EntryAbility.ets 6843import UIAbility from '@ohos.app.ability.UIAbility'; 6844import window from '@ohos.window'; 6845import { BusinessError } from '@ohos.base'; 6846import * as Index from '../pages/Index'; // Import the named route page. 6847 6848export default class EntryAbility extends UIAbility { 6849 // ... 6850 6851 storage: LocalStorage = new LocalStorage(); 6852 6853 onWindowStageCreate(windowStage: window.WindowStage) { 6854 console.log('onWindowStageCreate'); 6855 this.storage.setOrCreate('storageSimpleProp', 121); 6856 try { 6857 let promise = windowStage.loadContentByName(Index.entryName, this.storage); 6858 promise.then(() => { 6859 console.info('Succeeded in loading the content.'); 6860 }).catch((err: BusinessError) => { 6861 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6862 }); 6863 } catch (exception) { 6864 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6865 } 6866 } 6867}; 6868``` 6869```ts 6870// ets/pages/Index.ets 6871export const entryName : string = 'Index'; 6872@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 6873@Component 6874export struct Index { 6875 @State message: string = 'Hello World' 6876 build() { 6877 Row() { 6878 Column() { 6879 Text(this.message) 6880 .fontSize(50) 6881 .fontWeight(FontWeight.Bold) 6882 } 6883 .width('100%') 6884 } 6885 .height('100%') 6886 } 6887} 6888``` 6889 6890### on('windowStageEvent')<sup>9+</sup> 6891 6892on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 6893 6894Subscribes to the window stage lifecycle change event. 6895 6896**Model restriction**: This API can be used only in the stage model. 6897 6898**System capability**: SystemCapability.WindowManager.WindowManager.Core 6899 6900**Parameters** 6901 6902| Name | Type | Mandatory| Description | 6903| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6904| type | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event.| 6905| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | Yes | Callback used to return the window stage lifecycle state. | 6906 6907**Error codes** 6908 6909For details about the error codes, see [Window Error Codes](errorcode-window.md). 6910 6911| ID| Error Message| 6912| ------- | ------------------------------ | 6913| 1300002 | This window state is abnormal. | 6914| 1300005 | This window stage is abnormal. | 6915 6916**Example** 6917 6918```ts 6919import UIAbility from '@ohos.app.ability.UIAbility'; 6920import window from '@ohos.window'; 6921 6922export default class EntryAbility extends UIAbility { 6923 // ... 6924 6925 onWindowStageCreate(windowStage: window.WindowStage) { 6926 console.log('onWindowStageCreate'); 6927 try { 6928 windowStage.on('windowStageEvent', (data) => { 6929 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 6930 JSON.stringify(data)); 6931 }); 6932 } catch (exception) { 6933 console.error('Failed to enable the listener for window stage event changes. Cause:' + 6934 JSON.stringify(exception)); 6935 } 6936 } 6937}; 6938``` 6939 6940### off('windowStageEvent')<sup>9+</sup> 6941 6942off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 6943 6944Unsubscribes from the window stage lifecycle change event. 6945 6946**Model restriction**: This API can be used only in the stage model. 6947 6948**System capability**: SystemCapability.WindowManager.WindowManager.Core 6949 6950**Parameters** 6951 6952| Name | Type | Mandatory| Description | 6953| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6954| type | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event.| 6955| 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. | 6956 6957**Error codes** 6958 6959For details about the error codes, see [Window Error Codes](errorcode-window.md). 6960 6961| ID| Error Message| 6962| ------- | ------------------------------ | 6963| 1300002 | This window state is abnormal. | 6964| 1300005 | This window stage is abnormal. | 6965 6966**Example** 6967 6968```ts 6969import UIAbility from '@ohos.app.ability.UIAbility'; 6970import window from '@ohos.window'; 6971 6972export default class EntryAbility extends UIAbility { 6973 // ... 6974 6975 onWindowStageCreate(windowStage: window.WindowStage) { 6976 console.log('onWindowStageCreate'); 6977 try { 6978 windowStage.off('windowStageEvent'); 6979 } catch (exception) { 6980 console.error('Failed to disable the listener for window stage event changes. Cause:' + 6981 JSON.stringify(exception)); 6982 } 6983 } 6984}; 6985``` 6986