1# Interface (Window) 2<!--Kit: ArkUI--> 3<!--Subsystem: Window--> 4<!--Owner: @waterwin--> 5<!--Designer: @nyankomiya--> 6<!--Tester: @qinliwen0417--> 7<!--Adviser: @ge-yafang--> 8 9> **NOTE** 10> 11> 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. 12 13Represents a window instance, which is the basic unit managed by the window manager. 14 15In the following API examples, you must use [getLastWindow()](arkts-apis-window-f.md#windowgetlastwindow9), [createWindow()](arkts-apis-window-f.md#windowcreatewindow9), or [findWindow()](arkts-apis-window-f.md#windowfindwindow9) to obtain a Window instance (named windowClass in this example) and then call a method in this instance. 16 17## Modules to Import 18 19```ts 20import { window } from '@kit.ArkUI'; 21``` 22 23## showWindow<sup>9+</sup> 24 25showWindow(callback: AsyncCallback<void>): void 26 27Shows this window. This API uses an asynchronous callback to return the result. This API takes effect only for a system window or an application child window. For the main window of an application, this API moves it at the top when the main window is already displayed. 28 29**System capability**: SystemCapability.WindowManager.WindowManager.Core 30 31**Atomic service API**: This API can be used in atomic services since API version 11. 32 33**Parameters** 34 35| Name| Type| Mandatory| Description| 36| -------- | ------------------------- | -- | --------- | 37| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 38 39**Error codes** 40 41For details about the error codes, see [Window Error Codes](errorcode-window.md). 42 43| ID| Error Message| 44| ------- | ------------------------------ | 45| 1300002 | This window state is abnormal. | 46 47**Example** 48 49```ts 50import { BusinessError } from '@kit.BasicServicesKit'; 51 52windowClass.showWindow((err: BusinessError) => { 53 const errCode: number = err.code; 54 if (errCode) { 55 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 56 return; 57 } 58 console.info('Succeeded in showing the window.'); 59}); 60``` 61 62## showWindow<sup>9+</sup> 63 64showWindow(): Promise<void> 65 66Shows this window. This API uses a promise to return the result. This API takes effect only for a system window or an application child window. For the main window of an application, this API moves it at the top when the main window is already displayed. 67 68**System capability**: SystemCapability.WindowManager.WindowManager.Core 69 70**Atomic service API**: This API can be used in atomic services since API version 11. 71 72**Return value** 73 74| Type| Description| 75| ------------------- | ----------------------- | 76| Promise<void> | Promise that returns no value.| 77 78**Error codes** 79 80For details about the error codes, see [Window Error Codes](errorcode-window.md). 81 82| ID| Error Message| 83| ------- | ------------------------------ | 84| 1300002 | This window state is abnormal. | 85 86**Example** 87 88```ts 89import { BusinessError } from '@kit.BasicServicesKit'; 90 91let promise = windowClass.showWindow(); 92promise.then(() => { 93 console.info('Succeeded in showing the window.'); 94}).catch((err: BusinessError) => { 95 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 96}); 97``` 98 99## showWindow<sup>20+</sup> 100 101showWindow(options: ShowWindowOptions): Promise<void> 102 103Shows this window. This API uses a promise to return the result. This API takes effect only for a system window or an application child window. For the main window of an application, this API moves it at the top when the main window is already displayed. You can pass parameters to control the window display behavior. 104 105**System capability**: SystemCapability.Window.SessionManager 106 107**Atomic service API**: This API can be used in atomic services since API version 20. 108 109**Parameters** 110 111| Name| Type| Mandatory| Description| 112| -------- | ------------------------- | -- | --------- | 113| options | [ShowWindowOptions](arkts-apis-window-i.md#showwindowoptions20) | Yes| Parameters for displaying a child window or system window.| 114 115**Return value** 116 117| Type| Description| 118| ------------------- | ----------------------- | 119| Promise<void> | Promise that returns no value.| 120 121**Error codes** 122 123For details about the error codes, see [Window Error Codes](errorcode-window.md). 124 125| ID| Error Message| 126| ------- | ------------------------------ | 127| 801 | Capability not supported. Function showWindow can not work correctly due to limited device capabilities. | 128| 1300002 | This window state is abnormal. | 129| 1300004 | Unauthorized operation. | 130| 1300016 | Parameter validation error. Possible cause: 1. The value of the parameter is out of the allowed range; 2. The length of the parameter exceeds the allowed length; 3. The parameter format is incorrect. | 131 132**Example** 133 134```ts 135// EntryAbility.ets 136import { window } from '@kit.ArkUI'; 137import { UIAbility } from '@kit.AbilityKit'; 138import { BusinessError } from '@kit.BasicServicesKit'; 139 140export default class EntryAbility extends UIAbility { 141 onWindowStageCreate(windowStage: window.WindowStage): void { 142 console.info('onWindowStageCreate'); 143 // Create a child window. 144 try { 145 windowStage.createSubWindow('subWindow').then((data) => { 146 if (data == null) { 147 console.error('Failed to create the sub window. Cause: The data is empty'); 148 return; 149 } 150 let options: window.ShowWindowOptions = { 151 focusOnShow: false 152 }; 153 try { 154 data.showWindow(options).then(() => { 155 console.info('Succeeded in showing window'); 156 }).catch((err: BusinessError) => { 157 console.error(`Failed to show window. Cause code: ${err.code}, message: ${err.message}`); 158 }); 159 } catch (exception) { 160 console.error(`Failed to show window. Cause code: ${exception.code}, message: ${exception.message}`); 161 } 162 }); 163 } catch (exception) { 164 console.error(`Failed to create the sub window. Cause code: ${exception.code}, message: ${exception.message}`); 165 } 166 } 167} 168``` 169 170## destroyWindow<sup>9+</sup> 171 172destroyWindow(callback: AsyncCallback<void>): void 173 174Destroys this window. This API uses an asynchronous callback to return the result. This API takes effect only for a system window or an application child window. 175 176**System capability**: SystemCapability.WindowManager.WindowManager.Core 177 178**Atomic service API**: This API can be used in atomic services since API version 11. 179 180**Parameters** 181 182| Name| Type| Mandatory| Description| 183| -------- | ------------------------- | -- | --------- | 184| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 185 186**Error codes** 187 188For details about the error codes, see [Window Error Codes](errorcode-window.md). 189 190| ID| Error Message| 191| ------- | -------------------------------------------- | 192| 1300002 | This window state is abnormal. | 193 194**Example** 195 196```ts 197import { BusinessError } from '@kit.BasicServicesKit'; 198 199windowClass.destroyWindow((err) => { 200 const errCode: number = err.code; 201 if (errCode) { 202 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 203 return; 204 } 205 console.info('Succeeded in destroying the window.'); 206}); 207``` 208 209## destroyWindow<sup>9+</sup> 210 211destroyWindow(): Promise<void> 212 213Destroys this window. This API uses a promise to return the result. This API takes effect only for a system window or an application child window. 214 215**System capability**: SystemCapability.WindowManager.WindowManager.Core 216 217**Atomic service API**: This API can be used in atomic services since API version 11. 218 219**Return value** 220 221| Type| Description| 222| ------------------- | ------------------------ | 223| Promise<void> | Promise that returns no value.| 224 225**Error codes** 226 227For details about the error codes, see [Window Error Codes](errorcode-window.md). 228 229| ID| Error Message| 230| ------- | -------------------------------------------- | 231| 1300002 | This window state is abnormal. | 232 233**Example** 234 235```ts 236import { BusinessError } from '@kit.BasicServicesKit'; 237 238let promise = windowClass.destroyWindow(); 239promise.then(() => { 240 console.info('Succeeded in destroying the window.'); 241}).catch((err: BusinessError) => { 242 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 243}); 244``` 245 246## moveWindowTo<sup>9+</sup> 247 248moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 249 250Moves this window. This API uses an asynchronous callback to return the result. A value is returned once the API is called successfully. However, the final effect cannot be obtained immediately from the return value. To obtain the final effect immediately, call [moveWindowToAsync()](#movewindowtoasync12). 251 252> **NOTE** 253> 254> - This API is best suited for the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). You are not advised to use it in other window modes. 255> 256> - In [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode, the window moves relative to the screen. In non-freeform window mode, the window moves relative to the parent window. 257> 258> - To move the window relative to the screen while in non-freeform window mode, call [moveWindowToGlobal()](#movewindowtoglobal15). 259> 260> - This API does not work for the main window in non-freeform window mode. 261 262**System capability**: SystemCapability.WindowManager.WindowManager.Core 263 264**Atomic service API**: This API can be used in atomic services since API version 11. 265 266**Parameters** 267 268| Name| Type| Mandatory| Description| 269| -------- | ------------------------- | -- | --------------------------------------------- | 270| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. Non-integer values are rounded down.| 271| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. Non-integer values are rounded down.| 272| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 273 274**Error codes** 275 276For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 277 278| ID| Error Message| 279| ------- | -------------------------------------------- | 280| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 281| 1300002 | This window state is abnormal. | 282| 1300003 | This window manager service works abnormally. | 283 284**Example** 285 286```ts 287import { BusinessError } from '@kit.BasicServicesKit'; 288 289try { 290 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 291 const errCode: number = err.code; 292 if (errCode) { 293 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 294 return; 295 } 296 console.info('Succeeded in moving the window.'); 297 }); 298} catch (exception) { 299 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 300} 301``` 302 303## moveWindowTo<sup>9+</sup> 304 305moveWindowTo(x: number, y: number): Promise<void> 306 307Moves this window. This API uses a promise to return the result. A value is returned once the API is called successfully. However, the final effect cannot be obtained immediately from the return value. To obtain the final effect immediately, call [moveWindowToAsync()](#movewindowtoasync12). 308 309> **NOTE** 310> 311> - This API is best suited for the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). You are not advised to use it in other window modes. 312> 313> - In [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode, the window moves relative to the screen. In non-freeform window mode, the window moves relative to the parent window. 314> 315> - To move the window relative to the screen while in non-freeform window mode, call [moveWindowToGlobal()](#movewindowtoglobal15). 316> 317> - This API does not work for the main window in non-freeform window mode. 318 319**System capability**: SystemCapability.WindowManager.WindowManager.Core 320 321**Atomic service API**: This API can be used in atomic services since API version 11. 322 323**Parameters** 324 325| Name| Type| Mandatory| Description| 326| -- | ----- | -- | --------------------------------------------- | 327| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. Non-integer values are rounded down.| 328| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. Non-integer values are rounded down.| 329 330**Return value** 331 332| Type| Description| 333| ------------------- | ------------------------ | 334| Promise<void> | Promise that returns no value.| 335 336**Error codes** 337 338For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 339 340| ID| Error Message| 341| ------- | -------------------------------------------- | 342| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 343| 1300002 | This window state is abnormal. | 344| 1300003 | This window manager service works abnormally. | 345 346**Example** 347 348```ts 349import { BusinessError } from '@kit.BasicServicesKit'; 350 351try { 352 let promise = windowClass.moveWindowTo(300, 300); 353 promise.then(() => { 354 console.info('Succeeded in moving the window.'); 355 }).catch((err: BusinessError) => { 356 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 357 }); 358} catch (exception) { 359 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 360} 361``` 362 363## moveWindowToAsync<sup>12+</sup> 364 365moveWindowToAsync(x: number, y: number): Promise<void> 366 367Moves this window. This API uses a promise to return the result. 368 369A value is returned once the call takes effect. You can use [getWindowProperties()](#getwindowproperties9) in the callback (see the code snippet below) to obtain the final effect immediately. 370 371> **NOTE** 372> 373> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 374> 375> - In [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode, the window moves relative to the screen. In non-freeform window mode, the window moves relative to the parent window. 376> 377> - This API does not work for the main window in non-freeform window mode. 378 379**System capability**: SystemCapability.Window.SessionManager 380 381**Atomic service API**: This API can be used in atomic services since API version 12. 382 383**Parameters** 384 385| Name| Type| Mandatory| Description| 386| -- | ----- | -- | --------------------------------------------- | 387| x | number | Yes| Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. Non-integer values are rounded down.| 388| y | number | Yes| Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. Non-integer values are rounded down.| 389 390**Return value** 391 392| Type| Description| 393| ------------------- | ------------------------ | 394| Promise<void> | Promise that returns no value.| 395 396**Error codes** 397 398For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 399 400| ID| Error Message| 401| ------- | -------------------------------------------- | 402| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 403| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 404| 1300002 | This window state is abnormal. | 405| 1300003 | This window manager service works abnormally. | 406| 1300010 | The operation in the current window status is invalid. | 407 408**Example** 409 410```ts 411import { BusinessError } from '@kit.BasicServicesKit'; 412 413try { 414 let promise = windowClass.moveWindowToAsync(300, 300); 415 promise.then(() => { 416 console.info('Succeeded in moving the window.'); 417 let rect = windowClass?.getWindowProperties().windowRect; 418 console.info(`Get window rect: ` + JSON.stringify(rect)); 419 }).catch((err: BusinessError) => { 420 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 421 }); 422} catch (exception) { 423 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 424} 425``` 426 427## moveWindowToAsync<sup>15+</sup> 428 429moveWindowToAsync(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 430 431Moves this window. This API uses a promise to return the result. A value is returned once the call takes effect. You can use [getWindowProperties()](#getwindowproperties9) in the callback (see the code snippet below) to obtain the final effect immediately. 432 433> **NOTE** 434> 435> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 436> 437> - In [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode, the window moves relative to the screen. In non-freeform window mode, the window moves relative to the parent window. 438> 439> - This API does not work for the main window in non-freeform window mode. 440 441**System capability**: SystemCapability.Window.SessionManager 442 443**Atomic service API**: This API can be used in atomic services since API version 15. 444 445**Parameters** 446 447| Name| Type| Mandatory| Description| 448| -- | ----- | -- | --------------------------------------------- | 449| 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. Non-integer values are rounded down.| 450| 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. Non-integer values are rounded down.| 451| moveConfiguration | [MoveConfiguration](arkts-apis-window-i.md#moveconfiguration15) | No| Window movement configuration. If this parameter is not set, the window will stay on the current display.| 452 453**Return value** 454 455| Type| Description| 456| ------------------- | ------------------------ | 457| Promise<void> | Promise that returns no value.| 458 459**Error codes** 460 461For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 462 463| ID| Error Message| 464| ------- | -------------------------------------------- | 465| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 466| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 467| 1300002 | This window state is abnormal. | 468| 1300003 | This window manager service works abnormally. | 469| 1300010 | The operation in the current window status is invalid. | 470 471**Example** 472 473```ts 474import { window } from '@kit.ArkUI'; 475import { BusinessError } from '@kit.BasicServicesKit'; 476 477try { 478 let moveConfiguration: window.MoveConfiguration = { 479 displayId: 0 480 }; 481 let promise = windowClass.moveWindowToAsync(300, 300, moveConfiguration); 482 promise.then(() => { 483 console.info('Succeeded in moving the window.'); 484 let rect = windowClass?.getWindowProperties().windowRect; 485 console.info(`Get window rect: ` + JSON.stringify(rect)); 486 }).catch((err: BusinessError) => { 487 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 488 }); 489} catch (exception) { 490 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 491} 492``` 493 494## moveWindowToGlobal<sup>13+</sup> 495 496moveWindowToGlobal(x: number, y: number): Promise<void> 497 498Moves this window based on the coordinates. This API uses a promise to return the result. A value is returned once the call takes effect. You can use [getWindowProperties()](#getwindowproperties9) in the callback (see the code snippet below) to obtain the final effect immediately. 499 500> **NOTE** 501> 502> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 503> 504> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 505 506 507**System capability**: SystemCapability.Window.SessionManager 508 509**Atomic service API**: This API can be used in atomic services since API version 13. 510 511**Parameters** 512 513| Name| Type| Mandatory| Description| 514| -- | ----- | -- | --------------------------------------------- | 515| x | number | Yes| Distance that the window moves along the x-axis, in px, with the upper-left corner of the display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. Non-integer values are rounded down.| 516| y | number | Yes| Distance that the window moves along the y-axis, in px, with the upper-left corner of the display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. Non-integer values are rounded down.| 517 518**Return value** 519 520| Type| Description| 521| ------------------- | ------------------------ | 522| Promise<void> | Promise that returns no value.| 523 524**Error codes** 525 526For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 527 528| ID| Error Message| 529| ------- | -------------------------------------------- | 530| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 531| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 532| 1300002 | This window state is abnormal. | 533| 1300003 | This window manager service works abnormally. | 534| 1300010 | The operation in the current window status is invalid. | 535 536**Example** 537 538```ts 539import { BusinessError } from '@kit.BasicServicesKit'; 540 541try { 542 let promise = windowClass.moveWindowToGlobal(300, 300); 543 promise.then(() => { 544 console.info('Succeeded in moving the window.'); 545 let rect = windowClass?.getWindowProperties().windowRect; 546 console.info(`Get window rect: ` + JSON.stringify(rect)); 547 }).catch((err: BusinessError) => { 548 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 549 }); 550} catch (exception) { 551 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 552} 553``` 554 555## moveWindowToGlobal<sup>15+</sup> 556 557moveWindowToGlobal(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 558 559Moves this window based on the coordinates. This API uses a promise to return the result. A value is returned once the call takes effect. You can use [getWindowProperties()](#getwindowproperties9) in the callback (see the code snippet below) to obtain the final effect immediately. 560 561> **NOTE** 562> 563> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 564> 565> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 566 567**System capability**: SystemCapability.Window.SessionManager 568 569**Atomic service API**: This API can be used in atomic services since API version 15. 570 571**Parameters** 572 573| Name| Type| Mandatory| Description| 574| -- | ----- | -- | --------------------------------------------- | 575| x | number | Yes| Distance that the window moves along the x-axis, in px, with the upper-left corner of the target display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. Non-integer values are rounded down.| 576| y | number | Yes| Distance that the window moves along the y-axis, in px, with the upper-left corner of the target display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. Non-integer values are rounded down.| 577| moveConfiguration | [MoveConfiguration](arkts-apis-window-i.md#moveconfiguration15) | No| Window movement configuration. If this parameter is not set, the window will stay on the current display.| 578 579**Return value** 580 581| Type| Description| 582| ------------------- | ------------------------ | 583| Promise<void> | Promise that returns no value.| 584 585**Error codes** 586 587For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 588 589| ID| Error Message| 590| ------- | -------------------------------------------- | 591| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 592| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 593| 1300002 | This window state is abnormal. | 594| 1300003 | This window manager service works abnormally. | 595| 1300010 | The operation in the current window status is invalid. | 596 597**Example** 598 599```ts 600import { window } from '@kit.ArkUI'; 601import { BusinessError } from '@kit.BasicServicesKit'; 602 603try { 604 let moveConfiguration: window.MoveConfiguration = { 605 displayId: 0 606 }; 607 let promise = windowClass.moveWindowToGlobal(300, 300, moveConfiguration); 608 promise.then(() => { 609 console.info('Succeeded in moving the window.'); 610 let rect = windowClass?.getWindowProperties().windowRect; 611 console.info(`Get window rect: ` + JSON.stringify(rect)); 612 }).catch((err: BusinessError) => { 613 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 614 }); 615} catch (exception) { 616 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 617} 618``` 619 620## moveWindowToGlobalDisplay<sup>20+</sup> 621 622moveWindowToGlobalDisplay(x: number, y: number): Promise<void> 623 624Moves the window based on the global coordinate system. (In extended screen scenarios, the upper-left corner of the primary screen is used as the origin.) This API uses a promise to return the result. 625 626> **NOTE** 627> 628> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 629> 630> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 631 632**System capability**: SystemCapability.Window.SessionManager 633 634**Parameters** 635 636| Name| Type| Mandatory| Description| 637| -- | ----- | -- | --------------------------------------------- | 638| x | number | Yes| Distance that the window moves along the x-axis, in px, with the upper-left corner of the primary display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. Non-integer values are rounded down.| 639| y | number | Yes| Distance that the window moves along the y-axis, in px, with the upper-left corner of the primary display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. Non-integer values are rounded down.| 640 641**Return value** 642 643| Type| Description| 644| ------------------- | ------------------------ | 645| Promise<void> | Promise that returns no value.| 646 647**Error codes** 648 649For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 650 651| ID| Error Message| 652| ------- | -------------------------------------------- | 653| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 654| 1300002 | This window state is abnormal. | 655| 1300003 | This window manager service works abnormally. | 656| 1300010 | The operation in the current window status is invalid. | 657| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. | 658 659**Example** 660 661```ts 662import { BusinessError } from '@kit.BasicServicesKit'; 663 664try { 665 let promise = windowClass.moveWindowToGlobalDisplay(300, 300); 666 promise.then(() => { 667 console.info('Succeeded in moving the window in global display.'); 668 }).catch((err: BusinessError) => { 669 console.error(`Failed to move the window in global display. Cause code: ${err.code}, message: ${err.message}`); 670 }); 671} catch (exception) { 672 console.error(`Failed to move the window in global display. Cause code: ${exception.code}, message: ${exception.message}`); 673} 674``` 675 676## clientToGlobalDisplay<sup>20+</sup> 677 678clientToGlobalDisplay(winX: number, winY: number): Position 679 680Converts relative coordinates (based on the upper-left corner of the current window) into global coordinates (based on the upper-left corner of the primary screen). 681 682This API is not supported in windows that are subject to display scaling, such as floating windows on phones or tablets not in free windows mode. 683 684**System capability**: SystemCapability.Window.SessionManager 685 686**Parameters** 687 688| Name| Type| Mandatory| Description| 689| -- | ----- | -- | --------------------------------------------- | 690| winX | number | Yes| Distance that the component moves along the x-axis, in px, with the upper-left corner of the current window used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. Non-integer values are rounded down.| 691| winY | number | Yes| Distance that the component moves along the y-axis, in px, with the upper-left corner of the current window used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. Non-integer values are rounded down.| 692 693**Return value** 694 695| Type| Description| 696| ------------------- | ------------------------ | 697| [Position](arkts-apis-window-i.md#position20) | Coordinates after conversion.| 698 699**Error codes** 700 701For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 702 703| ID| Error Message| 704| ------- | -------------------------------------------- | 705| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 706| 1300002 | This window state is abnormal. | 707| 1300010 | The operation in the current window status is invalid. | 708| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. | 709 710**Example** 711 712```ts 713try { 714 let position = windowClass.clientToGlobalDisplay(100, 100); 715 console.info(`Succeeded in converting the position in the current window to the position in global display. Position: ` + JSON.stringify(position)); 716} catch (exception) { 717 console.error(`Failed to convert the position. Cause code: ${exception.code}, message: ${exception.message}`); 718} 719``` 720 721## globalDisplayToClient<sup>20+</sup> 722 723globalDisplayToClient(globalDisplayX: number, globalDisplayY: number): Position 724 725Converts global coordinates (based on the upper-left corner of the primary screen) into relative coordinates (based on the upper-left corner of the current window). 726 727This API is not supported in windows that are subject to display scaling, such as floating windows on phones or tablets not in free windows mode. 728 729**System capability**: SystemCapability.Window.SessionManager 730 731**Parameters** 732 733| Name| Type| Mandatory| Description| 734| -- | ----- | -- | --------------------------------------------- | 735| globalDisplayX | number | Yes| Distance that the component moves along the x-axis, in px, with the upper-left corner of the primary display used as the origin. A positive value indicates that the window moves to the right, and a negative value indicates that the window moves to the left. The value must be an integer. Non-integer values are rounded down.| 736| globalDisplayY | number | Yes| Distance that the component moves along the y-axis, in px, with the upper-left corner of the primary display used as the origin. A positive value indicates that the window moves downwards, and a negative value indicates that the window moves upwards. The value must be an integer. Non-integer values are rounded down.| 737 738**Return value** 739 740| Type| Description| 741| ------------------- | ------------------------ | 742| [Position](arkts-apis-window-i.md#position20) | Coordinates after conversion.| 743 744**Error codes** 745 746For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 747 748| ID| Error Message| 749| ------- | -------------------------------------------- | 750| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 751| 1300002 | This window state is abnormal. | 752| 1300010 | The operation in the current window status is invalid. | 753| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. | 754 755**Example** 756 757```ts 758try { 759 let position = windowClass.globalDisplayToClient(100, 100); 760 console.info(`Succeeded in converting in the position in global display to the position in the current window. Position: ` + JSON.stringify(position)); 761} catch (exception) { 762 console.error(`Failed to convert the position. Cause code: ${exception.code}, message: ${exception.message}`); 763} 764``` 765 766## resize<sup>9+</sup> 767 768resize(width: number, height: number, callback: AsyncCallback<void>): void 769 770Changes the size of this window. This API uses an asynchronous callback to return the result. 771 772The window size is restricted by [WindowLimits](arkts-apis-window-i.md#windowlimits11). You can call [getWindowLimits](#getwindowlimits11) to find out the exact limits. 773 774The new window width and height you set must meet the following limits: 775If the window width or height is less than the minimum width or height limit, then the minimum width or height limit takes effect. 776If the window width or height is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 777 778> **NOTE** 779> 780> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 781> 782> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 783 784**System capability**: SystemCapability.WindowManager.WindowManager.Core 785 786**Atomic service API**: This API can be used in atomic services since API version 11. 787 788**Parameters** 789 790| Name| Type| Mandatory| Description| 791| -------- | ------------------------- | -- | ------------------------ | 792| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 793| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 794| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 795 796**Error codes** 797 798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 799 800| ID| Error Message| 801| ------- | -------------------------------------------- | 802| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 803| 1300002 | This window state is abnormal. | 804| 1300003 | This window manager service works abnormally. | 805 806**Example** 807 808```ts 809import { BusinessError } from '@kit.BasicServicesKit'; 810 811try { 812 windowClass.resize(500, 1000, (err: BusinessError) => { 813 const errCode: number = err.code; 814 if (errCode) { 815 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 816 return; 817 } 818 console.info('Succeeded in changing the window size.'); 819 }); 820} catch (exception) { 821 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 822} 823``` 824 825## resize<sup>9+</sup> 826 827resize(width: number, height: number): Promise<void> 828 829Changes the size of this window. This API uses a promise to return the result. 830 831A value is returned once the API is called successfully. However, the final effect cannot be obtained immediately from the return value. To obtain the final effect immediately, call [resizeAsync()](#resizeasync12). 832 833The window size is restricted by [WindowLimits](arkts-apis-window-i.md#windowlimits11). You can call [getWindowLimits](#getwindowlimits11) to find out the exact limits. 834 835The new window width and height you set must meet the following limits: 836If the window width or height is less than the minimum width or height limit, then the minimum width or height limit takes effect. 837If the window width or height is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 838 839> **NOTE** 840> 841> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 842> 843> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 844 845**System capability**: SystemCapability.WindowManager.WindowManager.Core 846 847**Atomic service API**: This API can be used in atomic services since API version 11. 848 849**Parameters** 850 851| Name| Type| Mandatory| Description| 852| ------ | ------ | -- | ------------------------ | 853| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 854| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 855 856**Return value** 857 858| Type| Description| 859| ------------------- | ------------------------ | 860| Promise<void> | Promise that returns no value.| 861 862**Error codes** 863 864For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 865 866| ID| Error Message| 867| ------- | -------------------------------------------- | 868| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 869| 1300002 | This window state is abnormal. | 870| 1300003 | This window manager service works abnormally. | 871 872**Example** 873 874```ts 875import { BusinessError } from '@kit.BasicServicesKit'; 876 877try { 878 let promise = windowClass.resize(500, 1000); 879 promise.then(() => { 880 console.info('Succeeded in changing the window size.'); 881 }).catch((err: BusinessError) => { 882 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 883 }); 884} catch (exception) { 885 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 886} 887``` 888 889## resizeAsync<sup>12+</sup> 890 891resizeAsync(width: number, height: number): Promise<void> 892 893Changes the size of this window. This API uses a promise to return the result. 894 895A value is returned once the call takes effect. You can use [getWindowProperties()](#getwindowproperties9) in the callback (see the code snippet below) to obtain the final effect immediately. 896 897The window size is restricted by [WindowLimits](arkts-apis-window-i.md#windowlimits11). You can call [getWindowLimits](#getwindowlimits11) to find out the exact limits. 898 899The new window width and height you set must meet the following limits: 900If the window width or height is less than the minimum width or height limit, then the minimum width or height limit takes effect. 901If the window width or height is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 902 903> **NOTE** 904> 905> - This API is supported only in the floating window mode (when the window mode is **window.WindowStatusType.FLOATING**, which you can check using [getWindowStatus()](#getwindowstatus12)). 906> 907> - This API does not work for the main window not in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 908 909**System capability**: SystemCapability.Window.SessionManager 910 911**Atomic service API**: This API can be used in atomic services since API version 12. 912 913**Parameters** 914 915| Name| Type| Mandatory| Description| 916| ------ | ------ | -- | ------------------------ | 917| width | number | Yes| New width of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 918| height | number | Yes| New height of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 919 920**Return value** 921 922| Type| Description| 923| ------------------- | ------------------------ | 924| Promise<void> | Promise that returns no value.| 925 926**Error codes** 927 928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 929 930| ID| Error Message| 931| ------- | -------------------------------------------- | 932| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 933| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 934| 1300002 | This window state is abnormal. | 935| 1300003 | This window manager service works abnormally. | 936| 1300010 | The operation in the current window status is invalid. | 937 938**Example** 939 940```ts 941import { BusinessError } from '@kit.BasicServicesKit'; 942 943try { 944 let promise = windowClass.resizeAsync(500, 1000); 945 promise.then(() => { 946 console.info('Succeeded in changing the window size.'); 947 let rect = windowClass?.getWindowProperties().windowRect; 948 console.info(`Get window rect: ` + JSON.stringify(rect)); 949 }).catch((err: BusinessError) => { 950 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 951 }); 952} catch (exception) { 953 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 954} 955``` 956 957## getWindowProperties<sup>9+</sup> 958 959getWindowProperties(): WindowProperties 960 961Obtains the properties of this window. 962 963**System capability**: SystemCapability.WindowManager.WindowManager.Core 964 965**Atomic service API**: This API can be used in atomic services since API version 11. 966 967**Return value** 968 969| Type| Description| 970| ------------------------------------- | ------------- | 971| [WindowProperties](arkts-apis-window-i.md#windowproperties) | Window properties obtained.| 972 973**Error codes** 974 975For details about the error codes, see [Window Error Codes](errorcode-window.md). 976 977| ID| Error Message| 978| ------- | ------------------------------ | 979| 1300002 | This window state is abnormal. | 980 981**Example** 982 983```ts 984try { 985 let properties = windowClass.getWindowProperties(); 986} catch (exception) { 987 console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`); 988} 989``` 990 991## getWindowDensityInfo<sup>15+</sup> 992 993getWindowDensityInfo(): WindowDensityInfo 994 995Obtains the display density information of this window. 996 997**System capability**: SystemCapability.Window.SessionManager 998 999**Atomic service API**: This API can be used in atomic services since API version 15. 1000 1001**Return value** 1002 1003| Type| Description| 1004| ------------------------------------- | ------------- | 1005| [WindowDensityInfo](arkts-apis-window-i.md#windowdensityinfo15) | Display density information of the window. If the return value is [-1, -1, -1], the current device does not support this API.| 1006 1007**Error codes** 1008 1009For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1010 1011| ID| Error Message| 1012| ------- | ------------------------------ | 1013| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1014| 1300002 | This window state is abnormal. | 1015 1016**Example** 1017 1018```ts 1019try { 1020 let densityInfo = windowClass.getWindowDensityInfo(); 1021} catch (exception) { 1022 console.error(`Failed to obtain the window densityInfo. Cause code: ${exception.code}, message: ${exception.message}`); 1023} 1024``` 1025 1026## setWindowContainerColor<sup>20+</sup> 1027 1028setWindowContainerColor(activeColor: string, inactiveColor: string): void 1029 1030Sets the background color of the main window container for both when it has focus and when it does not. In the stage model, you need to call this API after [loadContent()](#loadcontent9) or [setUIContent()](#setuicontent9). 1031 1032The background color you set here covers the entire window, including both the title bar and the content area. If you also use [setWindowBackgroundColor()](#setwindowbackgroundcolor9), the content area shows the window background color, whereas the title bar shows the container background color. 1033 1034**System capability**: SystemCapability.Window.SessionManager 1035 1036**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 1037 1038**Required permission**: ohos.permission.SET_WINDOW_TRANSPARENT 1039 1040**Parameters** 1041 1042| Name| Type| Mandatory| Description| 1043| ----- | ------ | -- | ----------------------------------------------------------------------- | 1044| activeColor | string | Yes| Background color of the window container when it is focused. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**.| 1045| inactiveColor | string | Yes| Background color of the window container when it is not focused. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**. The opacity is fixed at **'FF'**.| 1046 1047**Error codes** 1048 1049For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1050 1051| ID| Error Message| 1052| ------- | ------------------------------ | 1053| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1054| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1055| 1300002 | This window state is abnormal. | 1056| 1300004 | Unauthorized operation. | 1057 1058**Example** 1059 1060```ts 1061// EntryAbility.ets 1062import { UIAbility } from '@kit.AbilityKit'; 1063import { BusinessError } from '@kit.BasicServicesKit'; 1064 1065export default class EntryAbility extends UIAbility { 1066 onWindowStageCreate(windowStage: window.WindowStage) { 1067 windowStage.loadContent("pages/page2", (err: BusinessError) => { 1068 let errCode: number = err.code; 1069 if (errCode) { 1070 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 1071 return; 1072 } 1073 console.info('Succeeded in loading the content.'); 1074 // Obtain the main window. 1075 let windowClass: window.Window | undefined = undefined; 1076 windowStage.getMainWindow((err: BusinessError, data) => { 1077 let errCode: number = err.code; 1078 if (errCode) { 1079 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1080 return; 1081 } 1082 windowClass = data; 1083 let activeColor: string = '#00000000'; 1084 let inactiveColor: string = '#FF000000'; 1085 try { 1086 windowClass.setWindowContainerColor(activeColor, inactiveColor); 1087 console.info('Succeeded in setting window container color.'); 1088 } catch (exception) { 1089 console.error(`Failed to set the window container color. Cause code: ${exception.code}, message: ${exception.message}`); 1090 }; 1091 }); 1092 }); 1093 } 1094} 1095``` 1096 1097## getGlobalRect<sup>13+</sup> 1098 1099getGlobalRect(): Rect 1100 1101Obtains the actual display area of this window on the screen. This API returns the result synchronously. 1102 1103This API can determine the actual on-screen location and size of a window that has been resized on certain devices. 1104 1105**System capability**: SystemCapability.Window.SessionManager 1106 1107**Atomic service API**: This API can be used in atomic services since API version 13. 1108 1109**Return value** 1110 1111| Type| Description| 1112| ------------------- | ------------------------ | 1113| [Rect](arkts-apis-window-i.md#rect7) | A set of four values, which indicates the horizontal distance from the screen's top-left corner to the window's left edge, the vertical distance from the screen's top-left corner to the window's top edge, the width of the window after scaling, and the height of the window after scaling.| 1114 1115**Error codes** 1116 1117For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1118 1119| ID| Error Message| 1120| ------- | -------------------------------------------- | 1121| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1122| 1300002 | This window state is abnormal. | 1123| 1300003 | This window manager service works abnormally. | 1124 1125**Example** 1126 1127```ts 1128try { 1129 let rect = windowClass.getGlobalRect(); 1130 console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect)); 1131} catch (exception) { 1132 console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`); 1133} 1134``` 1135 1136## getWindowAvoidArea<sup>9+</sup> 1137 1138getWindowAvoidArea(type: AvoidAreaType): AvoidArea 1139 1140Obtains the avoid area of this application window, for example, the system bar area, notch, gesture area, and soft keyboard area. 1141 1142This API is typically used in three scenarios: 1. In the **onWindowStageCreate** callback, this API can be used to obtain the avoid area in the initial layout during application startup. 2. When a child window needs to be temporarily displayed and requires layout adjustments for the content, this API can be used. 3. After you create a floating window, modal window, or system window (**WindowType** is a system window) and call [setSystemAvoidAreaEnabled](#setsystemavoidareaenabled18) to enable the such window to access the avoid area, this API can be used. 1143 1144**System capability**: SystemCapability.WindowManager.WindowManager.Core 1145 1146**Atomic service API**: This API can be used in atomic services since API version 11. 1147 1148**Parameters** 1149 1150| Name| Type| Mandatory| Description| 1151| ---- |----------------------------------| -- | ------------------------------------------------------------ | 1152| type | [AvoidAreaType](arkts-apis-window-e.md#avoidareatype7) | Yes| Type of the area.| 1153 1154**Return value** 1155 1156| Type| Description| 1157|--------------------------| ----------------- | 1158| [AvoidArea](arkts-apis-window-i.md#avoidarea7) | Area where the window cannot be displayed.| 1159 1160**Error codes** 1161 1162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1163 1164| ID| Error Message| 1165| ------- | ------------------------------ | 1166| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1167| 1300002 | This window state is abnormal. | 1168 1169**Example** 1170 1171```ts 1172let type = window.AvoidAreaType.TYPE_SYSTEM; 1173try { 1174 let avoidArea = windowClass.getWindowAvoidArea(type); 1175} catch (exception) { 1176 console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`); 1177} 1178``` 1179 1180## setSystemAvoidAreaEnabled<sup>18+</sup> 1181 1182setSystemAvoidAreaEnabled(enabled: boolean): Promise<void> 1183 1184Enables the window to access the [avoid area](arkts-apis-window-i.md#avoidarea7) when you create a floating window, modal window, or system window (**WindowType** is a system window). 1185 1186This API is particularly useful in the following scenario: After creating the aforementioned types of windows, you should call this API to enable the window to access the avoid area before calling [getWindowAvoidArea()](#getwindowavoidarea9) or [on('avoidAreaChange')](#onavoidareachange9) to obtain the avoid area or listen for changes in the avoid area. 1187 1188**System capability**: SystemCapability.Window.SessionManager 1189 1190**Atomic service API**: This API can be used in atomic services since API version 18. 1191 1192**Parameters** 1193 1194| Name| Type| Mandatory| Description| 1195| ---- |----------------------------------| -- | ------------------------------------------------------------ | 1196| enabled | boolean | Yes| Whether to enable the window to access the avoid area.<br> **true** to enable, **false** otherwise. The default value is **false**.| 1197 1198**Return value** 1199 1200| Type| Description| 1201| ------------------- | ----------------------- | 1202| Promise<void> | Promise that returns no value.| 1203 1204**Error codes** 1205 1206For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1207 1208| ID| Error Message| 1209| ------- | ------------------------------ | 1210| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1211| 1300002 | This window state is abnormal. | 1212| 1300003 | This window manager service works abnormally. | 1213| 1300004 | Unauthorized operation. | 1214 1215**Example** 1216 1217```ts 1218import { BusinessError } from '@kit.BasicServicesKit'; 1219 1220let windowClass: window.Window | undefined = undefined; 1221let config: window.Configuration = { 1222 name: "test", 1223 windowType: window.WindowType.TYPE_DIALOG, 1224 decorEnabled: true, 1225 ctx: this.context 1226}; 1227try { 1228 window.createWindow(config, (err: BusinessError, data) => { 1229 const errCode: number = err.code; 1230 if (errCode) { 1231 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 1232 return; 1233 } 1234 windowClass = data; 1235 windowClass.setUIContent("pages/Test"); 1236 let enabled = true; 1237 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 1238 promise.then(() => { 1239 let type = window.AvoidAreaType.TYPE_SYSTEM; 1240 let avoidArea = windowClass?.getWindowAvoidArea(type); 1241 }).catch((err: BusinessError) => { 1242 console.error(`Failed to obtain the system window avoid area. Cause code: ${err.code}, message: ${err.message}`); 1243 }); 1244 }); 1245} catch (exception) { 1246 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 1247} 1248``` 1249 1250## isSystemAvoidAreaEnabled<sup>18+</sup> 1251 1252isSystemAvoidAreaEnabled(): boolean 1253 1254Checks whether a floating window, modal window, or system window (**WindowType** is a system window) is enabled to access the [avoid area](arkts-apis-window-i.md#avoidarea7). 1255 1256**System capability**: SystemCapability.Window.SessionManager 1257 1258**Atomic service API**: This API can be used in atomic services since API version 18. 1259 1260**Return value** 1261 1262| Type| Description| 1263| ------------------------------------- | ------------- | 1264| boolean | Check result for whether the window is enabled to access the avoid area.<br> **true** if enabled, **false** otherwise.| 1265 1266**Error codes** 1267 1268For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1269 1270| ID| Error Message| 1271| ------- | ------------------------------ | 1272| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1273| 1300002 | This window state is abnormal. | 1274| 1300003 | This window manager service works abnormally. | 1275| 1300004 | Unauthorized operation. | 1276 1277**Example** 1278 1279```ts 1280import { BusinessError } from '@kit.BasicServicesKit'; 1281 1282let windowClass: window.Window | undefined = undefined; 1283let config: window.Configuration = { 1284 name: "test", 1285 windowType: window.WindowType.TYPE_DIALOG, 1286 decorEnabled: true, 1287 ctx: this.context 1288}; 1289try { 1290 window.createWindow(config, (err: BusinessError, data) => { 1291 const errCode: number = err.code; 1292 if (errCode) { 1293 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 1294 return; 1295 } 1296 windowClass = data; 1297 windowClass.setUIContent("pages/Test"); 1298 let enabled = true; 1299 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 1300 promise.then(() => { 1301 let enable = windowClass?.isSystemAvoidAreaEnabled(); 1302 }).catch((err: BusinessError) => { 1303 console.error(`Failed to obtain whether the system window can get avoid area. Cause code: ${err.code}, message: ${err.message}`); 1304 }); 1305 }); 1306} catch (exception) { 1307 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 1308} 1309``` 1310 1311## setTitleAndDockHoverShown<sup>14+</sup> 1312 1313setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise<void> 1314 1315Sets whether to show the window title bar and dock bar when the cursor hovers over the hot zone while the main window is in full-screen mode. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 1316 1317**System capability**: SystemCapability.Window.SessionManager 1318 1319**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 1320 1321**Atomic service API**: This API can be used in atomic services since API version 14. 1322 1323**Parameters** 1324 1325| Name | Type | Mandatory| Description | 1326| ---------- | ------- | ---- | ------------------------------------------------------------ | 1327| isTitleHoverShown | boolean | No | Whether to show the window title bar.<br>**true** to show, **false** otherwise. The default value is **true**.<br>| 1328| isDockHoverShown | boolean | No | Whether to show the dock bar.<br>**true** to show, **false** otherwise. The default value is **true**.<br>| 1329 1330**Return value** 1331 1332| Type | Description | 1333| ------------------- | ------------------------- | 1334| Promise<void> | Promise that returns no value.| 1335 1336**Error codes** 1337 1338For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1339 1340| ID| Error Message| 1341| ------- | -------------------------------------------- | 1342| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1343| 1300002 | This window state is abnormal. | 1344| 1300004 | Unauthorized operation. | 1345 1346**Example** 1347 1348```ts 1349// EntryAbility.ets 1350import { UIAbility } from '@kit.AbilityKit'; 1351import { BusinessError } from '@kit.BasicServicesKit'; 1352import { window } from '@kit.ArkUI'; 1353 1354export default class EntryAbility extends UIAbility { 1355 // ... 1356 onWindowStageCreate(windowStage: window.WindowStage): void { 1357 // Load the page corresponding to the main window. 1358 windowStage.loadContent('pages/Index', (err) => { 1359 let mainWindow: window.Window | undefined = undefined; 1360 // Obtain the main window. 1361 windowStage.getMainWindow().then( 1362 data => { 1363 if (!data) { 1364 console.error('Failed to get main window. Cause: The data is undefined.'); 1365 return; 1366 } 1367 mainWindow = data; 1368 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 1369 // Call maximize to enable the full-screen mode for the window. 1370 mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 1371 // Call setTitleAndDockHoverShown to hide the window title bar and dock bar. 1372 mainWindow.setTitleAndDockHoverShown(false, false); 1373 } 1374 ).catch((err: BusinessError) => { 1375 if(err.code){ 1376 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1377 } 1378 }); 1379 }); 1380 } 1381} 1382``` 1383 1384## setWindowLayoutFullScreen<sup>9+</sup> 1385 1386setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 1387 1388Sets whether the main window layout or the child window layout is immersive. This API uses a promise to return the result. It does not work when called by a system window. <!--RP8-->From API version 14, this API does not take effect on 2-in-1 devices.<!--RP8End--> 1389- An immersive layout means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 1390- A non-immersive layout means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 1391 1392**System capability**: SystemCapability.WindowManager.WindowManager.Core 1393 1394**Atomic service API**: This API can be used in atomic services since API version 12. 1395 1396**Parameters** 1397 1398| Name| Type| Mandatory| Description| 1399| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 1400| isLayoutFullScreen | boolean | Yes| Whether the layout of the window is immersive. (In immersive layout mode, the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> remain visible.) **true** if immersive, **false** otherwise.| 1401 1402**Return value** 1403 1404| Type| Description| 1405| ------------------- | ------------------------ | 1406| Promise<void> | Promise that returns no value.| 1407 1408**Error codes** 1409 1410For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1411 1412| ID| Error Message| 1413| ------- | -------------------------------------------- | 1414| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1415| 1300002 | This window state is abnormal. | 1416| 1300003 | This window manager service works abnormally. | 1417 1418**Example** 1419 1420```ts 1421// EntryAbility.ets 1422import { UIAbility } from '@kit.AbilityKit'; 1423import { BusinessError } from '@kit.BasicServicesKit'; 1424 1425export default class EntryAbility extends UIAbility { 1426 // ... 1427 onWindowStageCreate(windowStage: window.WindowStage): void { 1428 console.info('onWindowStageCreate'); 1429 let windowClass: window.Window | undefined = undefined; 1430 windowStage.getMainWindow((err: BusinessError, data) => { 1431 const errCode: number = err.code; 1432 if (errCode) { 1433 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1434 return; 1435 } 1436 windowClass = data; 1437 let isLayoutFullScreen = true; 1438 try { 1439 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 1440 promise.then(() => { 1441 console.info('Succeeded in setting the window layout to full-screen mode.'); 1442 }).catch((err: BusinessError) => { 1443 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 1444 }); 1445 } catch (exception) { 1446 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 1447 } 1448 }); 1449 } 1450} 1451``` 1452 1453## setImmersiveModeEnabledState<sup>12+</sup> 1454 1455setImmersiveModeEnabledState(enabled: boolean): void 1456 1457Sets whether to enable the immersive layout for the main window. This API does not change the window mode or size. It can be called only by the main window and child windows. <!--RP8-->From API version 14, this API does not take effect on 2-in-1 devices.<!--RP8End--> 1458 1459**System capability**: SystemCapability.WindowManager.WindowManager.Core 1460 1461**Atomic service API**: This API can be used in atomic services since API version 12. 1462 1463**Parameters** 1464 1465| Name | Type | Mandatory| Description | 1466| ---------- | ------- | ---- | ------------------------------------------------------------ | 1467| enabled | boolean | Yes | Whether to enable the immersive layout.<br>**true** to enable, **false** otherwise.<br>| 1468 1469**Error codes** 1470 1471For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1472 1473| ID| Error Message| 1474| ------- | -------------------------------------------- | 1475| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1476| 1300002 | This window state is abnormal. | 1477| 1300003 | This window manager service works abnormally. | 1478| 1300004 | Unauthorized operation. | 1479 1480**Example** 1481 1482```ts 1483try { 1484 let enabled = false; 1485 windowClass.setImmersiveModeEnabledState(enabled); 1486} catch (exception) { 1487 console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 1488} 1489``` 1490 1491## getImmersiveModeEnabledState<sup>12+</sup> 1492 1493getImmersiveModeEnabledState(): boolean 1494 1495Checks whether the immersive layout is enabled for this window. 1496 1497The return value is consistent with the settings applied via [setImmersiveModeEnabledState()](#setimmersivemodeenabledstate12) and [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9). If neither of these APIs has been called, the default return value is **false**. 1498 1499**System capability**: SystemCapability.WindowManager.WindowManager.Core 1500 1501**Atomic service API**: This API can be used in atomic services since API version 12. 1502 1503**Return value** 1504| Type | Description | 1505| ------- | ------------------------------------------------------------------------------------ | 1506| boolean | Check result for whether the immersive layout is enabled.<br>**true** if enabled, **false** otherwise.| 1507 1508**Error codes** 1509 1510For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1511 1512| ID| Error Message| 1513| -------- | -------------------------------------------- | 1514| 1300002 | This window state is abnormal. | 1515| 1300003 | This window manager service works abnormally. | 1516| 1300004 | Unauthorized operation. | 1517 1518**Example** 1519 1520```ts 1521try { 1522 let isEnabled = windowClass.getImmersiveModeEnabledState(); 1523} catch (exception) { 1524 console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 1525} 1526``` 1527 1528## isImmersiveLayout<sup>20+</sup> 1529 1530isImmersiveLayout(): boolean 1531 1532Checks whether this window is in immersive mode. 1533 1534**System capability**: SystemCapability.Window.SessionManager 1535 1536**Return value** 1537| Type | Description | 1538| ------- | ------------------------------------------------------------------------------------ | 1539| boolean | Check result for whether the window is in immersive mode. **true** if in immersive mode, **false** otherwise.| 1540 1541**Error codes** 1542 1543For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1544 1545| ID| Error Message| 1546| -------- | -------------------------------------------- | 1547| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1548| 1300002 | This window state is abnormal. | 1549 1550**Example** 1551 1552```ts 1553try { 1554 let isEnabled = windowClass.isImmersiveLayout(); 1555} catch (exception) { 1556 console.error(`Failed to check if the window layout is in immersive mode. Cause code: ${exception.code}, message: ${exception.message}`); 1557} 1558``` 1559 1560## setWindowDelayRaiseOnDrag<sup>19+</sup> 1561 1562setWindowDelayRaiseOnDrag(isEnabled: boolean): void 1563 1564Sets whether to enable delayed raising for the window. This API takes effect only for the main window and child windows. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 1565 1566If this API is not called or **false** is passed, the main window and child windows are raised immediately upon a left mouse button press by default.<br> 1567 1568When this API is called to enable delayed raising, in cross-window drag-and-drop situations, the window that contains the draggable component does not raise until the left mouse button is released, rather than raising immediately when the button is pressed. 1569 1570**System capability**: SystemCapability.Window.SessionManager 1571 1572**Atomic service API**: This API can be used in atomic services since API version 19. 1573 1574**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 1575 1576**Parameters** 1577 1578| Name | Type | Mandatory| Description | 1579| ---------- | ------- | ---- | ------------------------------------------------------------ | 1580| isEnabled | boolean | Yes | Whether to enable delayed raising.<br>**true** to enable, **false** otherwise.| 1581 1582**Error codes** 1583 1584For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1585 1586| ID| Error Message| 1587| ------- | -------------------------------------------- | 1588| 801 | Capability not supported.function setWindowDelayRaiseOnDrag can not work correctly due to limited device capabilities. | 1589| 1300002 | This window state is abnormal. | 1590 1591**Example** 1592 1593```ts 1594try { 1595 windowClass.setWindowDelayRaiseOnDrag(true); 1596} catch (exception) { 1597 console.error(`Failed to set window delay raise. Cause code: ${exception.code}, message: ${exception.message}`); 1598} 1599``` 1600 1601## setDragKeyFramePolicy<sup>20+</sup> 1602 1603setDragKeyFramePolicy(keyFramePolicy: KeyFramePolicy): Promise<KeyFramePolicy> 1604 1605Sets the keyframe policy for dragging the main window. This API uses a promise to return the result. 1606 1607If this API is called by a non-main window, error code 1300004 is returned. 1608 1609**System capability**: SystemCapability.Window.SessionManager 1610 1611**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 1612 1613**Parameters** 1614 1615| Name| Type | Mandatory| Description| 1616| ----- | ---------------------------- | -- | --------------------------------- | 1617| keyFramePolicy | [KeyFramePolicy](arkts-apis-window-i.md#keyframepolicy20) | Yes | Keyframe policy for dragging.| 1618 1619**Return value** 1620 1621| Type | Description | 1622| ------------------------------------- | ------------------------- | 1623| Promise<[KeyFramePolicy](arkts-apis-window-i.md#keyframepolicy20)> | Promise used to return the keyframe policy that takes effect.| 1624 1625**Error codes** 1626 1627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1628 1629| ID| Error Message | 1630| ------- | --------------------------------------------- | 1631| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1632| 1300002 | This window state is abnormal. | 1633| 1300003 | This window manager service works abnormally. | 1634| 1300004 | Unauthorized operation. | 1635| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range; 2. The parameter format is incorrect.| 1636 1637**Example** 1638 1639```ts 1640// EntryAbility.ets 1641import { UIAbility } from '@kit.AbilityKit'; 1642import { BusinessError } from '@kit.BasicServicesKit'; 1643 1644export default class EntryAbility extends UIAbility { 1645 // ... 1646 onWindowStageCreate(windowStage: window.WindowStage): void { 1647 console.info('onWindowStageCreate'); 1648 let windowClass: window.Window | undefined = undefined; 1649 windowStage.getMainWindow((err: BusinessError, data) => { 1650 const errCode: number = err.code; 1651 if (errCode) { 1652 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1653 return; 1654 } 1655 windowClass = data; 1656 let keyFramePolicy: window.KeyFramePolicy = { 1657 enable: true 1658 } 1659 try { 1660 let promise = windowClass.setDragKeyFramePolicy(keyFramePolicy); 1661 promise.then((ret: window.KeyFramePolicy) => { 1662 console.info(`Succeeded in setting key frame: ${JSON.stringify(ret)}`); 1663 }).catch((err: BusinessError) => { 1664 console.error(`Failed to set key frame. Cause code: ${err.code}, message: ${err.message}`); 1665 }); 1666 } catch (exception) { 1667 console.error(`Failed to set key frame. Cause code: ${exception.code}, message: ${exception.message}`); 1668 } 1669 }); 1670 } 1671} 1672``` 1673 1674## setWindowSystemBarEnable<sup>9+</sup> 1675 1676setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 1677 1678<!--RP14-->Sets whether to show the status bar and three-button navigation bar in the main window. The visibility of the status bar and three-button navigation bar is controlled by **status** and **navigation**, respectively.<!--RP14End--> This API uses a promise to return the result.<br>From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 1679 1680The return value does not indicate that the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> are shown or hidden. This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 1681 1682**Atomic service API**: This API can be used in atomic services since API version 12. 1683 1684**System capability**: SystemCapability.WindowManager.WindowManager.Core 1685 1686**Parameters** 1687 1688| Name| Type | Mandatory| Description| 1689| ----- | ---------------------------- | -- | --------------------------------- | 1690| names | Array<'status'\|'navigation'> | Yes| Whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> in full-screen mode.<br>For example, to show all of them, set this parameter to **['status', 'navigation']**. If this parameter is set to [], they are hidden.| 1691 1692**Return value** 1693 1694| Type| Description| 1695| ------------------- | ------------------------ | 1696| Promise<void> | Promise that returns no value.| 1697 1698**Error codes** 1699 1700For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1701 1702| ID| Error Message| 1703| ------- | -------------------------------------------- | 1704| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1705| 1300002 | This window state is abnormal. | 1706| 1300003 | This window manager service works abnormally. | 1707 1708**Example** 1709 1710```ts 1711// The following assumes that all of them are hidden. 1712// EntryAbility.ets 1713import { UIAbility } from '@kit.AbilityKit'; 1714import { BusinessError } from '@kit.BasicServicesKit'; 1715 1716export default class EntryAbility extends UIAbility { 1717 // ... 1718 onWindowStageCreate(windowStage: window.WindowStage): void { 1719 console.info('onWindowStageCreate'); 1720 let windowClass: window.Window | undefined = undefined; 1721 windowStage.getMainWindow((err: BusinessError, data) => { 1722 const errCode: number = err.code; 1723 if (errCode) { 1724 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1725 return; 1726 } 1727 windowClass = data; 1728 let names: Array<'status' | 'navigation'> = []; 1729 try { 1730 let promise = windowClass.setWindowSystemBarEnable(names); 1731 promise.then(() => { 1732 console.info('Succeeded in setting the system bar to be invisible.'); 1733 }).catch((err: BusinessError) => { 1734 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 1735 }); 1736 } catch (exception) { 1737 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 1738 } 1739 }); 1740 } 1741} 1742``` 1743 1744## setSpecificSystemBarEnabled<sup>11+</sup> 1745 1746setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise<void> 1747 1748Sets whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> of the main window. This API uses a promise to return the result.<br>From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 1749 1750The return value does not indicate that the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> are shown or hidden. This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 1751 1752**System capability**: SystemCapability.Window.SessionManager 1753 1754**Atomic service API**: This API can be used in atomic services since API version 11. 1755 1756**Parameters** 1757 1758| Name| Type | Mandatory| Description| 1759| ----- | ---------------------------- | -- | --------------------------------- | 1760| name | [SpecificSystemBar](arkts-apis-window-t.md#specificsystembar11) | Yes| Type of the system bar to be shown or hidden.| 1761| enable | boolean | Yes| Whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> in full-screen mode. **true** to show, **false** otherwise.| 1762| enableAnimation<sup>12+</sup> | boolean | No| Whether to enable animation when the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> status changes. **true** to enable, **false** otherwise. The default value is **false**.| 1763 1764**Return value** 1765 1766| Type| Description| 1767| ------------------- | ------------------------ | 1768| Promise<void> | Promise that returns no value.| 1769 1770**Error codes** 1771 1772For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1773 1774| ID| Error Message| 1775| ------- | -------------------------------------------- | 1776| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1777| 1300002 | This window state is abnormal. | 1778| 1300003 | This window manager service works abnormally. | 1779 1780**Example** 1781 1782```ts 1783// Here, the status bar is hidden. 1784// EntryAbility.ets 1785import { UIAbility } from '@kit.AbilityKit'; 1786import { BusinessError } from '@kit.BasicServicesKit'; 1787 1788export default class EntryAbility extends UIAbility { 1789 // ... 1790 onWindowStageCreate(windowStage: window.WindowStage): void { 1791 console.info('onWindowStageCreate'); 1792 let windowClass: window.Window | undefined = undefined; 1793 windowStage.getMainWindow((err: BusinessError, data) => { 1794 const errCode: number = err.code; 1795 if (errCode) { 1796 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1797 return; 1798 } 1799 windowClass = data; 1800 try { 1801 let promise = windowClass.setSpecificSystemBarEnabled('status', false); 1802 promise.then(() => { 1803 console.info('Succeeded in setting the system bar to be invisible.'); 1804 }).catch((err: BusinessError) => { 1805 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 1806 }); 1807 } catch (exception) { 1808 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 1809 } 1810 }); 1811 } 1812} 1813``` 1814 1815## setWindowSystemBarProperties<sup>9+</sup> 1816 1817setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 1818 1819Sets the properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar of the main window. This API uses a promise to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 1820 1821This API does not take effect when it is called by a child window. 1822 1823**System capability**: SystemCapability.WindowManager.WindowManager.Core 1824 1825**Atomic service API**: This API can be used in atomic services since API version 12. 1826 1827**Parameters** 1828 1829| Name | Type | Mandatory| Description | 1830| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1831| systemBarProperties | [SystemBarProperties](arkts-apis-window-i.md#systembarproperties) | Yes | Properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar.| 1832 1833**Return value** 1834 1835| Type | Description | 1836| ------------------- | ------------------------- | 1837| Promise<void> | Promise that returns no value.| 1838 1839**Error codes** 1840 1841For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1842 1843| ID| Error Message| 1844| ------- | -------------------------------------------- | 1845| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1846| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1847| 1300002 | This window state is abnormal. | 1848| 1300003 | This window manager service works abnormally. | 1849 1850**Example** 1851 1852```ts 1853// EntryAbility.ets 1854import { UIAbility } from '@kit.AbilityKit'; 1855import { BusinessError } from '@kit.BasicServicesKit'; 1856 1857export default class EntryAbility extends UIAbility { 1858 // ... 1859 onWindowStageCreate(windowStage: window.WindowStage): void { 1860 console.info('onWindowStageCreate'); 1861 let windowClass: window.Window | undefined = undefined; 1862 windowStage.getMainWindow((err: BusinessError, data) => { 1863 const errCode: number = err.code; 1864 if (errCode) { 1865 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1866 return; 1867 } 1868 windowClass = data; 1869 let SystemBarProperties: window.SystemBarProperties = { 1870 statusBarColor: '#ff00ff', 1871 navigationBarColor: '#00ff00', 1872 // The following properties are supported since API version 8. 1873 statusBarContentColor: '#ffffff', 1874 navigationBarContentColor: '#00ffff' 1875 }; 1876 try { 1877 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 1878 promise.then(() => { 1879 console.info('Succeeded in setting the system bar properties.'); 1880 }).catch((err: BusinessError) => { 1881 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 1882 }); 1883 } catch (exception) { 1884 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 1885 } 1886 }); 1887 } 1888} 1889``` 1890 1891## getWindowSystemBarProperties<sup>12+</sup> 1892 1893getWindowSystemBarProperties(): SystemBarProperties 1894 1895Obtains the properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar in the main window. 1896 1897**System capability**: SystemCapability.WindowManager.WindowManager.Core 1898 1899**Atomic service API**: This API can be used in atomic services since API version 12. 1900 1901**Return value** 1902 1903| Type| Description| 1904| ------------------------------------- | ------------- | 1905| [SystemBarProperties](arkts-apis-window-i.md#systembarproperties) | Properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar.| 1906 1907**Error codes** 1908 1909For details about the error codes, see [Window Error Codes](errorcode-window.md). 1910 1911| ID| Error Message| 1912| ------- | ------------------------------ | 1913| 1300002 | This window state is abnormal. | 1914| 1300003 | This window manager service works abnormally. | 1915| 1300004 | Unauthorized operation. | 1916 1917 1918**Example** 1919 1920```ts 1921// EntryAbility.ets 1922import { UIAbility } from '@kit.AbilityKit'; 1923import { BusinessError } from '@kit.BasicServicesKit'; 1924 1925export default class EntryAbility extends UIAbility { 1926 // ... 1927 1928 onWindowStageCreate(windowStage: window.WindowStage) { 1929 let windowClass: window.Window | undefined = undefined; 1930 windowStage.getMainWindow((err: BusinessError, data) => { 1931 const errCode: number = err.code; 1932 if (errCode) { 1933 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1934 return; 1935 } 1936 windowClass = data; 1937 try { 1938 let systemBarProperty = windowClass.getWindowSystemBarProperties(); 1939 console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty)); 1940 } catch (err) { 1941 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 1942 } 1943 }); 1944 } 1945}; 1946``` 1947 1948## setStatusBarColor<sup>18+</sup> 1949 1950setStatusBarColor(color: ColorMetrics): Promise<void> 1951 1952Sets the text color of the status bar in the main window. This API uses a promise to return the result. 1953 1954Setting the status bar text color is not supported for child windows. Calling this API on a child window will have no effect. This API has no effect on 2-in-1 devices. 1955 1956**System capability**: SystemCapability.Window.SessionManager 1957 1958**Atomic service API**: This API can be used in atomic services since API version 18. 1959 1960**Parameters** 1961 1962| Name | Type | Mandatory| Description | 1963| ------------------- | ------------------------------------------- | ---- | ---------------------- | 1964| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | Yes | Text color of the status bar.| 1965 1966**Return value** 1967 1968| Type | Description | 1969| ------------------- | ------------------------- | 1970| Promise<void> | Promise that returns no value.| 1971 1972**Error codes** 1973 1974For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 1975 1976| ID| Error Message| 1977| ------- | -------------------------------------------- | 1978| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1979| 801 | Capability not supported on this device. | 1980| 1300002 | This window state is abnormal. | 1981| 1300003 | This window manager service works abnormally. | 1982 1983**Example** 1984 1985```ts 1986// EntryAbility.ets 1987import { UIAbility } from '@kit.AbilityKit'; 1988import { BusinessError } from '@kit.BasicServicesKit'; 1989import { ColorMetrics, window } from '@kit.ArkUI'; 1990 1991export default class EntryAbility extends UIAbility { 1992 // ... 1993 onWindowStageCreate(windowStage: window.WindowStage): void { 1994 console.info('onWindowStageCreate'); 1995 let windowClass: window.Window | undefined = undefined; 1996 windowStage.getMainWindow((err: BusinessError, data) => { 1997 const errCode: number = err.code; 1998 if (errCode) { 1999 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2000 return; 2001 } 2002 windowClass = data; 2003 try { 2004 let promise = windowClass.setStatusBarColor(ColorMetrics.numeric(0x112233)); 2005 promise.then(() => { 2006 console.info('Succeeded in setting the status bar color.'); 2007 }).catch((err: BusinessError) => { 2008 console.error(`Set the status bar color failed. Cause code: ${err.code}, message: ${err.message}`); 2009 }); 2010 } catch (exception) { 2011 console.error(`Failed to set the status bar color. Cause code: ${exception.code}, message: ${exception.message}`); 2012 } 2013 }); 2014 } 2015} 2016``` 2017 2018## getStatusBarProperty<sup>18+</sup> 2019 2020getStatusBarProperty(): StatusBarProperty 2021 2022Obtains the properties (for example, text color) of the status bar in the main window. 2023 2024Calling this API is not supported for child window and will cause error code 1300002. 2025 2026**System capability**: SystemCapability.Window.SessionManager 2027 2028**Atomic service API**: This API can be used in atomic services since API version 18. 2029 2030**Return value** 2031 2032| Type| Description| 2033| ------------------------------------- | ------------- | 2034| [StatusBarProperty](arkts-apis-window-i.md#statusbarproperty18) | Status bar properties, such as its color.| 2035 2036**Error codes** 2037 2038For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2039 2040| ID| Error Message| 2041| ------- | ------------------------------ | 2042| 801 | Capability not supported on this device. | 2043| 1300002 | This window state is abnormal. | 2044 2045**Example** 2046 2047```ts 2048// EntryAbility.ets 2049import { UIAbility } from '@kit.AbilityKit'; 2050import { BusinessError } from '@kit.BasicServicesKit'; 2051import { window } from '@kit.ArkUI'; 2052 2053export default class EntryAbility extends UIAbility { 2054 // ... 2055 onWindowStageCreate(windowStage: window.WindowStage) { 2056 let windowClass: window.Window | undefined = undefined; 2057 windowStage.getMainWindow((err: BusinessError, data) => { 2058 const errCode: number = err.code; 2059 if (errCode) { 2060 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2061 return; 2062 } 2063 windowClass = data; 2064 try { 2065 let statusBarProperty = windowClass.getStatusBarProperty(); 2066 console.info('Succeeded in obtaining system bar properties. Property: ' + JSON.stringify(statusBarProperty)); 2067 } catch (err) { 2068 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2069 } 2070 }); 2071 } 2072}; 2073``` 2074 2075## setPreferredOrientation<sup>9+</sup> 2076 2077setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2078 2079Sets the preferred orientation for the main window. This API uses an asynchronous callback to return the result. For details about the development practices of orientation, see [Display Orientation Switching](https://developer.huawei.com/consumer/en/doc/best-practices/bpta-landscape-and-portrait-development). <!--RP9-->This API takes effect only on devices that support rotation with the sensor. It does not take effect on 2-in-1 devices or in the child window mode.<!--RP9End--> 2080 2081**System capability**: SystemCapability.WindowManager.WindowManager.Core 2082 2083**Atomic service API**: This API can be used in atomic services since API version 11. 2084 2085**Parameters** 2086 2087| Name | Type | Mandatory| Description | 2088| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2089| orientation | [Orientation](arkts-apis-window-e.md#orientation9) | Yes | Orientation to set. | 2090| callback | AsyncCallback<void> | Yes | Callback used to return the result. The callback indicates the API call result. It does not mean that the application rotation animation ends.| 2091 2092**Error codes** 2093 2094For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2095 2096| ID| Error Message| 2097| ------- | ------------------------------ | 2098| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2099| 1300002 | This window state is abnormal. | 2100 2101**Example** 2102 2103```ts 2104// EntryAbility.ets 2105import { UIAbility } from '@kit.AbilityKit'; 2106import { BusinessError } from '@kit.BasicServicesKit'; 2107 2108export default class EntryAbility extends UIAbility { 2109 // ... 2110 onWindowStageCreate(windowStage: window.WindowStage): void { 2111 console.info('onWindowStageCreate'); 2112 let windowClass: window.Window | undefined = undefined; 2113 windowStage.getMainWindow((err: BusinessError, data) => { 2114 const errCode: number = err.code; 2115 if (errCode) { 2116 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2117 return; 2118 } 2119 windowClass = data; 2120 let orientation = window.Orientation.AUTO_ROTATION; 2121 try { 2122 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 2123 const errCode: number = err.code; 2124 if (errCode) { 2125 console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`); 2126 return; 2127 } 2128 console.info('Succeeded in setting window orientation.'); 2129 }); 2130 } catch (exception) { 2131 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2132 } 2133 }); 2134 } 2135} 2136``` 2137 2138## setPreferredOrientation<sup>9+</sup> 2139 2140setPreferredOrientation(orientation: Orientation): Promise<void> 2141 2142Sets the preferred orientation for the main window. This API uses a promise to return the result. <!--RP9-->This API takes effect only on devices that support rotation with the sensor. It does not take effect on 2-in-1 devices or in the child window mode.<!--RP9End--> 2143 2144**System capability**: SystemCapability.WindowManager.WindowManager.Core 2145 2146**Atomic service API**: This API can be used in atomic services since API version 11. 2147 2148**Parameters** 2149 2150| Name | Type | Mandatory| Description | 2151| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2152| orientation | [Orientation](arkts-apis-window-e.md#orientation9) | Yes | Orientation to set. | 2153 2154**Return value** 2155 2156| Type | Description | 2157| ------------------- | ------------------------- | 2158| Promise<void> | Promise that returns no value.| 2159 2160**Error codes** 2161 2162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2163 2164| ID| Error Message| 2165| ------- | ------------------------------ | 2166| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2167| 1300002 | This window state is abnormal. | 2168 2169**Example** 2170 2171```ts 2172// EntryAbility.ets 2173import { UIAbility } from '@kit.AbilityKit'; 2174import { BusinessError } from '@kit.BasicServicesKit'; 2175 2176export default class EntryAbility extends UIAbility { 2177 // ... 2178 onWindowStageCreate(windowStage: window.WindowStage): void { 2179 console.info('onWindowStageCreate'); 2180 let windowClass: window.Window | undefined = undefined; 2181 windowStage.getMainWindow((err: BusinessError, data) => { 2182 const errCode: number = err.code; 2183 if (errCode) { 2184 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2185 return; 2186 } 2187 windowClass = data; 2188 let orientation = window.Orientation.AUTO_ROTATION; 2189 try { 2190 let promise = windowClass.setPreferredOrientation(orientation); 2191 promise.then(() => { 2192 console.info('Succeeded in setting the window orientation.'); 2193 }).catch((err: BusinessError) => { 2194 console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`); 2195 }); 2196 } catch (exception) { 2197 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2198 } 2199 }); 2200 } 2201} 2202``` 2203 2204## getPreferredOrientation<sup>12+</sup> 2205 2206getPreferredOrientation(): Orientation 2207 2208Obtains the orientation of the main window. This API can be called only by the main window. 2209 2210**System capability**: SystemCapability.WindowManager.WindowManager.Core 2211 2212**Atomic service API**: This API can be used in atomic services since API version 12. 2213 2214**Return value** 2215 2216| Type| Description| 2217|------------------------------| ------------------ | 2218| [Orientation](arkts-apis-window-e.md#orientation9) | Orientation.| 2219 2220**Error codes** 2221 2222For details about the error codes, see [Window Error Codes](errorcode-window.md). 2223 2224| ID| Error Message| 2225| ------- | ------------------------------ | 2226| 1300002 | This window state is abnormal. | 2227 2228**Example** 2229 2230```ts 2231// EntryAbility.ets 2232import { UIAbility } from '@kit.AbilityKit'; 2233import { BusinessError } from '@kit.BasicServicesKit'; 2234export default class EntryAbility extends UIAbility { 2235 // ... 2236 2237 onWindowStageCreate(windowStage: window.WindowStage) { 2238 console.info('onWindowStageCreate'); 2239 let windowClass: window.Window | undefined = undefined; 2240 windowStage.getMainWindow((err: BusinessError, data) => { 2241 const errCode: number = err.code; 2242 if (errCode) { 2243 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2244 return; 2245 } 2246 windowClass = data; 2247 try { 2248 let orientation = windowClass.getPreferredOrientation(); 2249 } catch (exception) { 2250 console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2251 } 2252 }); 2253 } 2254}; 2255``` 2256 2257## getUIContext<sup>10+</sup> 2258 2259getUIContext(): UIContext 2260 2261Obtains a UIContext instance. 2262 2263**Model restriction**: This API can be used only in the stage model. 2264 2265**System capability**: SystemCapability.WindowManager.WindowManager.Core 2266 2267**Atomic service API**: This API can be used in atomic services since API version 11. 2268 2269**Return value** 2270 2271| Type | Description | 2272| ---------- | ---------------------- | 2273| [UIContext](arkts-apis-uicontext-uicontext.md) | UIContext instance obtained.| 2274 2275**Error codes** 2276 2277For details about the error codes, see [Window Error Codes](errorcode-window.md). 2278 2279| ID| Error Message| 2280| ------- | ------------------------------ | 2281| 1300002 | This window state is abnormal. | 2282 2283**Example** 2284 2285```ts 2286// EntryAbility.ets 2287import { UIAbility } from '@kit.AbilityKit'; 2288import { window, UIContext } from '@kit.ArkUI'; 2289import { BusinessError } from '@kit.BasicServicesKit'; 2290 2291export default class EntryAbility extends UIAbility { 2292 onWindowStageCreate(windowStage: window.WindowStage) { 2293 // Load content for the main window. 2294 windowStage.loadContent("pages/page2", (err: BusinessError) => { 2295 let errCode: number = err.code; 2296 if (errCode) { 2297 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2298 return; 2299 } 2300 console.info('Succeeded in loading the content.'); 2301 // Obtain the main window. 2302 let windowClass: window.Window | undefined = undefined; 2303 windowStage.getMainWindow((err: BusinessError, data) => { 2304 let errCode: number = err.code; 2305 if (errCode) { 2306 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2307 return; 2308 } 2309 windowClass = data; 2310 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2311 // Obtain a UIContext instance. 2312 let uiContext: UIContext | null = null; 2313 uiContext = windowClass.getUIContext(); 2314 }); 2315 }); 2316 } 2317}; 2318``` 2319 2320## setUIContent<sup>9+</sup> 2321 2322setUIContent(path: string, callback: AsyncCallback<void>): void 2323 2324Loads 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. 2325 2326**System capability**: SystemCapability.WindowManager.WindowManager.Core 2327 2328**Atomic service API**: This API can be used in atomic services since API version 11. 2329 2330**Parameters** 2331 2332| Name| Type| Mandatory| Description| 2333| -------- | ------------------------- | -- | -------------------- | 2334| 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.| 2335| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 2336 2337**Error codes** 2338 2339For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2340 2341| ID| Error Message| 2342| ------- | -------------------------------------------- | 2343| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2344| 1300002 | This window state is abnormal. | 2345 2346**Example** 2347 2348```ts 2349import { BusinessError } from '@kit.BasicServicesKit'; 2350 2351try { 2352 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 2353 const errCode: number = err.code; 2354 if (errCode) { 2355 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2356 return; 2357 } 2358 console.info('Succeeded in loading the content.'); 2359 }); 2360} catch (exception) { 2361 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2362} 2363``` 2364 2365## setUIContent<sup>9+</sup> 2366 2367setUIContent(path: string): Promise<void> 2368 2369Loads 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. 2370 2371**System capability**: SystemCapability.WindowManager.WindowManager.Core 2372 2373**Atomic service API**: This API can be used in atomic services since API version 11. 2374 2375**Parameters** 2376 2377| Name| Type| Mandatory| Description| 2378| ---- | ------ | -- | ------------------ | 2379| 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.| 2380 2381**Return value** 2382 2383| Type| Description| 2384| ------------------- | ------------------------ | 2385| Promise<void> | Promise that returns no value.| 2386 2387**Error codes** 2388 2389For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2390 2391| ID| Error Message| 2392| ------- | -------------------------------------------- | 2393| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2394| 1300002 | This window state is abnormal. | 2395 2396**Example** 2397 2398```ts 2399import { BusinessError } from '@kit.BasicServicesKit'; 2400 2401try { 2402 let promise = windowClass.setUIContent('pages/page2/page3'); 2403 promise.then(() => { 2404 console.info('Succeeded in loading the content.'); 2405 }).catch((err: BusinessError) => { 2406 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2407 }); 2408} catch (exception) { 2409 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2410} 2411``` 2412 2413## loadContent<sup>9+</sup> 2414 2415loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2416 2417Loads the content of a page, with its path in the current project specified, to this window, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called repeatedly, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 2418 2419**Model restriction**: This API can be used only in the stage model. 2420 2421**System capability**: SystemCapability.WindowManager.WindowManager.Core 2422 2423**Atomic service API**: This API can be used in atomic services since API version 11. 2424 2425**Parameters** 2426 2427| Name | Type | Mandatory| Description | 2428| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2429| 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.| 2430| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 2431| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2432 2433**Error codes** 2434 2435For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2436 2437| ID| Error Message| 2438| ------- | -------------------------------------------- | 2439| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.| 2440| 1300002 | This window state is abnormal. | 2441 2442**Example** 2443 2444```ts 2445import { BusinessError } from '@kit.BasicServicesKit'; 2446 2447let storage: LocalStorage = new LocalStorage(); 2448storage.setOrCreate('storageSimpleProp', 121); 2449windowClass.loadContent('pages/page2', storage, (err: BusinessError) => { 2450 const errCode: number = err.code; 2451 if (errCode) { 2452 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2453 return; 2454 } 2455 console.info('Succeeded in loading the content.'); 2456}); 2457``` 2458 2459## loadContent<sup>9+</sup> 2460 2461loadContent(path: string, storage: LocalStorage): Promise<void> 2462 2463Loads the content of a page, with its path in the current project specified, to this window, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called repeatedly, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 2464 2465**Model restriction**: This API can be used only in the stage model. 2466 2467**System capability**: SystemCapability.WindowManager.WindowManager.Core 2468 2469**Atomic service API**: This API can be used in atomic services since API version 11. 2470 2471**Parameters** 2472 2473| Name | Type | Mandatory| Description | 2474| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2475| 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.| 2476| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 2477 2478**Return value** 2479 2480| Type | Description | 2481| ------------------- | ------------------------- | 2482| Promise<void> | Promise that returns no value.| 2483 2484**Error codes** 2485 2486For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2487 2488| ID| Error Message| 2489| ------- | -------------------------------------------- | 2490| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.| 2491| 1300002 | This window state is abnormal. | 2492 2493**Example** 2494 2495```ts 2496import { BusinessError } from '@kit.BasicServicesKit'; 2497 2498let storage: LocalStorage = new LocalStorage(); 2499storage.setOrCreate('storageSimpleProp', 121); 2500let promise = windowClass.loadContent('pages/page2', storage); 2501promise.then(() => { 2502 console.info('Succeeded in loading the content.'); 2503}).catch((err: BusinessError) => { 2504 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2505}); 2506``` 2507 2508## loadContentByName<sup>11+</sup> 2509 2510loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2511 2512Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window, and transfers the state attribute to the page through a local storage. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called repeatedly, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 2513 2514**Model restriction**: This API can be used only in the stage model. 2515 2516**System capability**: SystemCapability.WindowManager.WindowManager.Core 2517 2518**Atomic service API**: This API can be used in atomic services since API version 11. 2519 2520**Parameters** 2521 2522| Name | Type | Mandatory| Description | 2523| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2524| name | string | Yes | Name of the named route page. | 2525| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | Yes | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 2526| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2527 2528**Error codes** 2529 2530For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2531 2532| ID| Error Message | 2533| -------- | ------------------------------------------------------------ | 2534| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2535| 1300002 | This window state is abnormal. | 2536| 1300003 | This window manager service works abnormally. | 2537 2538**Example** 2539<!--code_no_check--> 2540```ts 2541import { UIAbility } from '@kit.AbilityKit'; 2542import { BusinessError } from '@kit.BasicServicesKit'; 2543import * as Index from '../pages/Index'; // Import the named route page. 2544 2545export default class EntryAbility extends UIAbility { 2546 onWindowStageCreate(windowStage: window.WindowStage) { 2547 console.info('onWindowStageCreate'); 2548 let storage: LocalStorage = new LocalStorage(); 2549 let newValue: Number = 121; 2550 storage.setOrCreate('storageSimpleProp', newValue); 2551 try { 2552 let windowClass: window.Window = windowStage.getMainWindowSync(); 2553 if (!windowClass) { 2554 console.error('Failed to get main window.'); 2555 return; 2556 } 2557 windowClass.loadContentByName(Index.entryName, storage, (err: BusinessError) => { 2558 const errCode: number = err?.code; 2559 if (errCode) { 2560 console.error(`Failed to load the content. Cause code: ${err?.code}, message: ${err?.message}`); 2561 return; 2562 } 2563 console.info('Succeeded in loading the content.'); 2564 }); 2565 } catch (exception) { 2566 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2567 } 2568 } 2569} 2570``` 2571<!--code_no_check--> 2572```ts 2573// ets/pages/Index.ets 2574export const entryName : string = 'Index'; 2575@Entry({routeName: entryName, useSharedStorage: true}) 2576@Component 2577export struct Index { 2578 @State message: string = 'Hello World' 2579 @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1; 2580 build() { 2581 Row() { 2582 Column() { 2583 Text(this.message) 2584 .fontSize(50) 2585 .fontWeight(FontWeight.Bold) 2586 } 2587 .width('100%') 2588 } 2589 .height('100%') 2590 } 2591} 2592``` 2593 2594## loadContentByName<sup>11+</sup> 2595 2596loadContentByName(name: string, callback: AsyncCallback<void>): void 2597 2598Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called repeatedly, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 2599 2600**Model restriction**: This API can be used only in the stage model. 2601 2602**System capability**: SystemCapability.WindowManager.WindowManager.Core 2603 2604**Atomic service API**: This API can be used in atomic services since API version 11. 2605 2606**Parameters** 2607 2608| Name | Type | Mandatory| Description | 2609| -------- | ------------------------- | ---- | ---------------- | 2610| name | string | Yes | Name of the named route page.| 2611| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2612 2613**Error codes** 2614 2615For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2616 2617| ID| Error Message | 2618| -------- | ------------------------------------------------------------ | 2619| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2620| 1300002 | This window state is abnormal. | 2621| 1300003 | This window manager service works abnormally. | 2622 2623**Example** 2624<!--code_no_check--> 2625```ts 2626import { BusinessError } from '@kit.BasicServicesKit'; 2627import * as Index from '../pages/Index'; // Import the named route page. 2628 2629try { 2630 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 2631 const errCode: number = err.code; 2632 if (errCode) { 2633 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2634 return; 2635 } 2636 console.info('Succeeded in loading the content.'); 2637 }); 2638} catch (exception) { 2639 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2640} 2641``` 2642<!--code_no_check--> 2643```ts 2644// ets/pages/Index.ets 2645export const entryName : string = 'Index'; 2646@Entry({routeName: entryName}) 2647@Component 2648export struct Index { 2649 @State message: string = 'Hello World' 2650 build() { 2651 Row() { 2652 Column() { 2653 Text(this.message) 2654 .fontSize(50) 2655 .fontWeight(FontWeight.Bold) 2656 } 2657 .width('100%') 2658 } 2659 .height('100%') 2660 } 2661} 2662``` 2663 2664## loadContentByName<sup>11+</sup> 2665 2666loadContentByName(name: string, storage?: LocalStorage): Promise<void> 2667 2668Loads the content of a [named route](../../ui/arkts-routing.md#named-route) page to this window, and transfers the state attribute to the page through a local storage. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called repeatedly, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 2669 2670**Model restriction**: This API can be used only in the stage model. 2671 2672**System capability**: SystemCapability.WindowManager.WindowManager.Core 2673 2674**Atomic service API**: This API can be used in atomic services since API version 11. 2675 2676**Parameters** 2677 2678| Name | Type | Mandatory| Description | 2679| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2680| name | string | Yes | Name of the named route page. | 2681| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | No | Page-level UI state storage unit, which is used to transfer the state attribute for the page.| 2682 2683**Return value** 2684 2685| Type | Description | 2686| ------------------- | ------------------------- | 2687| Promise<void> | Promise that returns no value.| 2688 2689**Error codes** 2690 2691For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 2692 2693| ID| Error Message | 2694| -------- | ------------------------------------------------------------ | 2695| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2696| 1300002 | This window state is abnormal. | 2697| 1300003 | This window manager service works abnormally. | 2698 2699**Example** 2700<!--code_no_check--> 2701```ts 2702import { BusinessError } from '@kit.BasicServicesKit'; 2703import * as Index from '../pages/Index'; // Import the named route page. 2704 2705let storage: LocalStorage = new LocalStorage(); 2706storage.setOrCreate('storageSimpleProp', 121); 2707try { 2708 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 2709 promise.then(() => { 2710 console.info('Succeeded in loading the content.'); 2711 }).catch((err: BusinessError) => { 2712 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2713 }); 2714} catch (exception) { 2715 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2716} 2717``` 2718<!--code_no_check--> 2719```ts 2720// ets/pages/Index.ets 2721export const entryName : string = 'Index'; 2722@Entry({routeName: entryName, useSharedStorage: true}) 2723@Component 2724export struct Index { 2725 @State message: string = 'Hello World' 2726 @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1; 2727 build() { 2728 Row() { 2729 Column() { 2730 Text(this.message) 2731 .fontSize(50) 2732 .fontWeight(FontWeight.Bold) 2733 } 2734 .width('100%') 2735 } 2736 .height('100%') 2737 } 2738} 2739``` 2740 2741## isWindowShowing<sup>9+</sup> 2742 2743isWindowShowing(): boolean 2744 2745Checks whether this window is displayed. 2746 2747**System capability**: SystemCapability.WindowManager.WindowManager.Core 2748 2749**Atomic service API**: This API can be used in atomic services since API version 11. 2750 2751**Return value** 2752 2753| Type| Description| 2754| ------- | ------------------------------------------------------------------ | 2755| boolean | Whether the window is displayed. **true** if displayed, **false** otherwise.| 2756 2757**Error codes** 2758 2759For details about the error codes, see [Window Error Codes](errorcode-window.md). 2760 2761| ID| Error Message| 2762| ------- | ------------------------------ | 2763| 1300002 | This window state is abnormal. | 2764 2765**Example** 2766 2767```ts 2768try { 2769 let data = windowClass.isWindowShowing(); 2770 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 2771} catch (exception) { 2772 console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`); 2773} 2774``` 2775 2776## on('windowSizeChange')<sup>7+</sup> 2777 2778on(type: 'windowSizeChange', callback: Callback<Size>): void 2779 2780Subscribes to the window size change event. 2781 2782**System capability**: SystemCapability.WindowManager.WindowManager.Core 2783 2784**Atomic service API**: This API can be used in atomic services since API version 11. 2785 2786**Parameters** 2787 2788| Name | Type | Mandatory| Description | 2789| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 2790| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 2791| callback | Callback<[Size](arkts-apis-window-i.md#size7)> | Yes | Callback used to return the window size. | 2792 2793**Error codes** 2794 2795For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2796 2797| ID| Error Message| 2798| ------- | -------------------------------------------- | 2799| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2800 2801**Example** 2802 2803```ts 2804try { 2805 windowClass.on('windowSizeChange', (data) => { 2806 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 2807 }); 2808} catch (exception) { 2809 console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 2810} 2811``` 2812 2813## off('windowSizeChange')<sup>7+</sup> 2814 2815off(type: 'windowSizeChange', callback?: Callback<Size>): void 2816 2817Unsubscribes from the window size change event. 2818 2819**System capability**: SystemCapability.WindowManager.WindowManager.Core 2820 2821**Atomic service API**: This API can be used in atomic services since API version 11. 2822 2823**Parameters** 2824 2825| Name | Type | Mandatory| Description | 2826| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 2827| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 2828| callback | Callback<[Size](arkts-apis-window-i.md#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. | 2829 2830**Error codes** 2831 2832For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2833 2834| ID| Error Message| 2835| ------- | -------------------------------------------- | 2836| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 2837 2838**Example** 2839 2840```ts 2841const callback = (size: window.Size) => { 2842 // ... 2843} 2844try { 2845 // Enable listening through the on API. 2846 windowClass.on('windowSizeChange', callback); 2847 // Disable the listening of a specified callback. 2848 windowClass.off('windowSizeChange', callback); 2849 // Unregister all the callbacks that have been registered through on(). 2850 windowClass.off('windowSizeChange'); 2851} catch (exception) { 2852 console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 2853} 2854``` 2855 2856## on('avoidAreaChange')<sup>9+</sup> 2857 2858on(type: 'avoidAreaChange', callback: Callback<AvoidAreaOptions>): void 2859 2860Subscribes to the event indicating changes to the area where this window cannot be displayed. 2861<!--RP7-->Common scenarios for triggering this event are as follows: transitions between full-screen mode, floating mode, and split-screen mode of the application window; rotation of the application window; transitions between folded and unfolded states of a foldable device; transfer of the application window between multiple devices.<!--RP7End--> 2862 2863**System capability**: SystemCapability.WindowManager.WindowManager.Core 2864 2865**Atomic service API**: This API can be used in atomic services since API version 11. 2866 2867**Parameters** 2868 2869| Name | Type | Mandatory| Description | 2870| -------- |----------------------------------| ---- |--------------------------------------| 2871| 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.| 2872| callback | Callback<[AvoidAreaOptions](arkts-apis-window-i.md#avoidareaoptions12)> | Yes | Callback used to return the area and area type.| 2873 2874**Error codes** 2875 2876For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2877 2878| ID| Error Message| 2879| ------- | -------------------------------------------- | 2880| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2881 2882**Example** 2883 2884```ts 2885try { 2886 windowClass.on('avoidAreaChange', (data) => { 2887 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 2888 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 2889 }); 2890} catch (exception) { 2891 console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 2892} 2893``` 2894 2895## off('avoidAreaChange')<sup>9+</sup> 2896 2897off(type: 'avoidAreaChange', callback?: Callback<AvoidAreaOptions>): void 2898 2899Unsubscribes from the event indicating changes to the area where this window cannot be displayed. 2900 2901**System capability**: SystemCapability.WindowManager.WindowManager.Core 2902 2903**Atomic service API**: This API can be used in atomic services since API version 11. 2904 2905**Parameters** 2906 2907| Name | Type | Mandatory| Description | 2908| -------- |----------------------------------|------|------------------------------------| 2909| 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.| 2910| callback | Callback<[AvoidAreaOptions](arkts-apis-window-i.md#avoidareaoptions12)> | No | Callback used to return the area and area type. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 2911 2912**Error codes** 2913 2914For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2915 2916| ID| Error Message| 2917| ------- | -------------------------------------------- | 2918| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 2919 2920**Example** 2921 2922```ts 2923interface Param { 2924 type: window.AvoidAreaType, 2925 area: window.AvoidArea 2926} 2927const callback = (data: Param) => { 2928 // ... 2929} 2930try { 2931 windowClass.on('avoidAreaChange', callback); 2932 2933 windowClass.off('avoidAreaChange', callback); 2934 // Unregister all the callbacks that have been registered through on(). 2935 windowClass.off('avoidAreaChange'); 2936} catch (exception) { 2937 console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 2938} 2939``` 2940 2941## on('keyboardHeightChange')<sup>7+</sup> 2942 2943on(type: 'keyboardHeightChange', callback: Callback<number>): void 2944 2945Subscribes to the event indicating soft keyboard height changes in the fixed state. 2946 2947The system notifies the keyboard height change when the soft keyboard is invoked by the window and overlaps with the window. 2948 2949Since API version 10, the soft keyboard can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 2950 2951**Atomic service API**: This API can be used in atomic services since API version 12. 2952 2953**System capability**: SystemCapability.WindowManager.WindowManager.Core 2954 2955**Parameters** 2956 2957| Name | Type | Mandatory| Description | 2958| -------- | ------------------- | ---- |-------------------------------------------| 2959| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 2960| callback | Callback<number> | Yes | Callback used to return the current keyboard height, which is an integer, in px. | 2961 2962**Error codes** 2963 2964For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2965 2966| ID| Error Message| 2967| ------- | -------------------------------------------- | 2968| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2969 2970**Example** 2971 2972```ts 2973import { BusinessError } from '@kit.BasicServicesKit'; 2974 2975try { 2976 windowClass.on('keyboardHeightChange', (data) => { 2977 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 2978 }); 2979} catch (exception) { 2980 console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 2981} 2982``` 2983 2984## off('keyboardHeightChange')<sup>7+</sup> 2985 2986off(type: 'keyboardHeightChange', callback?: Callback<number>): void 2987 2988Unsubscribes from the event indicating soft keyboard height changes in the fixed state so that the application does not receive notifications of soft keyboard height changes. 2989 2990Since API version 10, the soft keyboard can be set to the fixed or floating state. For details, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 2991 2992**Atomic service API**: This API can be used in atomic services since API version 12. 2993 2994**System capability**: SystemCapability.WindowManager.WindowManager.Core 2995 2996**Parameters** 2997 2998| Name | Type | Mandatory| Description | 2999| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3000| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 3001| 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. | 3002 3003**Error codes** 3004 3005For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3006 3007| ID| Error Message| 3008| ------- | -------------------------------------------- | 3009| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3010 3011**Example** 3012 3013```ts 3014import { BusinessError } from '@kit.BasicServicesKit'; 3015 3016const callback = (height: number) => { 3017 // ... 3018} 3019try { 3020 windowClass.on('keyboardHeightChange', callback); 3021 3022 windowClass.off('keyboardHeightChange', callback); 3023 // Unregister all the callbacks that have been registered through on(). 3024 windowClass.off('keyboardHeightChange'); 3025} catch (exception) { 3026 console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3027} 3028``` 3029 3030## on('keyboardWillShow')<sup>20+</sup> 3031 3032on(type: 'keyboardWillShow', callback: Callback<KeyboardInfo>): void 3033 3034Subscribes to the event indicating that the soft keyboard in the fixed state is about to show, or the soft keyboard is transitioning from the floating state to the fixed state. 3035 3036For details about the APIs used to set the soft keyboard to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3037 3038**Atomic service API**: This API can be used in atomic services since API version 20. 3039 3040**System capability**: SystemCapability.Window.SessionManager 3041 3042**Parameters** 3043 3044| Name | Type | Mandatory| Description | 3045| -------- | ------------------- | ---- |-------------------------------------------| 3046| type | string | Yes | Event type. The value is fixed at **'keyboardWillShow'**, indicating the soft keyboard in the fixed state is about to show.| 3047| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | Yes | Callback used to return the information about the soft keyboard. | 3048 3049**Error codes** 3050 3051For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3052 3053| ID| Error Message| 3054| ------- | -------------------------------------------- | 3055| 801 | Capability not supported. Function keyboardWillShow can not work correctly due to limited device capabilities. | 3056| 1300002 | This window state is abnormal. | 3057 3058**Example** 3059 3060```ts 3061import { BusinessError } from '@kit.BasicServicesKit'; 3062 3063const callback = (keyboardInfo: window.KeyboardInfo) => { 3064 console.info(`Keyboard will show animation. keyboardInfo: ` + JSON.stringify(keyboardInfo)); 3065} 3066try { 3067 windowClass.on('keyboardWillShow', callback); 3068 console.info(`Register keyboard will show animation success`); 3069} catch (exception) { 3070 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3071} 3072``` 3073 3074## off('keyboardWillShow')<sup>20+</sup> 3075 3076off(type: 'keyboardWillShow', callback?: Callback<KeyboardInfo>): void 3077 3078Unsubscribes from the event indicating that the soft keyboard in the fixed state is about to show. For details about the APIs used to set the input method panel to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3079 3080**Atomic service API**: This API can be used in atomic services since API version 20. 3081 3082**System capability**: SystemCapability.Window.SessionManager 3083 3084**Parameters** 3085 3086| Name | Type | Mandatory| Description | 3087| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3088| type | string | Yes | Event type. The value is fixed at **'keyboardWillShow'**, indicating the soft keyboard in the fixed state is about to show.| 3089| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | No | Callback used to return the information about the soft keyboard. 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. | 3090 3091**Error codes** 3092 3093For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3094 3095| ID| Error Message| 3096| ------- | -------------------------------------------- | 3097| 801 | Capability not supported. Function keyboardWillShow can not work correctly due to limited device capabilities. | 3098| 1300002 | This window state is abnormal. | 3099 3100**Example** 3101 3102```ts 3103import { BusinessError } from '@kit.BasicServicesKit'; 3104 3105const callback = (keyboardInfo: window.KeyboardInfo) => { 3106 console.info(`Keyboard will show animation. keyboardInfo: ` + JSON.stringify(keyboardInfo)); 3107} 3108try { 3109 windowClass.on('keyboardWillShow', callback); 3110 windowClass.off('keyboardWillShow', callback); 3111 // Unregister all the callbacks that have been registered through on(). 3112 windowClass.off('keyboardWillShow'); 3113 console.info(`Unregister keyboard will show animation success`); 3114} catch (exception) { 3115 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3116} 3117``` 3118 3119## on('keyboardWillHide')<sup>20+</sup> 3120 3121on(type: 'keyboardWillHide', callback: Callback<KeyboardInfo>): void 3122 3123Subscribes to the event indicating that the soft keyboard in the fixed state is about to hide, or the soft keyboard is transitioning from the fixed state to the floating state. 3124 3125For details about the APIs used to set the soft keyboard to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3126 3127**Atomic service API**: This API can be used in atomic services since API version 20. 3128 3129**System capability**: SystemCapability.Window.SessionManager 3130 3131**Parameters** 3132 3133| Name | Type | Mandatory| Description | 3134| -------- | ------------------- | ---- |-------------------------------------------| 3135| type | string | Yes | Event type. The value is fixed at **'keyboardWillHide'**, indicating the soft keyboard in the fixed state is about to hide.| 3136| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | Yes | Callback used to return the information about the soft keyboard. | 3137 3138**Error codes** 3139 3140For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3141 3142| ID| Error Message| 3143| ------- | -------------------------------------------- | 3144| 801 | Capability not supported. Function keyboardWillHide can not work correctly due to limited device capabilities. | 3145| 1300002 | This window state is abnormal. | 3146 3147**Example** 3148 3149```ts 3150import { BusinessError } from '@kit.BasicServicesKit'; 3151 3152const callback = (keyboardInfo: window.KeyboardInfo) => { 3153 console.info(`Keyboard will hide animation. keyboardInfo: ` + JSON.stringify(keyboardInfo)); 3154} 3155try { 3156 windowClass.on('keyboardWillHide', callback); 3157 console.info(`Register keyboard will hide animation success`); 3158} catch (exception) { 3159 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3160} 3161``` 3162 3163## off('keyboardWillHide')<sup>20+</sup> 3164 3165off(type: 'keyboardWillHide', callback?: Callback<KeyboardInfo>): void 3166 3167Unsubscribes from the event indicating that the soft keyboard in the fixed state is about to hide. For details about the APIs used to set the input method panel to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3168 3169**Atomic service API**: This API can be used in atomic services since API version 20. 3170 3171**System capability**: SystemCapability.Window.SessionManager 3172 3173**Parameters** 3174 3175| Name | Type | Mandatory| Description | 3176| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3177| type | string | Yes | Event type. The value is fixed at **'keyboardWillHide'**, indicating the soft keyboard in the fixed state is about to hide.| 3178| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | No | Callback used to return the information about the soft keyboard. 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. | 3179 3180**Error codes** 3181 3182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3183 3184| ID| Error Message| 3185| ------- | -------------------------------------------- | 3186| 801 | Capability not supported. Function keyboardWillHide can not work correctly due to limited device capabilities. | 3187| 1300002 | This window state is abnormal. | 3188 3189**Example** 3190 3191```ts 3192import { BusinessError } from '@kit.BasicServicesKit'; 3193 3194const callback = (keyboardInfo: window.KeyboardInfo) => { 3195 console.info(`Keyboard will hide animation. keyboardInfo: ` + JSON.stringify(keyboardInfo)); 3196} 3197try { 3198 windowClass.on('keyboardWillHide', callback); 3199 windowClass.off('keyboardWillHide', callback); 3200 // Unregister all the callbacks that have been registered through on(). 3201 windowClass.off('keyboardWillHide'); 3202 console.info(`Unregister keyboard will hide animation success`); 3203} catch (exception) { 3204 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3205} 3206``` 3207 3208## on('keyboardDidShow')<sup>18+</sup> 3209 3210on(type: 'keyboardDidShow', callback: Callback<KeyboardInfo>): void 3211 3212Subscribes to the event indicating that the show animation of the soft keyboard in the fixed state is completed, or when the soft keyboard finishes transitioning from the floating state to the fixed state. 3213 3214For details about the APIs used to set the soft keyboard to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3215 3216**Atomic service API**: This API can be used in atomic services since API version 18. 3217 3218**System capability**: SystemCapability.Window.SessionManager 3219 3220**Parameters** 3221 3222| Name | Type | Mandatory| Description | 3223| -------- | ------------------- | ---- |-------------------------------------------| 3224| type | string | Yes | Event type. The value is fixed at **'keyboardDidShow'**, indicating the show animation of the soft keyboard in the fixed state is completed.| 3225| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | Yes | Callback used to return the information about the soft keyboard. | 3226 3227**Error codes** 3228 3229For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3230 3231| ID| Error Message| 3232| ------- | -------------------------------------------- | 3233| 801 | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. | 3234| 1300002 | This window state is abnormal. | 3235 3236**Example** 3237 3238```ts 3239import { BusinessError } from '@kit.BasicServicesKit'; 3240 3241try { 3242 windowClass.on('keyboardDidShow', (keyboardInfo) => { 3243 console.info('keyboard show animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo)); 3244 }); 3245} catch (exception) { 3246 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3247} 3248``` 3249 3250## off('keyboardDidShow')<sup>18+</sup> 3251 3252off(type: 'keyboardDidShow', callback?: Callback<KeyboardInfo>): void 3253 3254Unsubscribes from the event indicating that the show animation of the soft keyboard in the fixed state is completed, For details about the APIs used to set the input method panel to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3255 3256**Atomic service API**: This API can be used in atomic services since API version 18. 3257 3258**System capability**: SystemCapability.Window.SessionManager 3259 3260**Parameters** 3261 3262| Name | Type | Mandatory| Description | 3263| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3264| type | string | Yes | Event type. The value is fixed at **'keyboardDidShow'**, indicating the show animation of the soft keyboard in the fixed state is completed.| 3265| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | No | Callback used to return the information about the soft keyboard. 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. | 3266 3267**Error codes** 3268 3269For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3270 3271| ID| Error Message| 3272| ------- | -------------------------------------------- | 3273| 801 | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. | 3274| 1300002 | This window state is abnormal. | 3275 3276**Example** 3277 3278```ts 3279import { BusinessError } from '@kit.BasicServicesKit'; 3280 3281const callback = (keyboardInfo: window.KeyboardInfo) => { 3282 // ... 3283} 3284try { 3285 windowClass.on('keyboardDidShow', callback); 3286 windowClass.off('keyboardDidShow', callback); 3287 // Unregister all the callbacks that have been registered through on(). 3288 windowClass.off('keyboardDidShow'); 3289} catch (exception) { 3290 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3291} 3292``` 3293 3294## on('keyboardDidHide')<sup>18+</sup> 3295 3296on(type: 'keyboardDidHide', callback: Callback<KeyboardInfo>): void 3297 3298Subscribes to the event indicating that the hide animation of the soft keyboard in the fixed state is completed, or when the soft keyboard finishes transitioning from the fixed state to the floating state. 3299 3300For details about the APIs used to set the soft keyboard to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3301 3302**Atomic service API**: This API can be used in atomic services since API version 18. 3303 3304**System capability**: SystemCapability.Window.SessionManager 3305 3306**Parameters** 3307 3308| Name | Type | Mandatory| Description | 3309| -------- | ------------------- | ---- |-------------------------------------------| 3310| type | string | Yes | Event type. The value is fixed at **'keyboardDidHide'**, indicating the hide animation of the soft keyboard in the fixed state is completed.| 3311| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | Yes | Callback used to return the information about the soft keyboard. | 3312 3313**Error codes** 3314 3315For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3316 3317| ID| Error Message| 3318| ------- | -------------------------------------------- | 3319| 801 | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. | 3320| 1300002 | This window state is abnormal. | 3321 3322**Example** 3323 3324```ts 3325import { BusinessError } from '@kit.BasicServicesKit'; 3326 3327try { 3328 windowClass.on('keyboardDidHide', (keyboardInfo) => { 3329 console.info('keyboard hide animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo)); 3330 }); 3331} catch (exception) { 3332 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3333} 3334``` 3335 3336## off('keyboardDidHide')<sup>18+</sup> 3337 3338off(type: 'keyboardDidHide', callback?: Callback<KeyboardInfo>): void 3339 3340Unsubscribes from the event indicating that the hide animation of the soft keyboard in the fixed state is completed, For details about the APIs used to set the input method panel to the fixed or floating state, see [Input Method Service](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10). 3341 3342**Atomic service API**: This API can be used in atomic services since API version 18. 3343 3344**System capability**: SystemCapability.Window.SessionManager 3345 3346**Parameters** 3347 3348| Name | Type | Mandatory| Description | 3349| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3350| type | string | Yes | Event type. The value is fixed at **'keyboardDidHide'**, indicating the hide animation of the soft keyboard in the fixed state is completed.| 3351| callback | Callback<[KeyboardInfo](arkts-apis-window-i.md#keyboardinfo18)> | No | Callback used to return the information about the soft keyboard. 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. | 3352 3353**Error codes** 3354 3355For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3356 3357| ID| Error Message| 3358| ------- | -------------------------------------------- | 3359| 801 | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. | 3360| 1300002 | This window state is abnormal. | 3361 3362**Example** 3363 3364```ts 3365import { BusinessError } from '@kit.BasicServicesKit'; 3366 3367const callback = (keyboardInfo: window.KeyboardInfo) => { 3368 // ... 3369} 3370try { 3371 windowClass.on('keyboardDidHide', callback); 3372 windowClass.off('keyboardDidHide', callback); 3373 // Unregister all the callbacks that have been registered through on(). 3374 windowClass.off('keyboardDidHide'); 3375} catch (exception) { 3376 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3377} 3378``` 3379 3380## on('touchOutside')<sup>11+</sup> 3381 3382on(type: 'touchOutside', callback: Callback<void>): void 3383 3384Subscribes to the touch event outside this window. 3385 3386**System capability**: SystemCapability.WindowManager.WindowManager.Core 3387 3388**Atomic service API**: This API can be used in atomic services since API version 11. 3389 3390**Parameters** 3391 3392| Name | Type | Mandatory| Description | 3393| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3394| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the touch event outside this window.| 3395| callback | Callback<void> | Yes | Callback used to return the touch event outside this window. | 3396 3397**Error codes** 3398 3399For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3400 3401| ID| Error Message| 3402| ------- | -------------------------------------------- | 3403| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3404 3405**Example** 3406 3407```ts 3408try { 3409 windowClass.on('touchOutside', () => { 3410 console.info('touch outside'); 3411 }); 3412} catch (exception) { 3413 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3414} 3415``` 3416 3417## off('touchOutside')<sup>11+</sup> 3418 3419off(type: 'touchOutside', callback?: Callback<void>): void 3420 3421Unsubscribes from the touch event outside this window. 3422 3423**System capability**: SystemCapability.WindowManager.WindowManager.Core 3424 3425**Atomic service API**: This API can be used in atomic services since API version 11. 3426 3427**Parameters** 3428 3429| Name | Type | Mandatory| Description | 3430| -------- |----------------------| ---- |--------------------------------------| 3431| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the touch event outside this window.| 3432| callback | Callback<void> | No | Callback used to return the touch event outside this window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3433 3434**Error codes** 3435 3436For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3437 3438| ID| Error Message| 3439| ------- | -------------------------------------------- | 3440| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3441 3442**Example** 3443 3444```ts 3445const callback = () => { 3446 // ... 3447} 3448try { 3449 windowClass.on('touchOutside', callback); 3450 windowClass.off('touchOutside', callback); 3451 // Unregister all the callbacks that have been registered through on(). 3452 windowClass.off('touchOutside'); 3453} catch (exception) { 3454 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3455} 3456``` 3457 3458## on('screenshot')<sup>9+</sup> 3459 3460on(type: 'screenshot', callback: Callback<void>): void 3461 3462Subscribes to the screenshot event. 3463 3464**Atomic service API**: This API can be used in atomic services since API version 12. 3465 3466**System capability**: SystemCapability.WindowManager.WindowManager.Core 3467 3468**Parameters** 3469 3470| Name | Type | Mandatory| Description | 3471| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3472| type | string | Yes | Event type. The value is fixed at **'screenshot'**, covering screenshot events initiated from the Control Panel, by running hdc commands, or by calling the screenshot interfaces.| 3473| callback | Callback<void> | Yes | Callback invoked when a screenshot event occurs. | 3474 3475**Error codes** 3476 3477For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3478 3479| ID| Error Message| 3480| ------- | -------------------------------------------- | 3481| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3482 3483**Example** 3484 3485```ts 3486try { 3487 windowClass.on('screenshot', () => { 3488 console.info('screenshot happened'); 3489 }); 3490} catch (exception) { 3491 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3492} 3493``` 3494 3495## off('screenshot')<sup>9+</sup> 3496 3497off(type: 'screenshot', callback?: Callback<void>): void 3498 3499Unsubscribes from the screenshot event. 3500 3501**Atomic service API**: This API can be used in atomic services since API version 12. 3502 3503**System capability**: SystemCapability.WindowManager.WindowManager.Core 3504 3505**Parameters** 3506 3507| Name | Type | Mandatory| Description | 3508| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3509| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 3510| 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.| 3511 3512**Error codes** 3513 3514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3515 3516| ID| Error Message| 3517| ------- | -------------------------------------------- | 3518| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3519 3520**Example** 3521 3522```ts 3523let callback = () => { 3524 console.info('screenshot happened'); 3525}; 3526try { 3527 windowClass.on('screenshot', callback); 3528 windowClass.off('screenshot', callback); 3529 // Unregister all the callbacks that have been registered through on(). 3530 windowClass.off('screenshot'); 3531} catch (exception) { 3532 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3533} 3534``` 3535 3536## on('screenshotAppEvent')<sup>20+</sup> 3537 3538on(type: 'screenshotAppEvent', callback: Callback<ScreenshotEventType>): void 3539 3540Subscribes to the screenshot event. 3541 3542**System capability**: SystemCapability.WindowManager.WindowManager.Core 3543 3544**Parameters** 3545 3546| Name | Type | Mandatory| Description | 3547| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3548| type | string | Yes | Event type. The value is fixed at **'screenshotAppEvent'**, covering screenshot events from the Control Panel, shortcut keys, and scroll capture.| 3549| callback | Callback<[ScreenshotEventType](arkts-apis-window-e.md#screenshoteventtype20)> | Yes | Callback invoked when a screenshot event occurs. | 3550 3551**Error codes** 3552 3553For details about the error codes, see [Window Error Codes](errorcode-window.md). 3554 3555| ID| Error Message| 3556| ------- | ------------------------------ | 3557| 1300002 | This window state is abnormal. | 3558| 1300003 | This window manager service works abnormally. | 3559 3560**Example** 3561 3562```ts 3563const callback = (eventType: window.ScreenshotEventType) => { 3564 console.info(`screenshotAppEvent happened. Event: ${eventType}`); 3565} 3566try { 3567 windowClass.on('screenshotAppEvent', callback); 3568} catch (exception) { 3569 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3570} 3571``` 3572 3573## off('screenshotAppEvent')<sup>20+</sup> 3574 3575off(type: 'screenshotAppEvent', callback?: Callback<ScreenshotEventType>): void 3576 3577Unsubscribes from the screenshot event. 3578 3579**System capability**: SystemCapability.WindowManager.WindowManager.Core 3580 3581**Parameters** 3582 3583| Name | Type | Mandatory| Description | 3584| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3585| type | string | Yes | Event type. The value is fixed at **'screenshotAppEvent'**, indicating the screenshot event.| 3586| callback | Callback<[ScreenshotEventType](arkts-apis-window-e.md#screenshoteventtype20)> | 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. | 3587 3588**Error codes** 3589 3590For details about the error codes, see [Window Error Codes](errorcode-window.md). 3591 3592| ID| Error Message| 3593| ------- | ------------------------------ | 3594| 1300002 | This window state is abnormal. | 3595| 1300003 | This window manager service works abnormally. | 3596 3597**Example** 3598 3599```ts 3600const callback = (eventType: window.ScreenshotEventType) => { 3601 // ... 3602} 3603try { 3604 // Enable listening through the on API. 3605 windowClass.on('screenshotAppEvent', callback); 3606 // Disable the listening of a specified callback. 3607 windowClass.off('screenshotAppEvent', callback); 3608 // Unregister all the callbacks that have been registered through on(). 3609 windowClass.off('screenshotAppEvent'); 3610} catch (exception) { 3611 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3612} 3613``` 3614 3615## on('dialogTargetTouch')<sup>10+</sup> 3616 3617on(type: 'dialogTargetTouch', callback: Callback<void>): void 3618 3619Subscribes to click or touch events in a window covered by a modal window. This API takes effect only when it is called by a modal window. 3620 3621**Atomic service API**: This API can be used in atomic services since API version 12. 3622 3623**System capability**: SystemCapability.WindowManager.WindowManager.Core 3624 3625**Parameters** 3626 3627| Name | Type | Mandatory| Description | 3628| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3629| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click or touch event in a window covered by a modal window.| 3630| callback | Callback<void>| Yes | Callback invoked when a click or touch event occurs in the window covered by the modal window.| 3631 3632**Error codes** 3633 3634For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3635 3636| ID| Error Message| 3637| ------- | -------------------------------------------- | 3638| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3639 3640**Example** 3641 3642```ts 3643try { 3644 windowClass.on('dialogTargetTouch', () => { 3645 console.info('touch dialog target'); 3646 }); 3647} catch (exception) { 3648 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3649} 3650``` 3651 3652## off('dialogTargetTouch')<sup>10+</sup> 3653 3654off(type: 'dialogTargetTouch', callback?: Callback<void>): void 3655 3656Unsubscribes from the touch event of the target window in the modal window mode. 3657 3658**Atomic service API**: This API can be used in atomic services since API version 12. 3659 3660**System capability**: SystemCapability.WindowManager.WindowManager.Core 3661 3662**Parameters** 3663 3664| Name | Type | Mandatory| Description | 3665| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3666| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the touch event of the target window in the modal window mode.| 3667| callback | Callback<void> | No | Callback invoked when the touch event occurs in the target window of the modal window mode. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 3668 3669**Error codes** 3670 3671For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3672 3673| ID| Error Message| 3674| ------- | -------------------------------------------- | 3675| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3676 3677**Example** 3678 3679```ts 3680const callback = () => { 3681 // ... 3682} 3683try { 3684 windowClass.on('dialogTargetTouch', callback); 3685 windowClass.off('dialogTargetTouch', callback); 3686 // Unregister all the callbacks that have been registered through on(). 3687 windowClass.off('dialogTargetTouch'); 3688} catch (exception) { 3689 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3690} 3691``` 3692 3693## on('windowEvent')<sup>10+</sup> 3694 3695on(type: 'windowEvent', callback: Callback<WindowEventType>): void 3696 3697Subscribes to the window lifecycle change event. 3698 3699**System capability**: SystemCapability.WindowManager.WindowManager.Core 3700 3701**Atomic service API**: This API can be used in atomic services since API version 11. 3702 3703**Parameters** 3704 3705| Name | Type | Mandatory| Description | 3706| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3707| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 3708| callback | Callback<[WindowEventType](arkts-apis-window-e.md#windoweventtype10)> | Yes | Callback used to return the window lifecycle state. | 3709 3710**Error codes** 3711 3712For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3713 3714| ID| Error Message| 3715| ------- | -------------------------------------------- | 3716| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3717 3718**Example** 3719 3720```ts 3721try { 3722 windowClass.on('windowEvent', (data) => { 3723 console.info('Window event happened. Event:' + JSON.stringify(data)); 3724 }); 3725} catch (exception) { 3726 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3727} 3728``` 3729 3730## off('windowEvent')<sup>10+</sup> 3731 3732off(type: 'windowEvent', callback?: Callback<WindowEventType>): void 3733 3734Unsubscribes from the window lifecycle change event. 3735 3736**System capability**: SystemCapability.WindowManager.WindowManager.Core 3737 3738**Atomic service API**: This API can be used in atomic services since API version 11. 3739 3740**Parameters** 3741 3742| Name | Type | Mandatory| Description | 3743| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3744| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 3745| callback | Callback<[WindowEventType](arkts-apis-window-e.md#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. | 3746 3747**Error codes** 3748 3749For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 3750 3751| ID| Error Message| 3752| ------- | -------------------------------------------- | 3753| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3754 3755**Example** 3756 3757```ts 3758const callback = (windowEventType: window.WindowEventType) => { 3759 // ... 3760} 3761try { 3762 // Enable listening through the on API. 3763 windowClass.on('windowEvent', callback); 3764 // Disable the listening of a specified callback. 3765 windowClass.off('windowEvent', callback); 3766 // Unregister all the callbacks that have been registered through on(). 3767 windowClass.off('windowEvent'); 3768} catch (exception) { 3769 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3770} 3771``` 3772 3773## on('displayIdChange')<sup>14+</sup> 3774 3775on(type: 'displayIdChange', callback: Callback<number>): void 3776 3777Subscribes to the display change event of this window. For example, this event is triggered when the window is moved to a different display. 3778 3779**Atomic service API**: This API can be used in atomic services since API version 14. 3780 3781**System capability**: SystemCapability.Window.SessionManager 3782 3783**Parameters** 3784 3785| Name | Type | Mandatory| Description | 3786| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3787| type | string | Yes | Event type. The value is fixed at **'displayIdChange'**, indicating the display change event.| 3788| callback | Callback<number> | Yes | Callback invoked when the display where the window is located changes. The callback contains a parameter of the number type, indicating the new display ID. | 3789 3790**Error codes** 3791 3792For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3793 3794| ID| Error Message| 3795| ------- | ------------------------------ | 3796| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3797| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3798| 1300002 | This window state is abnormal. | 3799 3800**Example** 3801 3802```ts 3803try { 3804 windowClass.on('displayIdChange', (data) => { 3805 console.info('Window displayId changed, displayId=' + JSON.stringify(data)); 3806 }); 3807} catch (exception) { 3808 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3809} 3810``` 3811## off('displayIdChange')<sup>14+</sup> 3812 3813off(type: 'displayIdChange', callback?: Callback<number>): void 3814 3815Unsubscribes from the display change event of this window. 3816 3817**Atomic service API**: This API can be used in atomic services since API version 14. 3818 3819**System capability**: SystemCapability.Window.SessionManager 3820 3821**Parameters** 3822 3823| Name | Type | Mandatory| Description | 3824| -------- |----------------------------| ---- |--------------------------------------| 3825| type | string | Yes | Event type. The value is fixed at **'displayIdChange'**, indicating the display change event.| 3826| callback | Callback<number> | No | Callback invoked when the display where the window is located changes. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3827 3828**Error codes** 3829 3830For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3831 3832| ID| Error Message| 3833| ------- | ------------------------------ | 3834| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3835| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3836| 1300002 | This window state is abnormal. | 3837 3838**Example** 3839 3840```ts 3841const callback = (displayId: number) => { 3842 // ... 3843} 3844try { 3845 // Enable listening through the on API. 3846 windowClass.on('displayIdChange', callback); 3847 // Disable the listening of a specified callback. 3848 windowClass.off('displayIdChange', callback); 3849 // Unregister all the callbacks that have been registered through on(). 3850 windowClass.off('displayIdChange'); 3851} catch (exception) { 3852 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3853} 3854``` 3855 3856## on('windowVisibilityChange')<sup>11+</sup> 3857 3858on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 3859 3860Subscribes to the visibility status change event of this window. 3861 3862**Atomic service API**: This API can be used in atomic services since API version 12. 3863 3864**System capability**: SystemCapability.Window.SessionManager 3865 3866**Parameters** 3867 3868| Name | Type | Mandatory| Description | 3869| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3870| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 3871| callback | Callback<boolean> | Yes | Callback used to return the visibility status of the window, which is a Boolean value. **true** if visible, **false** otherwise. | 3872 3873**Error codes** 3874 3875For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3876 3877| ID| Error Message| 3878| ------- | ------------------------------ | 3879| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3880| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3881| 1300002 | This window state is abnormal. | 3882| 1300003 | This window manager service works abnormally. | 3883 3884**Example** 3885 3886```ts 3887try { 3888 windowClass.on('windowVisibilityChange', (boolean) => { 3889 console.info('Window visibility changed, isVisible=' + boolean); 3890 }); 3891} catch (exception) { 3892 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3893} 3894``` 3895 3896## off('windowVisibilityChange')<sup>11+</sup> 3897 3898off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 3899 3900Unsubscribes from the visibility status change event of this window. 3901 3902**Atomic service API**: This API can be used in atomic services since API version 12. 3903 3904**System capability**: SystemCapability.Window.SessionManager 3905 3906**Parameters** 3907 3908| Name | Type | Mandatory| Description | 3909| -------- |----------------------------| ---- |--------------------------------------| 3910| type | string | Yes | Event type. The value is fixed at **'windowVisibilityChange'**, indicating the visibility status change event.| 3911| 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. | 3912 3913**Error codes** 3914 3915For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3916 3917| ID| Error Message| 3918| ------- | ------------------------------ | 3919| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3920| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3921| 1300002 | This window state is abnormal. | 3922| 1300003 | This window manager service works abnormally. | 3923 3924**Example** 3925 3926```ts 3927const callback = (bool: boolean) => { 3928 // ... 3929} 3930try { 3931 // Enable listening through the on API. 3932 windowClass.on('windowVisibilityChange', callback); 3933 // Disable the listening of a specified callback. 3934 windowClass.off('windowVisibilityChange', callback); 3935 // Unregister all the callbacks that have been registered through on(). 3936 windowClass.off('windowVisibilityChange'); 3937} catch (exception) { 3938 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3939} 3940``` 3941 3942## on('systemDensityChange')<sup>15+</sup> 3943 3944on(type: 'systemDensityChange', callback: Callback<number>): void 3945 3946Subscribes to the system density change event, which is triggered when the system's display size scale factor changes for the screen where the window is located. 3947 3948**Atomic service API**: This API can be used in atomic services since API version 15. 3949 3950**System capability**: SystemCapability.Window.SessionManager 3951 3952**Parameters** 3953 3954| Name | Type | Mandatory| Description | 3955| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3956| type | string | Yes | Event type. The value is fixed at **'systemDensityChange'**, indicating the system density change event.| 3957| callback | Callback<number> | Yes | Callback invoked when the system's display size scale factor changes. The callback contains a parameter of the number type, indicating the new scale factor. | 3958 3959**Error codes** 3960 3961 3962For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 3963 3964| ID| Error Message| 3965| ------- | ------------------------------ | 3966| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3967| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3968| 1300002 | This window state is abnormal. | 3969 3970**Example** 3971 3972```ts 3973const callback = (density: number) => { 3974 console.info('System density changed, density=' + JSON.stringify(density)); 3975} 3976try { 3977 windowClass.on('systemDensityChange', callback); 3978} catch (exception) { 3979 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3980} 3981``` 3982## off('systemDensityChange')<sup>15+</sup> 3983 3984off(type: 'systemDensityChange', callback?: Callback<number>): void 3985 3986Unsubscribes from the system density change event. 3987 3988**Atomic service API**: This API can be used in atomic services since API version 15. 3989 3990**System capability**: SystemCapability.Window.SessionManager 3991 3992**Parameters** 3993 3994| Name | Type | Mandatory| Description | 3995| -------- |----------------------------| ---- |--------------------------------------| 3996| type | string | Yes | Event type. The value is fixed at **'systemDensityChange'**, indicating the system density change event.| 3997| callback | Callback<number> | No | Callback invoked when the system's display size scale factor changes. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3998 3999**Error codes** 4000 4001For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4002 4003| ID| Error Message| 4004| ------- | ------------------------------ | 4005| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4006| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4007| 1300002 | This window state is abnormal. | 4008 4009**Example** 4010 4011```ts 4012const callback = (density: number) => { 4013 // ... 4014} 4015try { 4016 // Enable listening through the on API. 4017 windowClass.on('systemDensityChange', callback); 4018 // Disable the listening of a specified callback. 4019 windowClass.off('systemDensityChange', callback); 4020 // Unregister all the callbacks that have been registered through on(). 4021 windowClass.off('systemDensityChange'); 4022} catch (exception) { 4023 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4024} 4025``` 4026 4027## on('noInteractionDetected')<sup>12+</sup> 4028 4029on(type: 'noInteractionDetected', timeout: number, callback: Callback<void>): void 4030 4031Subscribes to non-interaction events in a window within the specified period. 4032 4033Interaction events include physical keyboard input events and screen touch/click events, but not soft keyboard input events. 4034 4035**Atomic service API**: This API can be used in atomic services since API version 12. 4036 4037**System capability**: SystemCapability.Window.SessionManager 4038 4039**Parameters** 4040 4041| Name | Type | Mandatory| Description | 4042| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4043| type | string | Yes | Event type. The value is fixed at **'noInteractionDetected'**, indicating that there is no interaction event in the window within the specified period.| 4044| timeout | number | Yes | Period during which no interaction is performed, in seconds. The value must be an integer. Negative numbers and decimals are invalid.| 4045| callback | Callback<void> | Yes | Callback invoked when there is no interaction event in the current window within the specified period. | 4046 4047**Error codes** 4048 4049For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4050 4051| ID| Error Message| 4052| ------- | ------------------------------ | 4053| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4054| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4055| 1300002 | This window state is abnormal. | 4056| 1300003 | This window manager service works abnormally. | 4057 4058**Example** 4059 4060```ts 4061try { 4062 windowClass.on('noInteractionDetected', 60, () => { 4063 console.info('no interaction in 60s'); 4064 }); 4065} catch (exception) { 4066 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4067} 4068``` 4069 4070## off('noInteractionDetected')<sup>12+</sup> 4071 4072off(type: 'noInteractionDetected', callback?: Callback<void>): void 4073 4074Unsubscribes from non-interaction events in a window within the specified period. 4075 4076Interaction events include physical keyboard input events and screen touch/click events, but not soft keyboard input events. 4077 4078**Atomic service API**: This API can be used in atomic services since API version 12. 4079 4080**System capability**: SystemCapability.Window.SessionManager 4081 4082**Parameters** 4083 4084| Name | Type | Mandatory| Description | 4085| -------- |----------------------------| ---- |--------------------------------------| 4086| type | string | Yes | Event type. The value is fixed at **'noInteractionDetected'**, indicating that there is no interaction event in the window within the specified period.| 4087| callback | Callback<void> | No | Callback invoked when there is no interaction event in the current window within the specified period. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4088 4089**Error codes** 4090 4091For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4092 4093| ID| Error Message| 4094| ------- | ------------------------------ | 4095| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4096| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4097| 1300002 | This window state is abnormal. | 4098| 1300003 | This window manager service works abnormally. | 4099 4100**Example** 4101 4102```ts 4103const callback = () => { 4104 // ... 4105} 4106try { 4107 windowClass.on('noInteractionDetected', 60, callback); 4108 windowClass.off('noInteractionDetected', callback); 4109 // Unregister all the callbacks that have been registered through on(). 4110 windowClass.off('noInteractionDetected'); 4111} catch (exception) { 4112 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4113} 4114``` 4115 4116## on('windowStatusChange')<sup>11+</sup> 4117 4118on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 4119 4120Subscribes to the window status change event. A notification is sent when the window status changes (the window properties may not be updated). 4121 4122**Atomic service API**: This API can be used in atomic services since API version 12. 4123 4124**System capability**: SystemCapability.Window.SessionManager 4125 4126**Parameters** 4127 4128| Name | Type | Mandatory| Description | 4129| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4130| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 4131| callback | Callback<[WindowStatusType](arkts-apis-window-e.md#windowstatustype11)> | Yes | Callback used to return the window status. | 4132 4133**Error codes** 4134 4135For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4136 4137| ID| Error Message| 4138| ------- | ------------------------------ | 4139| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4140| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4141 4142**Example** 4143 4144```ts 4145try { 4146 windowClass.on('windowStatusChange', (WindowStatusType) => { 4147 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 4148 }); 4149} catch (exception) { 4150 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4151} 4152``` 4153 4154## off('windowStatusChange')<sup>11+</sup> 4155 4156off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 4157 4158Unsubscribes from the window status change event. 4159 4160**Atomic service API**: This API can be used in atomic services since API version 12. 4161 4162**System capability**: SystemCapability.Window.SessionManager 4163 4164**Parameters** 4165 4166| Name | Type | Mandatory| Description | 4167| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 4168| type | string | Yes | Event type. The value is fixed at **'windowStatusChange'**, indicating the window status change event.| 4169| callback | Callback<[WindowStatusType](arkts-apis-window-e.md#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. | 4170 4171**Error codes** 4172 4173For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4174 4175| ID| Error Message| 4176| ------- | ------------------------------ | 4177| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4178| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4179 4180**Example** 4181 4182```ts 4183const callback = (windowStatusType: window.WindowStatusType) => { 4184 // ... 4185} 4186try { 4187 windowClass.on('windowStatusChange', callback); 4188 windowClass.off('windowStatusChange', callback); 4189 // Unregister all the callbacks that have been registered through on(). 4190 windowClass.off('windowStatusChange'); 4191} catch (exception) { 4192 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4193} 4194``` 4195 4196## on('windowStatusDidChange')<sup>20+</sup> 4197 4198on(type: 'windowStatusDidChange', callback: Callback<WindowStatusType>): void 4199 4200Subscribes to the event indicating that the window status has changed (the [Rect](arkts-apis-window-i.md#rect7) property of the window has been updated). 4201 4202**System capability**: SystemCapability.Window.SessionManager 4203 4204**Parameters** 4205 4206| Name | Type | Mandatory| Description | 4207| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4208| type | string | Yes | Event type. The value is fixed at **'windowStatusDidChange'**, indicating that the window status has changed.| 4209| callback | Callback<[WindowStatusType](arkts-apis-window-e.md#windowstatustype11)> | Yes | Callback used to return the window status. | 4210 4211**Error codes** 4212 4213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4214 4215| ID| Error Message| 4216| ------- | ------------------------------ | 4217| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4218| 1300002 | This window state is abnormal. | 4219 4220**Example** 4221 4222```ts 4223try { 4224 windowClass.on('windowStatusDidChange', (WindowStatusType) => { 4225 console.info(`Succeeded in enabling the listener for window status changes. Data: ${JSON.stringify(WindowStatusType)}`); 4226 }); 4227} catch (exception) { 4228 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4229} 4230``` 4231 4232## off('windowStatusDidChange')<sup>20+</sup> 4233 4234off(type: 'windowStatusDidChange', callback?: Callback<WindowStatusType>): void 4235 4236Unsubscribes from the event indicating that the window status has changed. 4237 4238**System capability**: SystemCapability.Window.SessionManager 4239 4240**Parameters** 4241 4242| Name | Type | Mandatory| Description | 4243| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 4244| type | string | Yes | Event type. The value is fixed at **'windowStatusDidChange'**, indicating that the window status has changed.| 4245| callback | Callback<[WindowStatusType](arkts-apis-window-e.md#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. | 4246 4247**Error codes** 4248 4249For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 4250 4251| ID| Error Message| 4252| ------- | ------------------------------ | 4253| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4254| 1300002 | This window state is abnormal. | 4255 4256**Example** 4257 4258```ts 4259const callback = (windowStatusType: window.WindowStatusType) => { 4260 // ... 4261} 4262try { 4263 windowClass.on('windowStatusDidChange', callback); 4264 windowClass.off('windowStatusDidChange', callback); 4265 // Unregister all the callbacks that have been registered through on(). 4266 windowClass.off('windowStatusDidChange'); 4267} catch (exception) { 4268 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4269} 4270``` 4271 4272## setWindowGrayScale<sup>12+</sup> 4273 4274setWindowGrayScale(grayScale: number): Promise<void> 4275 4276Sets the grayscale effect for this window. This API uses a promise to return the result. This API can be called only after [loadContent()](#loadcontent9) or [setUIContent()](#setuicontent9) is called. 4277 4278**Atomic service API**: This API can be used in atomic services since API version 12. 4279 4280**System capability**: SystemCapability.Window.SessionManager 4281 4282**Parameters** 4283 4284| Name| Type| Mandatory| Description | 4285| --------- | ------ | -- | ---------------------------------------- | 4286| grayScale | number | Yes| Grayscale of the window. The value is a floating-point number in the range [0.0, 1.0]. The value **0.0** means that the window image does not change, and **1.0** means that the window image is completely turned into grayscale. The effect changes linearly between 0.0 and 1.0.| 4287 4288**Return value** 4289 4290| Type| Description| 4291| ------------------- | ------------------------ | 4292| Promise<void> | Promise that returns no value.| 4293 4294**Error codes** 4295 4296For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4297 4298| ID| Error Message| 4299| ------- | --------------------------------------------- | 4300| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4301| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4302| 1300002 | This window state is abnormal. | 4303| 1300003 | This window manager service works abnormally. | 4304 4305**Example** 4306 4307```ts 4308import { BusinessError } from '@kit.BasicServicesKit'; 4309 4310windowClass?.setUIContent('pages/Index', (error: BusinessError) => { 4311 if (error.code) { 4312 console.error(`Failed to set the content. Cause code: ${error.code}`); 4313 return; 4314 } 4315 console.info('Succeeded in setting the content.'); 4316 let grayScale: number = 0.5; 4317 try { 4318 if (canIUse("SystemCapability.Window.SessionManager")) { 4319 let promise = windowClass?.setWindowGrayScale(grayScale); 4320 promise?.then(() => { 4321 console.info('Succeeded in setting the grayScale.'); 4322 }).catch((err: BusinessError) => { 4323 console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`); 4324 }); 4325 } 4326 } catch (exception) { 4327 console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`); 4328 } 4329}); 4330``` 4331 4332## on('windowTitleButtonRectChange')<sup>11+</sup> 4333 4334on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 4335 4336Subscribes to the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar of the window. This API takes effect for the window that has a title bar or a three-button area. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 4337 4338**Atomic service API**: This API can be used in atomic services since API version 12. 4339 4340**System capability**: SystemCapability.Window.SessionManager 4341 4342**Parameters** 4343 4344| Name | Type | Mandatory| Description | 4345| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4346| 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.| 4347| callback | Callback<[TitleButtonRect](arkts-apis-window-i.md#titlebuttonrect11)> | Yes | Callback used to return the new rectangle.| 4348 4349**Error codes** 4350 4351For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4352 4353| ID| Error Message | 4354| -------- | ------------------------------ | 4355| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4356| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4357| 1300002 | This window state is abnormal. | 4358 4359**Example** 4360 4361```ts 4362windowClass.setUIContent('pages/WindowPage').then(() => { 4363 try { 4364 windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => { 4365 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 4366 }); 4367 } catch (exception) { 4368 console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4369 } 4370}) 4371``` 4372 4373## off('windowTitleButtonRectChange')<sup>11+</sup> 4374 4375off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 4376 4377Unsubscribes from the change event of the rectangle that holds the minimize, maximize, and close buttons on the title bar of the window. This API takes effect for the window that has a title bar or a three-button area. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 4378 4379**Atomic service API**: This API can be used in atomic services since API version 12. 4380 4381**System capability**: SystemCapability.Window.SessionManager 4382 4383**Parameters** 4384 4385| Name | Type | Mandatory| Description | 4386| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4387| 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.| 4388| callback | Callback<[TitleButtonRect](arkts-apis-window-i.md#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.| 4389 4390**Error codes** 4391 4392For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4393 4394| ID| Error Message | 4395| -------- | ------------------------------ | 4396| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4397| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4398| 1300002 | This window state is abnormal. | 4399 4400**Example** 4401 4402```ts 4403windowClass.setUIContent('pages/WindowPage').then(() => { 4404 const callback = (titleButtonRect: window.TitleButtonRect) => { 4405 // ... 4406 } 4407 try { 4408 // Enable listening through the on API. 4409 windowClass?.on('windowTitleButtonRectChange', callback); 4410 // Disable the listening of a specified callback. 4411 windowClass?.off('windowTitleButtonRectChange', callback); 4412 // Unregister all the callbacks that have been registered through on(). 4413 windowClass?.off('windowTitleButtonRectChange'); 4414 } catch (exception) { 4415 console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4416 } 4417}) 4418``` 4419 4420## on('windowRectChange')<sup>12+</sup> 4421 4422on(type: 'windowRectChange', callback: Callback<RectChangeOptions>): void 4423 4424Subscribes to window rectangle (position and size) change events. 4425 4426**System capability**: SystemCapability.Window.SessionManager 4427 4428**Atomic service API**: This API can be used in atomic services since API version 12. 4429 4430**Parameters** 4431 4432| Name | Type | Mandatory| Description | 4433| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4434| type | string | Yes | Event type. The value is fixed at **'windowRectChange'**, indicating the window rectangle change event.| 4435| callback | Callback<[RectChangeOptions](arkts-apis-window-i.md#rectchangeoptions12)> | Yes | Callback used to return the value and reason of the window rectangle change. | 4436 4437**Error codes** 4438 4439For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4440 4441| ID| Error Message| 4442| ------- | -------------------------------------------- | 4443| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4444| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4445| 1300002 | This window state is abnormal. | 4446| 1300003 | This window manager service works abnormally. | 4447 4448**Example** 4449 4450```ts 4451try { 4452 windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 4453 console.info(`Succeeded in enabling the listener for window rect changes. Data: ` + JSON.stringify(data)); 4454 }); 4455} catch (exception) { 4456 console.error(`Failed to disable the listener for window rect changes. Cause code: ${exception.code}, message: ${exception.message}`); 4457} 4458``` 4459 4460## off('windowRectChange')<sup>12+</sup> 4461 4462off(type: 'windowRectChange', callback?: Callback<RectChangeOptions>): void 4463 4464Unsubscribes from window rectangle (position and size) change events. 4465 4466**System capability**: SystemCapability.Window.SessionManager 4467 4468**Atomic service API**: This API can be used in atomic services since API version 12. 4469 4470**Parameters** 4471 4472| Name | Type | Mandatory| Description | 4473| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4474| type | string | Yes | Event type. The value is fixed at **'windowRectChange'**, indicating the window rectangle change event. | 4475| callback | Callback<[RectChangeOptions](arkts-apis-window-i.md#rectchangeoptions12)> | No | Callback used to return the value and reason of the window rectangle change. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4476 4477**Error codes** 4478 4479For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4480 4481| ID| Error Message| 4482| ------- | -------------------------------------------- | 4483| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4484| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4485| 1300002 | This window state is abnormal. | 4486| 1300003 | This window manager service works abnormally. | 4487 4488**Example** 4489 4490```ts 4491const callback = (rectChangeOptions: window.RectChangeOptions) => { 4492 // ... 4493} 4494 4495try { 4496 windowClass.on('windowRectChange', callback); 4497 windowClass.off('windowRectChange', callback); 4498 // Unregister all the callbacks that have been registered through on(). 4499 windowClass.off('windowRectChange'); 4500} catch (exception) { 4501 console.error(`Failed to disable the listener for window rect changes. Cause code: ${exception.code}, message: ${exception.message}`); 4502} 4503``` 4504 4505## on('rectChangeInGlobalDisplay')<sup>20+</sup> 4506 4507on(type: 'rectChangeInGlobalDisplay', callback: Callback<RectChangeOptions>): void 4508 4509Subscribes to window rectangle (position and size) change events in the global coordinate system. (In extended screen scenarios, the upper-left corner of the primary screen is used as the origin.) 4510 4511**System capability**: SystemCapability.Window.SessionManager 4512 4513**Parameters** 4514 4515| Name | Type | Mandatory| Description | 4516| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4517| type | string | Yes | Event type. The value is fixed at **'rectChangeInGlobalDisplay'**, indicating the window rectangle change event in the global coordinate system.| 4518| callback | Callback<[RectChangeOptions](arkts-apis-window-i.md#rectchangeoptions12)> | Yes | Callback used to return the value and reason of the window rectangle change.| 4519 4520**Error codes** 4521 4522For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4523 4524| ID| Error Message| 4525| ------- | -------------------------------------------- | 4526| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4527| 1300002 | This window state is abnormal. | 4528| 1300003 | This window manager service works abnormally. | 4529 4530**Example** 4531 4532```ts 4533const callback = (rectChangeOptions: window.RectChangeOptions) => { 4534 console.info(`Succeeded in enabling the listener for window rect changes in global display. Data: ` + JSON.stringify(rectChangeOptions)); 4535} 4536 4537try { 4538 windowClass.on('rectChangeInGlobalDisplay', callback); 4539} catch (exception) { 4540 console.error(`Failed to disable the listener for window rect changes in global display. Cause code: ${exception.code}, message: ${exception.message}`); 4541} 4542``` 4543 4544## off('rectChangeInGlobalDisplay')<sup>20+</sup> 4545 4546off(type: 'rectChangeInGlobalDisplay', callback?: Callback<RectChangeOptions>): void 4547 4548Unsubscribes from window rectangle (position and size) change events in the global coordinate system. (In extended screen scenarios, the upper-left corner of the primary screen is used as the origin.) 4549 4550**System capability**: SystemCapability.Window.SessionManager 4551 4552**Parameters** 4553 4554| Name | Type | Mandatory| Description | 4555| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4556| type | string | Yes | Event type. The value is fixed at **'rectChangeInGlobalDisplay'**, indicating the window rectangle change event in the global coordinate system. | 4557| callback | Callback<[RectChangeOptions](arkts-apis-window-i.md#rectchangeoptions12)> | No | Callback used to return the value and reason of the window rectangle change. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4558 4559**Error codes** 4560 4561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4562 4563| ID| Error Message| 4564| ------- | -------------------------------------------- | 4565| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4566| 1300002 | This window state is abnormal. | 4567| 1300003 | This window manager service works abnormally. | 4568 4569**Example** 4570 4571```ts 4572const callback = (rectChangeOptions: window.RectChangeOptions) => { 4573 // ... 4574} 4575 4576try { 4577 windowClass.on('rectChangeInGlobalDisplay', callback); 4578 windowClass.off('rectChangeInGlobalDisplay', callback); 4579 // Unregister all the callbacks that have been registered through on(). 4580 windowClass.off('rectChangeInGlobalDisplay'); 4581} catch (exception) { 4582 console.error(`Failed to disable the listener for window rect changes in global display. Cause code: ${exception.code}, message: ${exception.message}`); 4583} 4584``` 4585 4586## on('subWindowClose')<sup>12+</sup> 4587 4588on(type: 'subWindowClose', callback: Callback<void>): void 4589 4590Subscribes to the event indicating that the child window is closed. This event is triggered only when the user clicks the system-provided close button in the upper-right corner to close the child window. It is not triggered when the child window is closed in other ways. 4591 4592If the event is subscribed to multiple times, only the most recently subscribed-to event takes effect. 4593 4594The callback function in this API is executed synchronously. For asynchronous close events of child windows, refer to [on('windowWillClose')](#onwindowwillclose15). 4595 4596If there is an existing event subscribed to by calling [on('windowWillClose')](#onwindowwillclose15), only the [on('windowWillClose')](#onwindowwillclose15) API will be responded to. 4597 4598**Atomic service API**: This API can be used in atomic services since API version 12. 4599 4600**System capability**: SystemCapability.Window.SessionManager 4601 4602**Parameters** 4603 4604| Name | Type | Mandatory| Description | 4605| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4606| type | string | Yes | Event type. The value is fixed at **'subWindowClose'**, indicating the child window close event.| 4607| callback | Callback<void> | Yes | Callback invoked when the close button in the upper-right corner of the child window is clicked. It does not return any parameter. The return value of the internal logic of the callback function determines whether to continue to close the child window. If **true** of the Boolean type is returned, the child window is not closed. If **false** or other non-Boolean types are returned, the child window is closed. | 4608 4609**Error codes** 4610 4611For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4612 4613| ID| Error Message| 4614| ------- | -------------------------------------------- | 4615| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4616| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4617| 1300002 | This window state is abnormal. | 4618| 1300004 | Unauthorized operation. | 4619 4620**Example** 4621 4622```ts 4623const callback = () => { 4624 // ... 4625 return true; 4626} 4627try { 4628 windowClass.on('subWindowClose', callback); 4629} catch (exception) { 4630 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4631} 4632``` 4633 4634## off('subWindowClose')<sup>12+</sup> 4635 4636off(type: 'subWindowClose', callback?: Callback<void>): void 4637 4638Unsubscribes from the event indicating that the child window is closed. 4639 4640**Atomic service API**: This API can be used in atomic services since API version 12. 4641 4642**System capability**: SystemCapability.Window.SessionManager 4643 4644**Parameters** 4645 4646| Name | Type | Mandatory| Description | 4647| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4648| type | string | Yes | Event type. The value is fixed at **'subWindowClose'**, indicating the child window close event. | 4649| callback | Callback<void> | No | Callback invoked when the close button in the upper-right corner of the child window is clicked. It does not return any parameter. The return value of the internal logic of the callback function determines whether to continue to close the child window. If **true** of the Boolean type is returned, the child window is not closed. If **false** or other non-Boolean types are returned, the child window is closed. 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.| 4650 4651**Error codes** 4652 4653For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4654 4655| ID| Error Message| 4656| ------- | -------------------------------------------- | 4657| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4658| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4659| 1300002 | This window state is abnormal. | 4660| 1300004 | Unauthorized operation. | 4661 4662**Example** 4663 4664```ts 4665const callback = () => { 4666 // ... 4667 return true; 4668} 4669try { 4670 windowClass.on('subWindowClose', callback); 4671 windowClass.off('subWindowClose', callback); 4672 // Unregister all the callbacks that have been registered through on(). 4673 windowClass.off('subWindowClose'); 4674} catch (exception) { 4675 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4676} 4677``` 4678 4679## on('windowWillClose')<sup>15+</sup> 4680 4681on(type: 'windowWillClose', callback: Callback<void, Promise<boolean>>): void 4682 4683Subscribes to the event indicating that the main window or child window will be closed. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. This event is triggered only when the user clicks the close button in the system-provided title bar to close the window. It is not triggered when the window is closed in other ways. 4684 4685The callback function in this API is executed synchronously. For synchronous close events of child windows, refer to [on('subWindowClose')](#onsubwindowclose12). For synchronous close events of the main window, refer to [on('windowStageClose')](arkts-apis-window-WindowStage.md#onwindowstageclose14). 4686 4687**Atomic service API**: This API can be used in atomic services since API version 15. 4688 4689**System capability**: SystemCapability.Window.SessionManager 4690 4691**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 4692 4693**Parameters** 4694 4695| Name | Type | Mandatory| Description | 4696| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4697| type | string | Yes | Event type. The value is fixed at **'windowWillClose'**, indicating the window close event.| 4698| callback | Callback<void, Promise<boolean>> | Yes | Callback invoked when the close button in the upper-right corner of the window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Promise<boolean> type. In the returned Promise function, **resolve(true)** means not to close the window, and **resolve(false)** or **reject** means to continue to close the window.| 4699 4700**Error codes** 4701 4702For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4703 4704| ID| Error Message| 4705| ------- | -------------------------------------------- | 4706| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4707| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4708| 1300002 | This window state is abnormal. | 4709| 1300004 | Unauthorized operation. | 4710 4711**Example** 4712 4713```ts 4714// EntryAbility.ets 4715import { UIAbility } from '@kit.AbilityKit'; 4716import { window } from '@kit.ArkUI'; 4717 4718export default class EntryAbility extends UIAbility { 4719 4720 onWindowStageCreate(windowStage: window.WindowStage) { 4721 console.info('onWindowStageCreate'); 4722 const callback = () => { 4723 // ... 4724 return new Promise<boolean>((resolve, reject) => { 4725 // Whether to close the window. 4726 let result: boolean = true; 4727 resolve(result); 4728 }); 4729 } 4730 try { 4731 let windowClass = windowStage.getMainWindowSync(); 4732 windowClass.on('windowWillClose', callback); 4733 } catch (exception) { 4734 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4735 } 4736 } 4737} 4738``` 4739 4740## off('windowWillClose')<sup>15+</sup> 4741 4742off(type: 'windowWillClose', callback?: Callback<void, Promise<boolean>>): void 4743 4744Unsubscribes from the event indicating that the main window or child window will be closed. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 4745 4746**Atomic service API**: This API can be used in atomic services since API version 15. 4747 4748**System capability**: SystemCapability.Window.SessionManager 4749 4750**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, it has no effect and does not report errors. 4751 4752**Parameters** 4753 4754| Name | Type | Mandatory| Description | 4755| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4756| type | string | Yes | Event type. The value is fixed at **'windowWillClose'**, indicating the window close event.| 4757| callback | Callback<void, Promise<boolean>> | No | Callback invoked when the close button in the upper-right corner of the window is clicked. It does not return any parameter. The internal logic of the callback function requires a return value of the Promise<boolean> type. In the returned Promise function, **resolve(true)** means not to close the window, and **resolve(false)** or **reject** means to continue to close the window.| 4758 4759**Error codes** 4760 4761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4762 4763| ID| Error Message| 4764| ------- | -------------------------------------------- | 4765| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4766| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4767| 1300002 | This window state is abnormal. | 4768| 1300004 | Unauthorized operation. | 4769 4770**Example** 4771 4772```ts 4773// EntryAbility.ets 4774import { UIAbility } from '@kit.AbilityKit'; 4775import { window } from '@kit.ArkUI'; 4776 4777export default class EntryAbility extends UIAbility { 4778 4779 onWindowStageCreate(windowStage: window.WindowStage) { 4780 console.info('onWindowStageCreate'); 4781 try { 4782 const callback = () => { 4783 // ... 4784 return new Promise<boolean>((resolve, reject) => { 4785 // Whether to close the window. 4786 let result: boolean = true; 4787 resolve(result); 4788 }); 4789 } 4790 let windowClass = windowStage.getMainWindowSync(); 4791 windowClass.on('windowWillClose', callback); 4792 windowClass.off('windowWillClose', callback); 4793 // Unregister all the callbacks that have been registered through on(). 4794 windowClass.off('windowWillClose'); 4795 } catch (exception) { 4796 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4797 } 4798 } 4799} 4800``` 4801 4802## on('windowHighlightChange')<sup>15+</sup> 4803 4804on(type: 'windowHighlightChange', callback: Callback<boolean>): void 4805 4806Subscribes to the highlighted state change event of the window. 4807 4808**Atomic service API**: This API can be used in atomic services since API version 15. 4809 4810**System capability**: SystemCapability.Window.SessionManager 4811 4812**Parameters** 4813 4814| Name | Type | Mandatory| Description | 4815| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4816| type | string | Yes | Event type. The value is fixed at **'windowHighlightChange'**, indicating the window highlighted state change event.| 4817| callback | Callback<boolean> | Yes | Callback used to return the highlighted state of the window. which is a Boolean value. **true** if highlighted, **false** otherwise. | 4818 4819**Error codes** 4820 4821For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4822 4823| ID| Error Message| 4824| ------- | -------------------------------------------- | 4825| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4826| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4827| 1300002 | This window state is abnormal. | 4828| 1300003 | This window manager service works abnormally. | 4829 4830**Example** 4831 4832```ts 4833try { 4834 windowClass.on('windowHighlightChange', (data: boolean) => { 4835 console.info(`Window highlight Change: ${data}`); 4836 }); 4837} catch (exception) { 4838 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4839} 4840``` 4841 4842## off('windowHighlightChange')<sup>15+</sup> 4843 4844off(type: 'windowHighlightChange', callback?: Callback<boolean>): void 4845 4846Unsubscribes from the highlighted state change event of the window. 4847 4848**Atomic service API**: This API can be used in atomic services since API version 15. 4849 4850**System capability**: SystemCapability.Window.SessionManager 4851 4852**Parameters** 4853 4854| Name | Type | Mandatory| Description | 4855| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4856| type | string | Yes | Event type. The value is fixed at **'windowHighlightChange'**, indicating the window highlighted state change event. | 4857| callback | Callback<boolean> | No | Callback used to return the highlighted state of the window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 4858 4859**Error codes** 4860 4861For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4862 4863| ID| Error Message| 4864| ------- | -------------------------------------------- | 4865| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4866| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4867| 1300002 | This window state is abnormal. | 4868| 1300003 | This window manager service works abnormally. | 4869 4870**Example** 4871 4872```ts 4873const callback = (data: boolean) => { 4874 // ... 4875} 4876try { 4877 // Enable listening through the on API. 4878 windowClass.on('windowHighlightChange', callback); 4879 // Disable the listening of a specified callback. 4880 windowClass.off('windowHighlightChange', callback); 4881 // Unregister all the callbacks that have been registered through on(). 4882 windowClass.off('windowHighlightChange'); 4883} catch (exception) { 4884 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4885} 4886``` 4887 4888## on('rotationChange')<sup>19+</sup> 4889 4890on(type: 'rotationChange', callback: RotationChangeCallback<RotationChangeInfo, RotationChangeResult | void>): void 4891 4892Subscribes to the window rotation change event. If the window rotation event type in [RotationChangeInfo](arkts-apis-window-i.md#rotationchangeinfo19) is **WINDOW_WILL_ROTATE**, [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19) must be returned. If the window rotation event type is **WINDOW_DID_ROTATE**, [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19) does not take effect. 4893 4894This API can be registered only on the main thread. If a window registers multiple callbacks of the same type, only the return value of the most recently registered callback will be effective. The system provides a timeout protection mechanism. If the window does not return [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19) within 20 ms, the system does not process the return value. 4895 4896<!--RP10-->This API has no effect on 2-in-1 devices.<!--RP10End--> 4897 4898**Atomic service API**: This API can be used in atomic services since API version 19. 4899 4900**System capability**: SystemCapability.Window.SessionManager 4901 4902**Parameters** 4903 4904| Name | Type | Mandatory| Description | 4905| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4906| type | string | Yes | Event type. The value is fixed at **'rotationChange'**, indicating the window rotation change event.| 4907| callback | RotationChangeCallback<[RotationChangeInfo](arkts-apis-window-i.md#rotationchangeinfo19), [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19) \| void> | Yes| Callback used to return [RotationChangeInfo](arkts-apis-window-i.md#rotationchangeinfo19) and [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19). | 4908 4909**Error codes** 4910 4911For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4912 4913| ID| Error Message| 4914| ------- | -------------------------------------------- | 4915| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4916| 1300002 | This window state is abnormal. | 4917| 1300003 | This window manager service works abnormally. | 4918 4919**Example** 4920 4921```ts 4922function calculateRect(info: window.RotationChangeInfo): window.Rect { 4923 // calculate result with info 4924 let rect : window.Rect = { 4925 left: 0, 4926 top: 0, 4927 width: 500, 4928 height: 600, 4929 } 4930 return rect; 4931} 4932 4933const callback = (info: window.RotationChangeInfo): window.RotationChangeResult | void => { 4934 let result: window.RotationChangeResult = { 4935 rectType: window.RectType.RELATIVE_TO_SCREEN, 4936 windowRect: { 4937 left: 0, 4938 top: 0, 4939 width: 0, 4940 height: 0, 4941 } 4942 }; 4943 if (info.type === window.RotationChangeType.WINDOW_WILL_ROTATE) { 4944 result.rectType = window.RectType.RELATIVE_TO_SCREEN; 4945 result.windowRect = calculateRect(info); 4946 return result; 4947 } else { 4948 // do something after rotate 4949 return; 4950 } 4951} 4952 4953try { 4954 windowClass.on('rotationChange', callback); 4955} catch (exception) { 4956 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4957} 4958``` 4959 4960## off('rotationChange')<sup>19+</sup> 4961 4962off(type: 'rotationChange', callback?: RotationChangeCallback<RotationChangeInfo, RotationChangeResult | void>): void 4963 4964Unsubscribes from the window rotation change event. 4965 4966<!--RP10-->This API has no effect on 2-in-1 devices.<!--RP10End--> 4967 4968**Atomic service API**: This API can be used in atomic services since API version 19. 4969 4970**System capability**: SystemCapability.Window.SessionManager 4971 4972**Parameters** 4973 4974| Name | Type | Mandatory| Description | 4975| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4976| type | string | Yes | Event type. The value is fixed at **'rotationChange'**, indicating the window rotation change event. | 4977| callback | RotationChangeCallback<[RotationChangeInfo](arkts-apis-window-i.md#rotationchangeinfo19), [RotationChangeResult](arkts-apis-window-i.md#rotationchangeresult19) \| void> | No | Callback used to return the result. 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.| 4978 4979**Error codes** 4980 4981For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 4982 4983| ID| Error Message| 4984| ------- | -------------------------------------------- | 4985| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4986| 1300002 | This window state is abnormal. | 4987| 1300003 | This window manager service works abnormally. | 4988 4989**Example** 4990 4991```ts 4992const callback = (info: window.RotationChangeInfo): window.RotationChangeResult | void => { 4993 // ... 4994 return; 4995} 4996try { 4997 windowClass.off('rotationChange', callback); 4998 // Unregister all the callbacks that have been registered through on(). 4999 windowClass.off('rotationChange'); 5000} catch (exception) { 5001 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 5002} 5003``` 5004 5005## on('uiExtensionSecureLimitChange')<sup>20+</sup> 5006 5007on(eventType: 'uiExtensionSecureLimitChange', callback: Callback<boolean>): void 5008 5009Subscribes to the event indicating changes in the security restrictions of the UIExtensionAbility within the window. You are advised to initiate the subscription right after the window is created. 5010 5011**Atomic service API**: This API can be used in atomic services since API version 20. 5012 5013**System capability**: SystemCapability.Window.SessionManager 5014 5015**Parameters** 5016 5017| Name | Type | Mandatory| Description | 5018| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5019| eventType | string | Yes | Event type. The value is fixed at **'uiExtensionSecureLimitChange'**, indicating that the UIExtensionAbility security restrictions in the window changes.| 5020| callback | Callback<boolean> | Yes | Callback used to return the result. The value **true** means that at least one UIExtensionAbility within the window has enabled the hiding of unsafe windows, and **false** means that all UIExtensionAbilities within the window have disabled the hiding of unsafe windows. | 5021 5022**Error codes** 5023 5024For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5025 5026| ID| Error Message| 5027| ------- | -------------------------------------------- | 5028| 801 | Capability not supported.Function on('uiExtensionSecureLimitChange') can not work correctly due to limited device capabilities. | 5029| 1300002 | This window state is abnormal. | 5030| 1300003 | This window manager service works abnormally. | 5031 5032**Example** 5033 5034```ts 5035try { 5036 windowClass.on('uiExtensionSecureLimitChange', (data: boolean) => { 5037 console.info(`Window secure limit Change: ${data}`); 5038 }); 5039} catch (exception) { 5040 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5041} 5042``` 5043 5044## off('uiExtensionSecureLimitChange')<sup>20+</sup> 5045 5046off(eventType: 'uiExtensionSecureLimitChange', callback?: Callback<boolean>): void 5047 5048Unsubscribes from the event indicating changes in the security restrictions of the UIExtensionAbility within the window. 5049 5050**Atomic service API**: This API can be used in atomic services since API version 20. 5051 5052**System capability**: SystemCapability.Window.SessionManager 5053 5054**Parameters** 5055 5056| Name | Type | Mandatory| Description | 5057| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 5058| eventType | string | Yes | Event type. The value is fixed at **'uiExtensionSecureLimitChange'**, indicating that the UIExtensionAbility security restrictions in the window changes. | 5059| callback | Callback<boolean> | No | Callback used to return the result. 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.| 5060 5061**Error codes** 5062 5063For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5064 5065| ID| Error Message| 5066| ------- | -------------------------------------------- | 5067| 801 | Capability not supported.Function off('uiExtensionSecureLimitChange') can not work correctly due to limited device capabilities. | 5068| 1300002 | This window state is abnormal. | 5069| 1300003 | This window manager service works abnormally. | 5070 5071**Example** 5072 5073```ts 5074const callback = (data: boolean) => { 5075 // ... 5076} 5077try { 5078 // Enable listening through the on API. 5079 windowClass.on('uiExtensionSecureLimitChange', callback); 5080 // Disable the listening of a specified callback. 5081 windowClass.off('uiExtensionSecureLimitChange', callback); 5082 // Unregister all the callbacks that have been registered through on(). 5083 windowClass.off('uiExtensionSecureLimitChange'); 5084} catch (exception) { 5085 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 5086} 5087``` 5088 5089## isWindowSupportWideGamut<sup>9+</sup> 5090 5091isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 5092 5093Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 5094 5095**Atomic service API**: This API can be used in atomic services since API version 12. 5096 5097**System capability**: SystemCapability.WindowManager.WindowManager.Core 5098 5099**Parameters** 5100 5101| Name| Type| Mandatory| Description| 5102| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 5103| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. **true** if the wide-gamut color space is supported, **false** otherwise.| 5104 5105**Error codes** 5106 5107For details about the error codes, see [Window Error Codes](errorcode-window.md). 5108 5109| ID| Error Message| 5110| ------- | ------------------------------ | 5111| 1300002 | This window state is abnormal. | 5112 5113**Example** 5114 5115```ts 5116import { BusinessError } from '@kit.BasicServicesKit'; 5117 5118windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 5119 const errCode: number = err.code; 5120 if (errCode) { 5121 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5122 return; 5123 } 5124 console.info(`Succeeded in checking whether the window support WideGamut Data: ${data}`); 5125}); 5126``` 5127 5128## isWindowSupportWideGamut<sup>9+</sup> 5129 5130isWindowSupportWideGamut(): Promise<boolean> 5131 5132Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 5133 5134**Atomic service API**: This API can be used in atomic services since API version 12. 5135 5136**System capability**: SystemCapability.WindowManager.WindowManager.Core 5137 5138**Return value** 5139 5140| Type| Description| 5141| ---------------------- | ------------------------------------------------------------------------------------ | 5142| Promise<boolean> | Promise used to return the result. **true** if the wide-gamut color space is supported, **false** otherwise.| 5143 5144**Error codes** 5145 5146For details about the error codes, see [Window Error Codes](errorcode-window.md). 5147 5148| ID| Error Message| 5149| ------- | ------------------------------ | 5150| 1300002 | This window state is abnormal. | 5151 5152**Example** 5153 5154```ts 5155import { BusinessError } from '@kit.BasicServicesKit'; 5156 5157let promise = windowClass.isWindowSupportWideGamut(); 5158promise.then((data) => { 5159 console.info(`Succeeded in checking whether the window support WideGamut. Data: ${data}`); 5160}).catch((err: BusinessError) => { 5161 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5162}); 5163``` 5164 5165## setWindowColorSpace<sup>9+</sup> 5166 5167setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5168 5169Sets a color space for this window. This API uses an asynchronous callback to return the result. 5170 5171**Atomic service API**: This API can be used in atomic services since API version 12. 5172 5173**System capability**: SystemCapability.WindowManager.WindowManager.Core 5174 5175**Parameters** 5176 5177| Name| Type| Mandatory| Description| 5178| ---------- | ------------------------- | -- | ----------- | 5179| colorSpace | [ColorSpace](arkts-apis-window-e.md#colorspace8) | Yes| Color space to set.| 5180| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5181 5182**Error codes** 5183 5184For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5185 5186| ID| Error Message| 5187| ------- | ------------------------------ | 5188| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5189| 1300002 | This window state is abnormal. | 5190 5191**Example** 5192 5193```ts 5194import { BusinessError } from '@kit.BasicServicesKit'; 5195 5196try { 5197 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 5198 const errCode: number = err.code; 5199 if (errCode) { 5200 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5201 return; 5202 } 5203 console.info('Succeeded in setting window colorspace.'); 5204 }); 5205} catch (exception) { 5206 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5207} 5208``` 5209 5210## setWindowColorSpace<sup>9+</sup> 5211 5212setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 5213 5214Sets a color space for this window. This API uses a promise to return the result. 5215 5216**Atomic service API**: This API can be used in atomic services since API version 12. 5217 5218**System capability**: SystemCapability.WindowManager.WindowManager.Core 5219 5220**Parameters** 5221 5222| Name| Type| Mandatory| Description| 5223| ---------- | ------------------------- | -- | ------------- | 5224| colorSpace | [ColorSpace](arkts-apis-window-e.md#colorspace8) | Yes| Color space to set.| 5225 5226**Return value** 5227 5228| Type| Description| 5229| ------------------- | ------------------------ | 5230| Promise<void> | Promise that returns no value.| 5231 5232**Error codes** 5233 5234For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5235 5236| ID| Error Message| 5237| ------- | ------------------------------ | 5238| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5239| 1300002 | This window state is abnormal. | 5240 5241**Example** 5242 5243```ts 5244import { BusinessError } from '@kit.BasicServicesKit'; 5245 5246try { 5247 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 5248 promise.then(() => { 5249 console.info('Succeeded in setting window colorspace.'); 5250 }).catch((err: BusinessError) => { 5251 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5252 }); 5253} catch (exception) { 5254 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5255} 5256``` 5257 5258## getWindowColorSpace<sup>9+</sup> 5259 5260getWindowColorSpace(): ColorSpace 5261 5262Obtains the color space of this window. 5263 5264**Atomic service API**: This API can be used in atomic services since API version 12. 5265 5266**System capability**: SystemCapability.WindowManager.WindowManager.Core 5267 5268**Return value** 5269 5270| Type| Description| 5271| ------------------------- | ------------- | 5272| [ColorSpace](arkts-apis-window-e.md#colorspace8) | Color space obtained.| 5273 5274**Error codes** 5275 5276For details about the error codes, see [Window Error Codes](errorcode-window.md). 5277 5278| ID| Error Message| 5279| ------- | ------------------------------ | 5280| 1300002 | This window state is abnormal. | 5281 5282**Example** 5283 5284```ts 5285import { BusinessError } from '@kit.BasicServicesKit'; 5286 5287try { 5288 let colorSpace = windowClass.getWindowColorSpace(); 5289 console.info(`Succeeded in getting the window color space. ColorSpace: ${colorSpace}`); 5290} catch (exception) { 5291 console.error(`Failed to get the window color space. Cause code: ${exception.code}, message: ${exception.message}`); 5292} 5293``` 5294 5295## setWindowBackgroundColor<sup>9+</sup> 5296 5297setWindowBackgroundColor(color: string | ColorMetrics): void 5298 5299Sets 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. 5300 5301**System capability**: SystemCapability.WindowManager.WindowManager.Core 5302 5303**Atomic service API**: This API can be used in atomic services since API version 11. 5304 5305**Parameters** 5306 5307| Name| Type| Mandatory| Description| 5308| ----- | ------ | -- | ----------------------------------------------------------------------- | 5309| color | string \| [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12)<sup>18+</sup> | Yes| Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **'#00FF00'** or **'#FF00FF00'**.<br>Since API version 18, this parameter supports the ColorMetrics type.| 5310 5311**Error codes** 5312 5313For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5314 5315| ID| Error Message| 5316| ------- | ------------------------------ | 5317| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5318| 1300002 | This window state is abnormal. | 5319 5320**Example** 5321 5322```ts 5323import { BusinessError } from '@kit.BasicServicesKit'; 5324import { ColorMetrics } from '@kit.ArkUI'; 5325 5326let storage: LocalStorage = new LocalStorage(); 5327storage.setOrCreate('storageSimpleProp', 121); 5328windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 5329 let errCode: number = err.code; 5330 if (errCode) { 5331 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5332 return; 5333 } 5334 console.info('Succeeded in loading the content.'); 5335 let color1: string = '#00ff33'; 5336 let color2: ColorMetrics = ColorMetrics.numeric(0xff112233); 5337 try { 5338 windowClass?.setWindowBackgroundColor(color1); 5339 windowClass?.setWindowBackgroundColor(color2); 5340 } catch (exception) { 5341 console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); 5342 }; 5343}); 5344``` 5345 5346## setWindowShadowEnabled<sup>20+</sup> 5347 5348setWindowShadowEnabled(enable: boolean): Promise<void> 5349 5350Sets whether the main window displays a shadow. This API uses a promise to return the result. By default, the main window displays a shadow unless you explicitly change it with this API. 5351 5352**System capability**: SystemCapability.Window.SessionManager 5353 5354**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 5355 5356**Required permission**: ohos.permission.SET_WINDOW_TRANSPARENT 5357 5358**Parameters** 5359 5360| Name| Type| Mandatory| Description| 5361| ----- | ------ | -- | ----------------------------------------------------------------------- | 5362| enable | boolean | Yes| Whether the main window displays a shadow. **true** if the main window displays a shadow, **false** otherwise.| 5363 5364**Return value** 5365 5366| Type| Description| 5367| ------------------- | ------------------------ | 5368| Promise<void> | Promise that returns no value.| 5369 5370**Error codes** 5371 5372For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5373 5374| ID| Error Message| 5375| ------- | ------------------------------ | 5376| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5377| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5378| 1300002 | This window state is abnormal. | 5379| 1300003 | This window manager service works abnormally. | 5380| 1300004 | Unauthorized operation. | 5381 5382**Example** 5383 5384```ts 5385// EntryAbility.ets 5386import { UIAbility } from '@kit.AbilityKit'; 5387import { BusinessError } from '@kit.BasicServicesKit'; 5388 5389export default class EntryAbility extends UIAbility { 5390 onWindowStageCreate(windowStage: window.WindowStage) { 5391 windowStage.loadContent("pages/page2", (err: BusinessError) => { 5392 let errCode: number = err.code; 5393 if (errCode) { 5394 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5395 return; 5396 } 5397 console.info('Succeeded in loading the content.'); 5398 // Obtain the main window. 5399 let windowClass: window.Window | undefined = undefined; 5400 windowStage.getMainWindow((err: BusinessError, data) => { 5401 let errCode: number = err.code; 5402 if (errCode) { 5403 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5404 return; 5405 } 5406 windowClass = data; 5407 let enable = true; 5408 let promise = windowClass.setWindowShadowEnabled(enable); 5409 promise.then(() => { 5410 console.info('Succeeded in setting window shadow.'); 5411 }).catch((err: BusinessError) => { 5412 console.error(`Failed to set the window shadow. Cause code: ${err.code}, message: ${err.message}`); 5413 }); 5414 }); 5415 }); 5416 } 5417} 5418``` 5419 5420## setWindowBrightness<sup>9+</sup> 5421 5422setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 5423 5424Sets the screen brightness for the main window. This API uses an asynchronous callback to return the result. 5425 5426- For non-2-in-1 devices, when the screen brightness setting for the window by this API takes effect, Control Panel cannot adjust the overall system screen brightness. It can do so only after the window-specific screen brightness is restored to the default value. 5427- For 2-in-1 devices, Control Panel has the same priority as this API. Event if this API is called to set the window-specific screen brightness, Control Panel can adjust the overall system screen brightness. 5428 5429**System capability**: SystemCapability.WindowManager.WindowManager.Core 5430 5431**Atomic service API**: This API can be used in atomic services since API version 11. 5432 5433**Parameters** 5434 5435| Name| Type| Mandatory| Description | 5436| ---------- | ------------------------- | -- |-------------------------------------------| 5437| brightness | number | Yes| Brightness to set. The value is a floating-point number in the range [0.0, 1.0] or is set to **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 5438| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5439 5440**Error codes** 5441 5442For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5443 5444| ID| Error Message| 5445| ------- | -------------------------------------------- | 5446| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5447| 1300002 | This window state is abnormal. | 5448| 1300003 | This window manager service works abnormally. | 5449 5450**Example** 5451 5452```ts 5453// EntryAbility.ets 5454import { UIAbility } from '@kit.AbilityKit'; 5455import { BusinessError } from '@kit.BasicServicesKit'; 5456 5457export default class EntryAbility extends UIAbility { 5458 // ... 5459 onWindowStageCreate(windowStage: window.WindowStage): void { 5460 console.info('onWindowStageCreate'); 5461 let windowClass: window.Window | undefined = undefined; 5462 windowStage.getMainWindow((err: BusinessError, data) => { 5463 const errCode: number = err.code; 5464 if (errCode) { 5465 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5466 return; 5467 } 5468 windowClass = data; 5469 let brightness: number = 1.0; 5470 try { 5471 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 5472 const errCode: number = err.code; 5473 if (errCode) { 5474 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5475 return; 5476 } 5477 console.info('Succeeded in setting the brightness.'); 5478 }); 5479 } catch (exception) { 5480 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5481 } 5482 }); 5483 } 5484} 5485``` 5486 5487## setWindowBrightness<sup>9+</sup> 5488 5489setWindowBrightness(brightness: number): Promise<void> 5490 5491Sets the screen brightness for the main window. This API uses a promise to return the result. 5492 5493- For non-2-in-1 devices, when the screen brightness setting for the window by this API takes effect, Control Panel cannot adjust the overall system screen brightness. It can do so only after the window-specific screen brightness is restored to the default value. 5494- For 2-in-1 devices, Control Panel has the same priority as this API. Event if this API is called to set the window-specific screen brightness, Control Panel can adjust the overall system screen brightness. 5495 5496**System capability**: SystemCapability.WindowManager.WindowManager.Core 5497 5498**Atomic service API**: This API can be used in atomic services since API version 11. 5499 5500**Parameters** 5501 5502| Name| Type| Mandatory| Description | 5503| ---------- | ------ | -- |----------------------------------------| 5504| brightness | number | Yes| Brightness to set. The value is a floating-point number in the range [0.0, 1.0] or is set to **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 5505 5506**Return value** 5507 5508| Type| Description| 5509| ------------------- | ------------------------ | 5510| Promise<void> | Promise that returns no value.| 5511 5512**Error codes** 5513 5514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5515 5516| ID| Error Message| 5517| ------- | -------------------------------------------- | 5518| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5519| 1300002 | This window state is abnormal. | 5520| 1300003 | This window manager service works abnormally. | 5521 5522**Example** 5523 5524```ts 5525// EntryAbility.ets 5526import { UIAbility } from '@kit.AbilityKit'; 5527import { BusinessError } from '@kit.BasicServicesKit'; 5528 5529export default class EntryAbility extends UIAbility { 5530 // ... 5531 onWindowStageCreate(windowStage: window.WindowStage): void { 5532 console.info('onWindowStageCreate'); 5533 let windowClass: window.Window | undefined = undefined; 5534 windowStage.getMainWindow((err: BusinessError, data) => { 5535 const errCode: number = err.code; 5536 if (errCode) { 5537 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5538 return; 5539 } 5540 windowClass = data; 5541 let brightness: number = 1.0; 5542 try { 5543 let promise = windowClass.setWindowBrightness(brightness); 5544 promise.then(() => { 5545 console.info('Succeeded in setting the brightness.'); 5546 }).catch((err: BusinessError) => { 5547 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5548 }); 5549 } catch (exception) { 5550 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5551 } 5552 }); 5553 } 5554} 5555``` 5556 5557## setWindowFocusable<sup>9+</sup> 5558 5559setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5560 5561Sets whether this window is focusable. This API uses an asynchronous callback to return the result. 5562 5563**Atomic service API**: This API can be used in atomic services since API version 12. 5564 5565**System capability**: SystemCapability.WindowManager.WindowManager.Core 5566 5567**Parameters** 5568 5569| Name| Type| Mandatory| Description| 5570| ----------- | ------------------------- | -- | ------------------------------------------------------- | 5571| isFocusable | boolean | Yes| Whether the window is focusable. **true** if focusable, **false** otherwise.| 5572| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5573 5574**Error codes** 5575 5576For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5577 5578| ID| Error Message| 5579| ------- | -------------------------------------------- | 5580| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5581| 1300002 | This window state is abnormal. | 5582| 1300003 | This window manager service works abnormally. | 5583 5584**Example** 5585 5586```ts 5587import { BusinessError } from '@kit.BasicServicesKit'; 5588 5589let isFocusable: boolean = true; 5590try { 5591 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 5592 const errCode: number = err.code; 5593 if (errCode) { 5594 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5595 return; 5596 } 5597 console.info('Succeeded in setting the window to be focusable.'); 5598 }); 5599} catch (exception) { 5600 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5601} 5602``` 5603 5604## setWindowFocusable<sup>9+</sup> 5605 5606setWindowFocusable(isFocusable: boolean): Promise<void> 5607 5608Sets whether this window is focusable. This API uses a promise to return the result. 5609 5610**Atomic service API**: This API can be used in atomic services since API version 12. 5611 5612**System capability**: SystemCapability.WindowManager.WindowManager.Core 5613 5614**Parameters** 5615 5616| Name| Type| Mandatory| Description| 5617| ----------- | ------- | -- | -------------------------------------------------------- | 5618| isFocusable | boolean | Yes| Whether the window is focusable. **true** if focusable, **false** otherwise. | 5619 5620**Return value** 5621 5622| Type| Description| 5623| ------------------- | ------------------------ | 5624| Promise<void> | Promise that returns no value.| 5625 5626**Error codes** 5627 5628For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5629 5630| ID| Error Message| 5631| ------- | -------------------------------------------- | 5632| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5633| 1300002 | This window state is abnormal. | 5634| 1300003 | This window manager service works abnormally. | 5635 5636**Example** 5637 5638```ts 5639import { BusinessError } from '@kit.BasicServicesKit'; 5640 5641let isFocusable: boolean = true; 5642try { 5643 let promise = windowClass.setWindowFocusable(isFocusable); 5644 promise.then(() => { 5645 console.info('Succeeded in setting the window to be focusable.'); 5646 }).catch((err: BusinessError) => { 5647 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5648 }); 5649} catch (exception) { 5650 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5651} 5652``` 5653 5654## setWindowKeepScreenOn<sup>9+</sup> 5655 5656setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5657 5658Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 5659 5660Set **isKeepScreenOn** to **true** only in necessary scenarios (such as navigation, video playback, drawing, and gaming scenarios). After exiting these scenarios, set the parameter to **false**. Do not use this API in other scenarios (such as no screen interaction or audio playback). When the system detects that the API is used in a non-standard manner, automatic screen-off may be invoked. 5661 5662**System capability**: SystemCapability.WindowManager.WindowManager.Core 5663 5664**Atomic service API**: This API can be used in atomic services since API version 11. 5665 5666**Parameters** 5667 5668| Name| Type| Mandatory| Description| 5669| -------------- | ------------------------- | -- | ---------------------------------------------------- | 5670| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. **true** to keep the screen always on, **false** otherwise. | 5671| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5672 5673**Error codes** 5674 5675For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5676 5677| ID| Error Message| 5678| ------- | -------------------------------------------- | 5679| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5680| 1300002 | This window state is abnormal. | 5681| 1300003 | This window manager service works abnormally. | 5682 5683**Example** 5684 5685```ts 5686import { BusinessError } from '@kit.BasicServicesKit'; 5687 5688let isKeepScreenOn: boolean = true; 5689try { 5690 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 5691 const errCode: number = err.code; 5692 if (errCode) { 5693 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5694 return; 5695 } 5696 console.info('Succeeded in setting the screen to be always on.'); 5697 }); 5698} catch (exception) { 5699 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5700} 5701``` 5702 5703## setWindowKeepScreenOn<sup>9+</sup> 5704 5705setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5706 5707Sets whether to keep the screen always on. This API uses a promise to return the result. 5708 5709Set **isKeepScreenOn** to **true** only in necessary scenarios (such as navigation, video playback, drawing, and gaming scenarios). After exiting these scenarios, set the parameter to **false**. Do not use this API in other scenarios (such as no screen interaction or audio playback). When the system detects that the API is used in a non-standard manner, automatic screen-off may be invoked. 5710 5711**System capability**: SystemCapability.WindowManager.WindowManager.Core 5712 5713**Atomic service API**: This API can be used in atomic services since API version 11. 5714 5715**Parameters** 5716 5717| Name| Type| Mandatory| Description| 5718| -------------- | ------- | -- | --------------------------------------------------- | 5719| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. **true** to keep the screen always on, **false** otherwise.| 5720 5721**Return value** 5722 5723| Type| Description| 5724| ------------------- | ------------------------ | 5725| Promise<void> | Promise that returns no value.| 5726 5727**Error codes** 5728 5729For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5730 5731| ID| Error Message| 5732| ------- | -------------------------------------------- | 5733| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5734| 1300002 | This window state is abnormal. | 5735| 1300003 | This window manager service works abnormally. | 5736 5737**Example** 5738 5739```ts 5740import { BusinessError } from '@kit.BasicServicesKit'; 5741 5742let isKeepScreenOn: boolean = true; 5743try { 5744 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 5745 promise.then(() => { 5746 console.info('Succeeded in setting the screen to be always on.'); 5747 }).catch((err: BusinessError) => { 5748 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5749 }); 5750} catch (exception) { 5751 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5752} 5753``` 5754 5755## setWindowPrivacyMode<sup>9+</sup> 5756 5757setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 5758 5759Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 5760 5761A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5762 5763**System capability**: SystemCapability.WindowManager.WindowManager.Core 5764 5765**Atomic service API**: This API can be used in atomic services since API version 12. 5766 5767**Required permissions**: ohos.permission.PRIVACY_WINDOW 5768 5769**Parameters** 5770 5771| Name| Type| Mandatory| Description| 5772| ------------- | ------------------------- | -- | ------------------------------------------------------ | 5773| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise. | 5774| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5775 5776**Error codes** 5777 5778For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5779 5780| ID| Error Message| 5781| ------- | ------------------------------ | 5782| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5783| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5784| 1300002 | This window state is abnormal. | 5785 5786**Example** 5787 5788```ts 5789import { BusinessError } from '@kit.BasicServicesKit'; 5790 5791let isPrivacyMode: boolean = true; 5792try { 5793 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 5794 const errCode: number = err.code; 5795 if (errCode) { 5796 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5797 return; 5798 } 5799 console.info('Succeeded in setting the window to privacy mode.'); 5800 }); 5801} catch (exception) { 5802 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5803} 5804``` 5805 5806## setWindowPrivacyMode<sup>9+</sup> 5807 5808setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 5809 5810Sets whether this window is in privacy mode. This API uses a promise to return the result. 5811 5812A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 5813 5814**System capability**: SystemCapability.WindowManager.WindowManager.Core 5815 5816**Atomic service API**: This API can be used in atomic services since API version 12. 5817 5818**Required permissions**: ohos.permission.PRIVACY_WINDOW 5819 5820**Parameters** 5821 5822| Name| Type| Mandatory| Description| 5823| ------------- | ------- | -- | ----------------------------------------------------- | 5824| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise.| 5825 5826**Return value** 5827 5828| Type| Description| 5829| ------------------- | ------------------------ | 5830| Promise<void> | Promise that returns no value.| 5831 5832**Error codes** 5833 5834For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5835 5836| ID| Error Message| 5837| ------- | ------------------------------ | 5838| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5839| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5840| 1300002 | This window state is abnormal. | 5841 5842**Example** 5843 5844```ts 5845import { BusinessError } from '@kit.BasicServicesKit'; 5846 5847let isPrivacyMode: boolean = true; 5848try { 5849 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 5850 promise.then(() => { 5851 console.info('Succeeded in setting the window to privacy mode.'); 5852 }).catch((err: BusinessError) => { 5853 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5854 }); 5855} catch (exception) { 5856 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5857} 5858``` 5859 5860## setWindowTouchable<sup>9+</sup> 5861 5862setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 5863 5864Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 5865 5866**Atomic service API**: This API can be used in atomic services since API version 12. 5867 5868**System capability**: SystemCapability.WindowManager.WindowManager.Core 5869 5870**Parameters** 5871 5872| Name| Type| Mandatory| Description| 5873| ----------- | ------------------------- | -- | ----------------------------------------------- | 5874| isTouchable | boolean | Yes| Whether the window is touchable. **true** if touchable, **false** otherwise.| 5875| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 5876 5877**Error codes** 5878 5879For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5880 5881| ID| Error Message| 5882| ------- | -------------------------------------------- | 5883| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5884| 1300002 | This window state is abnormal. | 5885| 1300003 | This window manager service works abnormally. | 5886 5887**Example** 5888 5889```ts 5890import { BusinessError } from '@kit.BasicServicesKit'; 5891 5892let isTouchable = true; 5893try { 5894 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 5895 const errCode: number = err.code; 5896 if (errCode) { 5897 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5898 return; 5899 } 5900 console.info('Succeeded in setting the window to be touchable.'); 5901 }); 5902} catch (exception) { 5903 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5904} 5905``` 5906 5907## setWindowTouchable<sup>9+</sup> 5908 5909setWindowTouchable(isTouchable: boolean): Promise<void> 5910 5911Sets whether this window is touchable. This API uses a promise to return the result. 5912 5913**Atomic service API**: This API can be used in atomic services since API version 12. 5914 5915**System capability**: SystemCapability.WindowManager.WindowManager.Core 5916 5917**Parameters** 5918 5919| Name| Type| Mandatory| Description| 5920| ----------- | ------- | -- | ----------------------------------------------- | 5921| isTouchable | boolean | Yes| Whether the window is touchable. **true** if touchable, **false** otherwise.| 5922 5923**Return value** 5924 5925| Type| Description| 5926| ------------------- | ------------------------- | 5927| Promise<void> | Promise that returns no value.| 5928 5929**Error codes** 5930 5931For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 5932 5933| ID| Error Message| 5934| ------- | -------------------------------------------- | 5935| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5936| 1300002 | This window state is abnormal. | 5937| 1300003 | This window manager service works abnormally. | 5938 5939**Example** 5940 5941```ts 5942import { BusinessError } from '@kit.BasicServicesKit'; 5943 5944let isTouchable: boolean = true; 5945try { 5946 let promise = windowClass.setWindowTouchable(isTouchable); 5947 promise.then(() => { 5948 console.info('Succeeded in setting the window to be touchable.'); 5949 }).catch((err: BusinessError) => { 5950 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5951 }); 5952} catch (exception) { 5953 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5954} 5955``` 5956 5957## snapshot<sup>9+</sup> 5958 5959snapshot(callback: AsyncCallback<image.PixelMap>): void 5960 5961Captures this window. This API uses an asynchronous callback to return the result. If privacy mode is enabled for the current window (using [setWindowPrivacyMode](#setwindowprivacymode9)), taking a screenshot will result in a blank screen. 5962 5963**Atomic service API**: This API can be used in atomic services since API version 12. 5964 5965**System capability**: SystemCapability.WindowManager.WindowManager.Core 5966 5967**Parameters** 5968 5969| Name | Type | Mandatory| Description | 5970| ----------- | ------------------------- | ---- | -------------------- | 5971| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Yes | Callback used to return the result. | 5972 5973**Error codes** 5974 5975For details about the error codes, see [Window Error Codes](errorcode-window.md). 5976 5977| ID| Error Message| 5978| ------- | ------------------------------ | 5979| 1300002 | This window state is abnormal. | 5980 5981**Example** 5982 5983```ts 5984import { BusinessError } from '@kit.BasicServicesKit'; 5985import { image } from '@kit.ImageKit'; 5986 5987windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 5988 const errCode: number = err.code; 5989 if (errCode) { 5990 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 5991 return; 5992 } 5993 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 5994 pixelMap.release(); // Release the memory in time after the PixelMap is used. 5995}); 5996``` 5997 5998## snapshot<sup>9+</sup> 5999 6000snapshot(): Promise<image.PixelMap> 6001 6002Captures this window. If privacy mode is enabled for the current window (using [setWindowPrivacyMode](#setwindowprivacymode9)), taking a screenshot will result in a blank screen. 6003 6004**Atomic service API**: This API can be used in atomic services since API version 12. 6005 6006**System capability**: SystemCapability.WindowManager.WindowManager.Core 6007 6008**Return value** 6009 6010| Type | Description | 6011| ------------------- | ------------------------- | 6012| Promise<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Promise used to return the window screenshot.| 6013 6014**Error codes** 6015 6016For details about the error codes, see [Window Error Codes](errorcode-window.md). 6017 6018| ID| Error Message| 6019| ------- | ------------------------------ | 6020| 1300002 | This window state is abnormal. | 6021 6022**Example** 6023 6024```ts 6025import { BusinessError } from '@kit.BasicServicesKit'; 6026import { image } from '@kit.ImageKit'; 6027 6028let promise = windowClass.snapshot(); 6029promise.then((pixelMap: image.PixelMap) => { 6030 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6031 pixelMap.release(); // Release the memory in time after the PixelMap is used. 6032}).catch((err: BusinessError) => { 6033 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6034}); 6035``` 6036 6037## snapshotSync<sup>20+</sup> 6038 6039snapshotSync(): image.PixelMap 6040 6041Captures this window. This API returns the result synchronously. If privacy mode is enabled for the current window (using [setWindowPrivacyMode](#setwindowprivacymode9)), taking a screenshot will result in a blank screen. 6042 6043In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 6044 6045**System capability**: SystemCapability.Window.SessionManager 6046 6047**Return value** 6048 6049| Type | Description | 6050| ------------------- | ------------------------- | 6051| [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | Window screenshot.| 6052 6053**Error codes** 6054 6055For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6056 6057| ID| Error Message| 6058| ------- | ------------------------------ | 6059| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6060| 1300002 | This window state is abnormal. | 6061| 1300018 | Timeout. | 6062 6063**Example** 6064 6065```ts 6066import { BusinessError } from '@kit.BasicServicesKit'; 6067import { image } from '@kit.ImageKit'; 6068 6069try { 6070 let pixelMap = windowClass.snapshotSync(); 6071 console.info(`Succeeded in snapshotting window`); 6072 pixelMap.release(); // Release the memory in time after the PixelMap is used. 6073} catch (exception) { 6074 console.error(`Failed to snapshot window. Cause code: ${exception.code}, message: ${exception.message}`); 6075} 6076``` 6077 6078## snapshotIgnorePrivacy<sup>18+</sup> 6079 6080snapshotIgnorePrivacy(): Promise<image.PixelMap> 6081 6082Captures this window. This API can be called to obtain the screenshot of the current window even if privacy mode is enabled for the current window (using [setWindowPrivacyMode](#setwindowprivacymode9)). 6083 6084**Atomic service API**: This API can be used in atomic services since API version 18. 6085 6086**System capability**: SystemCapability.Window.SessionManager 6087 6088**Return value** 6089 6090| Type | Description | 6091| ------------------- | ------------------------- | 6092| Promise<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Promise used to return the window screenshot.| 6093 6094**Error codes** 6095 6096For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6097 6098| ID| Error Message| 6099| ------- | ------------------------------ | 6100| 801 | Capability not supported. Function snapshotIgnorePrivacy can not work correctly due to limited device capabilities. | 6101| 1300002 | This window state is abnormal. | 6102 6103**Example** 6104 6105```ts 6106import { BusinessError } from '@kit.BasicServicesKit'; 6107import { image } from '@kit.ImageKit'; 6108 6109let promise = windowClass.snapshotIgnorePrivacy(); 6110promise.then((pixelMap: image.PixelMap) => { 6111 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6112 pixelMap.release(); // Release the memory in time after the PixelMap is used. 6113}).catch((err: BusinessError) => { 6114 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6115}); 6116``` 6117 6118## setAspectRatio<sup>10+</sup> 6119 6120setAspectRatio(ratio: number): Promise<void> 6121 6122Sets the aspect ratio of the window content layout. This API uses a promise to return the result. 6123 6124When the window size is set by using other APIs such as [resize](#resize9) and [resizeAsync](#resizeasync12), the window size is not restricted by **ratio**. 6125 6126This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). The aspect ratio is saved persistently, which means that the setting is valid even after the application is closed or the device is restarted. 6127 6128**Atomic service API**: This API can be used in atomic services since API version 12. 6129 6130**System capability**: SystemCapability.WindowManager.WindowManager.Core 6131 6132**Parameters** 6133 6134| Name | Type | Mandatory| Description | 6135| ------------------ | ------- | ---- |-------------------------------------------| 6136| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating-point number and is restricted by the maximum and minimum sizes of the window. The minimum ratio is the value of minimum width divided by the maximum height, and the maximum ratio is the maximum width divided by the minimum height. The maximum and minimum sizes of the window are determined by the intersection of the setting of [WindowLimits](arkts-apis-window-i.md#windowlimits11) and the system limit. The system limit takes precedence over [WindowLimits](arkts-apis-window-i.md#windowlimits11). The valid range of **ratio** varies with [WindowLimits](arkts-apis-window-i.md#windowlimits11). If [WindowLimits](arkts-apis-window-i.md#windowlimits11) is set prior to **ratio**, any conflict will result in an error code when setting **ratio**. Conversely, if **ratio** is set before and then conflicts arise with the subsequently configured [WindowLimits](arkts-apis-window-i.md#windowlimits11), the window's aspect ratio may not adhere to the initially configured value of **ratio**.| 6137 6138**Return value** 6139 6140| Type | Description | 6141| ------------------- | ------------------------- | 6142| Promise<void> | Promise that returns no value.| 6143 6144**Error codes** 6145 6146For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6147 6148| ID| Error Message| 6149| ------- | -------------------------------------------- | 6150| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6151| 1300002 | This window state is abnormal. | 6152| 1300004 | Unauthorized operation. | 6153 6154**Example** 6155<!--code_no_check--> 6156```ts 6157// EntryAbility.ets 6158import { UIAbility } from '@kit.AbilityKit'; 6159import { BusinessError } from '@kit.BasicServicesKit'; 6160 6161export default class EntryAbility extends UIAbility { 6162 6163 // ... 6164 onWindowStageCreate(windowStage: window.WindowStage) { 6165 console.info('onWindowStageCreate'); 6166 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6167 if (!windowClass) { 6168 console.info('windowClass is null'); 6169 } 6170 try { 6171 let ratio = 1.0; 6172 let promise = windowClass.setAspectRatio(ratio); 6173 promise.then(() => { 6174 console.info('Succeeded in setting aspect ratio of window.'); 6175 }).catch((err: BusinessError) => { 6176 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6177 }); 6178 } catch (exception) { 6179 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6180 } 6181 } 6182} 6183``` 6184 6185## setAspectRatio<sup>10+</sup> 6186 6187setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 6188 6189Sets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 6190 6191When the window size is set by using other APIs such as [resize](#resize9) and [resizeAsync](#resizeasync12), the window size is not restricted by **ratio**. 6192 6193This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). The aspect ratio is saved persistently, which means that the setting is valid even after the application is closed or the device is restarted. 6194 6195**Atomic service API**: This API can be used in atomic services since API version 12. 6196 6197**System capability**: SystemCapability.WindowManager.WindowManager.Core 6198 6199**Parameters** 6200 6201| Name | Type | Mandatory| Description | 6202| ------------------ | ------- | ---- |--------------------------------------------| 6203| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating-point number and is restricted by the maximum and minimum sizes of the window. The minimum ratio is the value of minimum width divided by the maximum height, and the maximum ratio is the maximum width divided by the minimum height. The maximum and minimum sizes of the window are determined by the intersection of the setting of [WindowLimits](arkts-apis-window-i.md#windowlimits11) and the system limit. The system limit takes precedence over [WindowLimits](arkts-apis-window-i.md#windowlimits11). The valid range of **ratio** varies with [WindowLimits](arkts-apis-window-i.md#windowlimits11). If [WindowLimits](arkts-apis-window-i.md#windowlimits11) is set prior to **ratio**, any conflict will result in an error code when setting **ratio**. Conversely, if **ratio** is set before and then conflicts arise with the subsequently configured [WindowLimits](arkts-apis-window-i.md#windowlimits11), the window's aspect ratio may not adhere to the initially configured value of **ratio**.| 6204| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6205 6206**Error codes** 6207 6208For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6209 6210| ID| Error Message| 6211| ------- | -------------------------------------------- | 6212| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6213| 1300002 | This window state is abnormal. | 6214| 1300004 | Unauthorized operation. | 6215 6216**Example** 6217<!--code_no_check--> 6218```ts 6219// EntryAbility.ets 6220import { UIAbility } from '@kit.AbilityKit'; 6221import { BusinessError } from '@kit.BasicServicesKit'; 6222 6223export default class EntryAbility extends UIAbility { 6224 6225 // ... 6226 onWindowStageCreate(windowStage: window.WindowStage) { 6227 console.info('onWindowStageCreate'); 6228 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6229 if (!windowClass) { 6230 console.info('Failed to load the content. Cause: windowClass is null'); 6231 } 6232 try { 6233 let ratio = 1.0; 6234 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 6235 const errCode: number = err.code; 6236 if (errCode) { 6237 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6238 return; 6239 } 6240 console.info('Succeeded in setting the aspect ratio of window.'); 6241 }); 6242 } catch (exception) { 6243 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6244 } 6245 } 6246} 6247 6248``` 6249 6250## resetAspectRatio<sup>10+</sup> 6251 6252resetAspectRatio(): Promise<void> 6253 6254Resets the aspect ratio of the window content layout. This API uses a promise to return the result. 6255 6256This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). After this API is called, the persistently stored aspect ratio is cleared. 6257 6258**Atomic service API**: This API can be used in atomic services since API version 12. 6259 6260**System capability**: SystemCapability.WindowManager.WindowManager.Core 6261 6262**Return value** 6263 6264| Type | Description | 6265| ------------------- | ------------------------- | 6266| Promise<void> | Promise that returns no value.| 6267 6268**Error codes** 6269 6270For details about the error codes, see [Window Error Codes](errorcode-window.md). 6271 6272| ID| Error Message| 6273| ------- | -------------------------------------------- | 6274| 1300002 | This window state is abnormal. | 6275| 1300004 | Unauthorized operation. | 6276 6277**Example** 6278<!--code_no_check--> 6279```ts 6280// EntryAbility.ets 6281import { UIAbility } from '@kit.AbilityKit'; 6282import { BusinessError } from '@kit.BasicServicesKit'; 6283 6284export default class EntryAbility extends UIAbility { 6285 6286 // ... 6287 onWindowStageCreate(windowStage: window.WindowStage) { 6288 console.info('onWindowStageCreate'); 6289 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6290 if (!windowClass) { 6291 console.info('Failed to load the content. Cause: windowClass is null'); 6292 } 6293 try { 6294 let promise = windowClass.resetAspectRatio(); 6295 promise.then(() => { 6296 console.info('Succeeded in resetting aspect ratio of window.'); 6297 }).catch((err: BusinessError) => { 6298 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6299 }); 6300 } catch (exception) { 6301 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6302 } 6303 } 6304} 6305``` 6306 6307## resetAspectRatio<sup>10+</sup> 6308 6309resetAspectRatio(callback: AsyncCallback<void>): void 6310 6311Resets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 6312 6313This API can be called only for the main window and the setting takes effect only in floating window mode (**window.WindowStatusType.FLOATING** mode). After this API is called, the persistently stored aspect ratio is cleared. 6314 6315**Atomic service API**: This API can be used in atomic services since API version 12. 6316 6317**System capability**: SystemCapability.WindowManager.WindowManager.Core 6318 6319**Parameters** 6320 6321| Name | Type | Mandatory| Description | 6322| ------------------ | ------- | ---- | ------------------------------------------------------------ | 6323| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6324 6325**Error codes** 6326 6327For details about the error codes, see [Window Error Codes](errorcode-window.md). 6328 6329| ID| Error Message| 6330| ------- | -------------------------------------------- | 6331| 1300002 | This window state is abnormal. | 6332| 1300004 | Unauthorized operation. | 6333 6334**Example** 6335<!--code_no_check--> 6336```ts 6337// EntryAbility.ets 6338import { UIAbility } from '@kit.AbilityKit'; 6339import { BusinessError } from '@kit.BasicServicesKit'; 6340 6341export default class EntryAbility extends UIAbility { 6342 6343 // ... 6344 onWindowStageCreate(windowStage: window.WindowStage) { 6345 console.info('onWindowStageCreate'); 6346 let windowClass: window.Window = windowStage.getMainWindowSync(); // Obtain the main window of the application. 6347 if (!windowClass) { 6348 console.info('Failed to load the content. Cause: windowClass is null'); 6349 } 6350 try { 6351 windowClass.resetAspectRatio((err: BusinessError) => { 6352 const errCode: number = err.code; 6353 if (errCode) { 6354 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6355 return; 6356 } 6357 console.info('Succeeded in resetting aspect ratio of window.'); 6358 }); 6359 } catch (exception) { 6360 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6361 } 6362 } 6363} 6364``` 6365 6366## minimize<sup>11+</sup> 6367 6368minimize(callback: AsyncCallback<void>): void 6369 6370The behavior of this API varies based on the caller: 6371 6372- Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. For 2-in-1 devices, it can be restored by calling [restore()](#restore14). 6373 6374- Hides the child window or floating window if the caller is a child window. The child window or floating window cannot be restored in the dock bar. It can be made visible again by calling [showWindow()](#showwindow9). 6375 6376This API uses an asynchronous callback to return the result. 6377 6378**Atomic service API**: This API can be used in atomic services since API version 12. 6379 6380**System capability**: SystemCapability.Window.SessionManager 6381 6382**Parameters** 6383 6384| Name | Type | Mandatory| Description | 6385| -------- | ------------------------- | ---- | ---------- | 6386| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6387 6388**Error codes** 6389 6390For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6391 6392| ID| Error Message| 6393| ------- | ------------------------------ | 6394| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6395| 1300002 | This window state is abnormal. | 6396| 1300003 | This window manager service works abnormally. | 6397 6398**Example** 6399 6400```ts 6401import { BusinessError } from '@kit.BasicServicesKit'; 6402 6403windowClass.minimize((err: BusinessError) => { 6404 const errCode: number = err.code; 6405 if (errCode) { 6406 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6407 return; 6408 } 6409 console.info('Succeeded in minimizing the window.'); 6410}); 6411``` 6412 6413## minimize<sup>11+</sup> 6414 6415minimize(): Promise<void> 6416 6417The behavior of this API varies based on the caller: 6418 6419- Minimizes the main window if the caller is the main window. The main window can be restored in the dock bar. For 2-in-1 devices, it can be restored by calling [restore()](#restore14). 6420 6421- Hides the child window or floating window if the caller is a child window. The child window or floating window cannot be restored in the dock bar. It can be made visible again by calling [showWindow()](#showwindow9). 6422 6423This API uses a promise to return the result. 6424 6425**Atomic service API**: This API can be used in atomic services since API version 12. 6426 6427**System capability**: SystemCapability.Window.SessionManager 6428 6429**Return value** 6430 6431| Type | Description | 6432| ------------------- | ------------------------- | 6433| Promise<void> | Promise that returns no value.| 6434 6435**Error codes** 6436 6437For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6438 6439| ID| Error Message| 6440| ------- | ------------------------------ | 6441| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6442| 1300002 | This window state is abnormal. | 6443| 1300003 | This window manager service works abnormally. | 6444 6445**Example** 6446 6447```ts 6448import { BusinessError } from '@kit.BasicServicesKit'; 6449 6450let promise = windowClass.minimize(); 6451promise.then(() => { 6452 console.info('Succeeded in minimizing the window.'); 6453}).catch((err: BusinessError) => { 6454 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6455}); 6456``` 6457 6458## maximize<sup>12+</sup> 6459maximize(presentation?: MaximizePresentation): Promise<void> 6460 6461Maximizes the main window. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. The main window can use this API to maximize. For child windows, you need to set **maximizeSupported** to **true** when creating the window and then call this API to maximize. This API uses a promise to return the result. 6462 6463**Atomic service API**: This API can be used in atomic services since API version 12. 6464 6465**System capability**: SystemCapability.Window.SessionManager 6466 6467**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 6468 6469**Parameters** 6470 6471| Name| Type | Mandatory| Description| 6472| ----- | ---------------------------- | -- | --------------------------------- | 6473| presentation | [MaximizePresentation](arkts-apis-window-e.md#maximizepresentation12) | No| Layout of the main window or child window when maximized. The default value is **window.MaximizePresentation.ENTER_IMMERSIVE**, indicating that the window enters the full-screen mode when maximized.| 6474 6475**Return value** 6476 6477| Type | Description | 6478| ------------------- | ------------------------- | 6479| Promise<void> | Promise that returns no value.| 6480 6481**Error codes** 6482 6483For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6484 6485| ID| Error Message| 6486| ------- | ------------------------------ | 6487| 801 | Capability not supported. Function maximize can not work correctly due to limited device capabilities. | 6488| 1300002 | This window state is abnormal. | 6489| 1300003 | This window manager service works abnormally. | 6490| 1300004 | Unauthorized operation. | 6491 6492**Example** 6493 6494```ts 6495// EntryAbility.ets 6496import { UIAbility } from '@kit.AbilityKit'; 6497import { BusinessError } from '@kit.BasicServicesKit'; 6498export default class EntryAbility extends UIAbility { 6499 // ... 6500 6501 onWindowStageCreate(windowStage: window.WindowStage) { 6502 console.info('onWindowStageCreate'); 6503 let windowClass: window.Window | undefined = undefined; 6504 windowStage.getMainWindow((err: BusinessError, data) => { 6505 const errCode: number = err.code; 6506 if (errCode) { 6507 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6508 return; 6509 } 6510 windowClass = data; 6511 let promise = windowClass.maximize(); 6512 // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 6513 promise.then(() => { 6514 console.info('Succeeded in maximizing the window.'); 6515 }).catch((err: BusinessError) => { 6516 console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`); 6517 }); 6518 }); 6519 } 6520}; 6521``` 6522 6523## setResizeByDragEnabled<sup>14+</sup> 6524setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 6525 6526Sets whether to enable the main window or child window with decorations to resize itself by dragging. This API uses an asynchronous callback to return the result. 6527 6528**Atomic service API**: This API can be used in atomic services since API version 14. 6529 6530**System capability**: SystemCapability.Window.SessionManager 6531 6532**Parameters** 6533 6534| Name| Type | Mandatory| Description| 6535| ----- | ---------------------------- | -- | --------------------------------- | 6536| enable | boolean | Yes| Whether to enable the window to resize itself by dragging. **true** to enable, **false** otherwise.| 6537| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 6538 6539**Error codes** 6540 6541For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6542 6543| ID| Error Message| 6544| ------- | ------------------------------ | 6545| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6546| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6547| 1300002 | This window state is abnormal. | 6548| 1300003 | This window manager service works abnormally. | 6549 6550**Example** 6551 6552```ts 6553try { 6554 let enabled = false; 6555 windowClass.setResizeByDragEnabled(enabled, (err) => { 6556 if (err.code) { 6557 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6558 return; 6559 } 6560 console.info(`Succeeded in setting the function of disabling the resize by drag window.`); 6561 }); 6562} catch (exception) { 6563 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${exception.code}, message: ${exception.message}`); 6564} 6565``` 6566 6567## setResizeByDragEnabled<sup>14+</sup> 6568setResizeByDragEnabled(enable: boolean): Promise<void> 6569 6570Sets whether to enable the main window or child window with decorations to resize itself by dragging. This API uses a promise to return the result. 6571 6572**Atomic service API**: This API can be used in atomic services since API version 14. 6573 6574**System capability**: SystemCapability.Window.SessionManager 6575 6576**Parameters** 6577 6578| Name| Type | Mandatory| Description| 6579| ----- | ---------------------------- | -- | --------------------------------- | 6580| enable | boolean | Yes| Whether to enable the window to resize itself by dragging. **true** to enable, **false** otherwise.| 6581 6582**Return value** 6583 6584| Type| Description| 6585| ------------------- | ------------------------ | 6586| Promise<void> | Promise that returns no value.| 6587 6588**Error codes** 6589 6590For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6591 6592| ID| Error Message| 6593| ------- | ------------------------------ | 6594| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6595| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6596| 1300002 | This window state is abnormal. | 6597| 1300003 | This window manager service works abnormally. | 6598 6599**Example** 6600 6601```ts 6602import { BusinessError } from '@kit.BasicServicesKit'; 6603 6604try { 6605 let enabled = false; 6606 let promise = windowClass.setResizeByDragEnabled(enabled); 6607 promise.then(() => { 6608 console.info(`Succeeded in setting the function of disabling the resize by drag window.`); 6609 }).catch((err: BusinessError) => { 6610 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6611 }); 6612} catch (exception) { 6613 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${exception.code}, message: ${exception.message}`); 6614} 6615``` 6616 6617## recover<sup>11+</sup> 6618 6619recover(): Promise<void> 6620 6621Restores the main window from the full-screen, maximized, or split-screen mode to a floating window (**window.WindowStatusType.FLOATING** mode), 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 works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. This API uses a promise to return the result. 6622 6623**Atomic service API**: This API can be used in atomic services since API version 12. 6624 6625**System capability**: SystemCapability.Window.SessionManager 6626 6627**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 6628 6629**Return value** 6630 6631| Type | Description | 6632| ------------------- | ------------------------- | 6633| Promise<void> | Promise that returns no value.| 6634 6635**Error codes** 6636 6637For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6638 6639| ID| Error Message| 6640| ------- | ------------------------------ | 6641| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6642| 1300001 | Repeated operation. | 6643| 1300002 | This window state is abnormal. | 6644 6645**Example** 6646 6647```ts 6648// EntryAbility.ets 6649import { UIAbility } from '@kit.AbilityKit'; 6650import { BusinessError } from '@kit.BasicServicesKit'; 6651 6652export default class EntryAbility extends UIAbility { 6653 // ... 6654 onWindowStageCreate(windowStage: window.WindowStage): void { 6655 console.info('onWindowStageCreate'); 6656 try { 6657 let windowClass = windowStage.getMainWindowSync(); 6658 if (!windowClass) { 6659 console.error('Failed to get main window.'); 6660 return; 6661 } 6662 let promise = windowClass.recover(); 6663 promise.then(() => { 6664 console.info('Succeeded in recovering the window.'); 6665 }).catch((err: BusinessError) => { 6666 console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`); 6667 }); 6668 } catch (exception) { 6669 console.error(`Failed to recover the window. Cause code: ${exception.code}, message: ${exception.message}`); 6670 } 6671 } 6672} 6673``` 6674 6675## restore<sup>14+</sup> 6676 6677restore(): Promise<void> 6678 6679Restores the main window from minimization to the foreground, returning it to its size and position before it is minimized. This API takes effect only when the main window is minimized and the UIAbility is in the onForeground state. This API uses a promise to return the result. 6680 6681**Atomic service API**: This API can be used in atomic services since API version 14. 6682 6683**System capability**: SystemCapability.Window.SessionManager 6684 6685**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 6686 6687**Return value** 6688 6689| Type | Description | 6690| ------------------- | ------------------------- | 6691| Promise<void> | Promise that returns no value.| 6692 6693**Error codes** 6694 6695For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6696 6697| **ID**| **Error Message** | 6698| ------------ | ------------------------------------------------------------ | 6699| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6700| 1300002 | This window state is abnormal. | 6701| 1300003 | This window manager service works abnormally. | 6702| 1300004 | Unauthorized operation. | 6703 6704**Example** 6705 6706```ts 6707// EntryAbility.ets 6708import { UIAbility } from '@kit.AbilityKit'; 6709import { BusinessError } from '@kit.BasicServicesKit'; 6710 6711export default class EntryAbility extends UIAbility { 6712 onWindowStageCreate(windowStage: window.WindowStage): void { 6713 try { 6714 let windowClass = windowStage.getMainWindowSync(); 6715 // Call minimize() to minimize the main window. 6716 windowClass.minimize(); 6717 // Set the delay function to restore the main window after a delay of 5 seconds. 6718 setTimeout(()=>{ 6719 // Call restore() to restore the main window. 6720 let promise = windowClass.restore(); 6721 promise.then(() => { 6722 console.info('Succeeded in restoring the window.'); 6723 }).catch((err: BusinessError) => { 6724 console.error(`Failed to restore the window. Cause code: ${err.code}, message: ${err.message}`); 6725 }); 6726 }, 5000); 6727 } catch (exception) { 6728 console.error(`Failed to restore the window. Cause code: ${exception.code}, message: ${exception.message}`); 6729 } 6730 } 6731} 6732``` 6733 6734## getWindowLimits<sup>11+</sup> 6735 6736getWindowLimits(): WindowLimits 6737 6738Obtains the size limits of this application window. 6739 6740**Atomic service API**: This API can be used in atomic services since API version 12. 6741 6742**System capability**: SystemCapability.Window.SessionManager 6743 6744**Return value** 6745 6746| Type | Description | 6747| ----------------------------- | ------------------ | 6748| [WindowLimits](arkts-apis-window-i.md#windowlimits11) | Window size limits.| 6749 6750**Error codes** 6751 6752For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6753 6754| ID| Error Message | 6755| :------- | :----------------------------- | 6756| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6757| 1300002 | This window state is abnormal. | 6758 6759**Example** 6760 6761```ts 6762try { 6763 let windowLimits = windowClass.getWindowLimits(); 6764} catch (exception) { 6765 console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`); 6766} 6767``` 6768 6769## setWindowLimits<sup>11+</sup> 6770 6771setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 6772 6773Sets the size limits for this application window. This API uses a promise to return the result. 6774By default, system size limits are provided. They are determined by the product configuration and cannot be modified. If **setWindowLimits** has not been called, you can call [getWindowLimits](#getwindowlimits11) to obtain the system size limits. 6775 6776**Atomic service API**: This API can be used in atomic services since API version 12. 6777 6778**System capability**: SystemCapability.Window.SessionManager 6779 6780**Parameters** 6781 6782| Name | Type | Mandatory| Description | 6783| :----------- | :---------------------------- | :--- | :----------------------------- | 6784| windowLimits | [WindowLimits](arkts-apis-window-i.md#windowlimits11) | Yes | Target size limits, in px.| 6785 6786**Return value** 6787 6788| Type | Description | 6789| :------------------------------------------- | :---------------------------------- | 6790| Promise<[WindowLimits](arkts-apis-window-i.md#windowlimits11)> | Promise used to return the final size limits, which are the intersection between the passed-in size limits and the system size limits.| 6791 6792**Error codes** 6793 6794For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6795 6796| ID| Error Message | 6797| :------- | :-------------------------------------------- | 6798| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6799| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6800| 1300002 | This window state is abnormal. | 6801| 1300003 | This window manager service works abnormally. | 6802| 1300004 | Unauthorized operation. | 6803 6804**Example** 6805 6806```ts 6807import { BusinessError } from '@kit.BasicServicesKit'; 6808try { 6809 let windowLimits: window.WindowLimits = { 6810 maxWidth: 1500, 6811 maxHeight: 1000, 6812 minWidth: 500, 6813 minHeight: 400 6814 }; 6815 let promise = windowClass.setWindowLimits(windowLimits); 6816 promise.then((data) => { 6817 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6818 }).catch((err: BusinessError) => { 6819 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6820 }); 6821} catch (exception) { 6822 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6823} 6824``` 6825 6826## setWindowLimits<sup>15+</sup> 6827 6828setWindowLimits(windowLimits: WindowLimits, isForcible: boolean): Promise<WindowLimits> 6829 6830Sets the size limits for this application window. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 6831 6832By default, system size limits are provided. They are determined by the product configuration and cannot be modified. If **setWindowLimits** has not been called, you can call [getWindowLimits](#getwindowlimits11) to obtain the system size limits. 6833 6834**Atomic service API**: This API can be used in atomic services since API version 15. 6835 6836**System capability**: SystemCapability.Window.SessionManager 6837 6838**Device behavior differences**: In versions earlier than API version 19, this API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. Since API version 19, this API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 6839 6840**Parameters** 6841 6842| Name | Type | Mandatory| Description | 6843| :----------- | :---------------------------- | :--- | :----------------------------- | 6844| windowLimits | [WindowLimits](arkts-apis-window-i.md#windowlimits11) | Yes | Target size limits, in px.| 6845| isForcible | boolean | Yes | Whether to forcibly set the window size limits.<br>If this parameter is set to **true**, the minimum width and height of the window are determined by the lower value between the system size limits and 40 vp, and the maximum width and height depend on the system size limits.<br>If this parameter is set to **false**, the minimum and maximum window width and height are restricted by the system size limits.| 6846 6847**Return value** 6848 6849| Type | Description | 6850| :------------------------------------------- | :---------------------------------- | 6851| Promise<[WindowLimits](arkts-apis-window-i.md#windowlimits11)> | Promise used to return the new window size limits. Depending on the value of **isForcible**, the return value represents the intersection between the value passed and the system size limits.| 6852 6853**Error codes** 6854 6855For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6856 6857| ID| Error Message | 6858| :------- | :-------------------------------------------- | 6859| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6860| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6861| 1300002 | This window state is abnormal. | 6862| 1300003 | This window manager service works abnormally. | 6863| 1300004 | Unauthorized operation. | 6864 6865**Example** 6866 6867```ts 6868import { BusinessError } from '@kit.BasicServicesKit'; 6869try { 6870 let windowLimits: window.WindowLimits = { 6871 maxWidth: 1500, 6872 maxHeight: 1000, 6873 minWidth: 100, 6874 minHeight: 100 6875 }; 6876 let promise = windowClass.setWindowLimits(windowLimits, true); 6877 promise.then((data) => { 6878 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6879 }).catch((err: BusinessError) => { 6880 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6881 }); 6882} catch (exception) { 6883 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6884} 6885``` 6886 6887## setWindowMask<sup>12+</sup> 6888 6889setWindowMask(windowMask: Array<Array<number>>): Promise<void>; 6890 6891Sets a mask for this window to get an irregularly shaped window. This API uses a promise to return the result. The mask is used to describe the shape of the irregularly shaped window. This API is available only for child windows and global floating windows. 6892When the size of an irregularly shaped window changes, the actual display content is the intersection of the mask size and the window size. 6893 6894Error code 1300002 may be returned only when multiple threads operate the same window. Error code 401 is returned when the window is destroyed. 6895 6896<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End--> 6897 6898**Atomic service API**: This API can be used in atomic services since API version 12. 6899 6900**System capability**: SystemCapability.Window.SessionManager 6901 6902**Parameters** 6903 6904| Name | Type | Mandatory| Description | 6905| :----------- | :---------------------------- | :--- | :----------------------------- | 6906| windowMask | Array<Array<number>> | Yes | Mask. The value can only be a two-dimensional array containing the window size in pixels, with each element in the array set to either **0** or **1**. The value **0** indicates that the pixel is transparent, and **1** indicates that the pixel is opaque. If the passed-in pixel array does not match the window size or the value of any element in the array is not **0** or **1**, the value is invalid.| 6907 6908**Return value** 6909 6910| Type | Description | 6911| :------------------------------------------- | :---------------------------------- | 6912| Promise<void> | Promise that returns no value.| 6913 6914**Error codes** 6915 6916For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6917 6918| ID| Error Message | 6919| :------- | :-------------------------------------------- | 6920| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6921| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6922| 1300002 | This window state is abnormal. | 6923| 1300003 | This window manager service works abnormally. | 6924| 1300004 | Unauthorized operation. | 6925 6926**Example** 6927 6928```ts 6929import { BusinessError } from '@kit.BasicServicesKit'; 6930try { 6931 let windowMask: Array<Array<number>> = [ 6932 [0, 0, 0, 1, 0, 0, 0], 6933 [0, 0, 1, 1, 1, 0, 0], 6934 [0, 1, 1, 0, 1, 1, 0], 6935 [1, 1, 0, 0, 0, 1, 1] 6936 ]; 6937 let promise = windowClass.setWindowMask(windowMask); 6938 promise.then(() => { 6939 console.info('Succeeded in setting the window mask.'); 6940 }).catch((err: BusinessError) => { 6941 console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`); 6942 }); 6943} catch (exception) { 6944 console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`); 6945} 6946``` 6947 6948## keepKeyboardOnFocus<sup>11+</sup> 6949 6950keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 6951 6952Sets whether to keep the soft keyboard created by others when a window has focus. This API can be called only by a system window or an application child window. 6953 6954**Atomic service API**: This API can be used in atomic services since API version 12. 6955 6956**System capability**: SystemCapability.Window.SessionManager 6957 6958**Parameters** 6959 6960| Name | Type | Mandatory| Description | 6961| ---------------- | ------- | ---- | ------------------------------------------------------------ | 6962| keepKeyboardFlag | boolean | Yes | Whether to keep the soft keyboard created by others. **true** to keep, **false** otherwise.| 6963 6964**Error codes** 6965 6966For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 6967 6968| ID| Error Message| 6969| ------- | ---------------------------------------- | 6970| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6971| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6972| 1300002 | This window state is abnormal. | 6973| 1300004 | Unauthorized operation. | 6974 6975**Example** 6976 6977```ts 6978try { 6979 windowClass.keepKeyboardOnFocus(true); 6980} catch (exception) { 6981 console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`); 6982} 6983``` 6984 6985## setWindowDecorVisible<sup>11+</sup> 6986 6987setWindowDecorVisible(isVisible: boolean): void 6988 6989Sets whether the title bar is visible in the window. This API takes effect for the window that has a title bar or a three-button area. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 6990 6991When the window title bar is hidden and the main window transitions into full-screen mode, hovering the cursor over the hot zone of the top window's title bar will cause a floating title bar to appear. To prevent the floating title bar from appearing, call [setTitleAndDockHoverShown()](#settitleanddockhovershown14). 6992 6993**Atomic service API**: This API can be used in atomic services since API version 12. 6994 6995**System capability**: SystemCapability.Window.SessionManager 6996 6997**Parameters** 6998 6999| Name | Type | Mandatory| Description | 7000| --------- | ------- | ---- | --------------------------------------------- | 7001| isVisible | boolean | Yes | Whether the title bar is visible. **true** if visible, **false** otherwise.| 7002 7003**Error codes** 7004 7005For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7006 7007| ID| Error Message | 7008| -------- | ------------------------------ | 7009| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7010| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7011| 1300002 | This window state is abnormal. | 7012 7013**Example** 7014 7015```ts 7016import { BusinessError } from '@kit.BasicServicesKit'; 7017let storage: LocalStorage = new LocalStorage(); 7018storage.setOrCreate('storageSimpleProp', 121); 7019windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 7020 let errCode: number = err.code; 7021 if (errCode) { 7022 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 7023 return; 7024 } 7025 console.info('Succeeded in loading the content.'); 7026 let isVisible = false; 7027 // Call setWindowDecorVisible. 7028 try { 7029 windowClass?.setWindowDecorVisible(isVisible); 7030 } catch (exception) { 7031 console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7032 } 7033}); 7034``` 7035 7036## getWindowDecorVisible<sup>18+</sup> 7037 7038getWindowDecorVisible(): boolean 7039 7040Checks whether the title bar of this window is visible. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7041 7042**Atomic service API**: This API can be used in atomic services since API version 18. 7043 7044**System capability**: SystemCapability.Window.SessionManager 7045 7046**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7047 7048**Return value** 7049 7050| Type | Description | 7051| ------ | ------------------------------------------------------------ | 7052| boolean | Check result for whether the title bar is visible. **true** if visible, **false** otherwise.| 7053 7054**Error codes** 7055 7056For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7057 7058| ID| Error Message | 7059| -------- | ------------------------------ | 7060| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7061| 1300002 | This window state is abnormal. | 7062 7063**Example** 7064 7065```ts 7066let isVisible: boolean | undefined = undefined; 7067windowClass.setUIContent('pages/WindowPage').then(() => { 7068 try { 7069 isVisible = windowClass?.getWindowDecorVisible(); 7070 } catch (exception) { 7071 console.error(`Failed to get the window decor visibility. Cause code: ${exception.code}, message: ${exception.message}`); 7072 } 7073}) 7074``` 7075 7076## setWindowTitle<sup>15+</sup> 7077 7078setWindowTitle(titleName: string): Promise<void> 7079 7080Sets the window title. This API uses a promise to return the result. The setting takes effect for a window with a title bar. If the window does not have a title bar, error code 1300002 is returned. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7081 7082**Atomic service API**: This API can be used in atomic services since API version 15. 7083 7084**System capability**: SystemCapability.Window.SessionManager 7085 7086**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7087 7088**Parameters** 7089 7090| Name | Type | Mandatory| Description | 7091| --------- | ------- | ---- | --------------------------------------------- | 7092| titleName | string | Yes | Window title. The title display area should not go past the left side of the three-button area of the system. Any part that goes beyond will show as an ellipsis.| 7093 7094**Return value** 7095 7096| Type| Description| 7097| ------------------- | ------------------------ | 7098| Promise<void> | Promise that returns no value. | 7099 7100**Error codes** 7101 7102For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7103 7104| ID| Error Message | 7105| -------- | ------------------------------ | 7106| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7107| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7108| 1300002 | This window state is abnormal. | 7109 7110**Example** 7111 7112```ts 7113import { BusinessError } from '@kit.BasicServicesKit'; 7114 7115try { 7116 let title = "title"; 7117 windowClass.setWindowTitle(title).then(() => { 7118 console.info('Succeeded in setting the window title.'); 7119 }).catch((err: BusinessError) => { 7120 console.error(`Failed to set the window title. Cause code: ${err.code}, message: ${err.message}`); 7121 }); 7122} catch (exception) { 7123 console.error(`Failed to set the window title. Cause code: ${exception.code}, message: ${exception.message}`); 7124} 7125``` 7126 7127## setWindowTitleMoveEnabled<sup>14+</sup> 7128 7129setWindowTitleMoveEnabled(enabled: boolean): void 7130 7131Enables or disables the capability to move the window (either main window or child window) by dragging its title bar and to maximize the window with a double-click. When this capability is disabled, you can use [startMoving()](#startmoving14) to move the window by dragging in the application's hot zone and use [maximize()](#maximize12) to maximize the window. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7132 7133**Atomic service API**: This API can be used in atomic services since API version 14. 7134 7135**System capability**: SystemCapability.Window.SessionManager 7136 7137**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7138 7139**Parameters** 7140 7141| Name | Type | Mandatory| Description | 7142| --------- | ------- | ---- | --------------------------------------------- | 7143| enabled | boolean | Yes | Whether to enable the capability to move the window by dragging the title bar and to maximize the window with a double-click. **true** to enable, **false** otherwise.| 7144 7145**Error codes** 7146 7147For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7148 7149| ID| Error Message | 7150| -------- | ------------------------------ | 7151| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7152| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7153| 1300002 | This window state is abnormal. | 7154| 1300004 | Unauthorized operation. | 7155 7156**Example** 7157 7158```ts 7159// EntryAbility.ets 7160import { UIAbility } from '@kit.AbilityKit'; 7161 7162export default class EntryAbility extends UIAbility { 7163 onWindowStageCreate(windowStage: window.WindowStage): void { 7164 try { 7165 windowStage.loadContent("pages/Index").then(() =>{ 7166 let windowClass = windowStage.getMainWindowSync(); 7167 let enabled = false; 7168 windowClass.setWindowTitleMoveEnabled(enabled); 7169 console.info(`Succeeded in setting the the window title move enabled: ${enabled}`); 7170 }); 7171 } catch (exception) { 7172 console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`); 7173 } 7174 } 7175} 7176``` 7177 7178## setSubWindowModal<sup>12+</sup> 7179 7180setSubWindowModal(isModal: boolean): Promise<void> 7181 7182Enables the modal property of the child window. This API uses a promise to return the result. 7183 7184This API must be called by a child window and the setting takes effect for the child window. 7185 7186After the modal property is enabled, the parent window does not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7187 7188If this API is called by a main window, an error is reported. 7189 7190**Atomic service API**: This API can be used in atomic services since API version 12. 7191 7192**System capability**: SystemCapability.Window.SessionManager 7193 7194**Parameters** 7195 7196| Name | Type | Mandatory| Description | 7197| --------- | ------- | ---- | --------------------------------------------- | 7198| isModal | boolean | Yes | Whether to enable the modal property of the child window. **true** to enable, **false** otherwise.| 7199 7200 7201**Return value** 7202 7203| Type| Description| 7204| ------------------- | ------------------------ | 7205| Promise<void> | Promise that returns no value.| 7206 7207**Error codes** 7208 7209For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7210 7211| ID| Error Message | 7212| -------- | ------------------------------ | 7213| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7214| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7215| 1300002 | This window state is abnormal. | 7216| 1300003 | This window manager service works abnormally. | 7217| 1300004 | Unauthorized operation. | 7218 7219**Example** 7220 7221```ts 7222// EntryAbility.ets 7223import { UIAbility } from '@kit.AbilityKit'; 7224import { BusinessError } from '@kit.BasicServicesKit'; 7225 7226export default class EntryAbility extends UIAbility { 7227 // ... 7228 onWindowStageCreate(windowStage: window.WindowStage): void { 7229 console.info('onWindowStageCreate'); 7230 let windowClass: window.Window | undefined = undefined; 7231 // Create a child window. 7232 try { 7233 let subWindow = windowStage.createSubWindow("testSubWindow"); 7234 subWindow.then((data) => { 7235 if (data == null) { 7236 console.error("Failed to create the subWindow. Cause: The data is empty"); 7237 return; 7238 } 7239 windowClass = data; 7240 let promise = windowClass.setSubWindowModal(true); 7241 promise.then(() => { 7242 console.info('Succeeded in setting subwindow modal'); 7243 }).catch((err: BusinessError) => { 7244 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7245 }); 7246 }); 7247 } catch (exception) { 7248 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7249 } 7250 } 7251} 7252``` 7253 7254## setSubWindowModal<sup>14+</sup> 7255 7256setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise<void> 7257 7258Sets the modality type of the child window. This API uses a promise to return the result. 7259 7260When the child window is of the window-modal type, its parent window does not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7261 7262When the child window is of the application-modal type, its parent window and the windows from other instances of the application do not respond to user interactions until the child window is closed or the child window's modal property is disabled. 7263 7264This API is used to set the modality type. To disable the modal property, you are advised to use [setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12). 7265 7266If this API is called by a main window, an error is reported. 7267 7268**Atomic service API**: This API can be used in atomic services since API version 14. 7269 7270**System capability**: SystemCapability.Window.SessionManager 7271 7272**Parameters** 7273 7274| Name | Type | Mandatory| Description | 7275| --------- | ------- | ---- | --------------------------------------------- | 7276| isModal | boolean | Yes | Whether to enable the modal property of the child window. **true** to enable, **false** otherwise. Currently, this parameter can only be set to **true**.| 7277| modalityType | [ModalityType](arkts-apis-window-e.md#modalitytype14) | Yes | Modality type of the child window.| 7278 7279**Return value** 7280 7281| Type| Description| 7282| ------------------- | ------------------------ | 7283| Promise<void> | Promise that returns no value.| 7284 7285**Error codes** 7286 7287For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7288 7289| ID| Error Message | 7290| -------- | ------------------------------ | 7291| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7292| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7293| 1300002 | This window state is abnormal. | 7294| 1300003 | This window manager service works abnormally. | 7295| 1300004 | Unauthorized operation. | 7296 7297**Example** 7298 7299```ts 7300// EntryAbility.ets 7301import { UIAbility } from '@kit.AbilityKit'; 7302import { BusinessError } from '@kit.BasicServicesKit'; 7303import { window } from '@kit.ArkUI'; 7304 7305export default class EntryAbility extends UIAbility { 7306 // ... 7307 onWindowStageCreate(windowStage: window.WindowStage): void { 7308 console.info('onWindowStageCreate'); 7309 let windowClass: window.Window | undefined = undefined; 7310 // Create a child window. 7311 try { 7312 let subWindow = windowStage.createSubWindow("testSubWindow"); 7313 subWindow.then((data) => { 7314 if (!data) { 7315 console.error("Failed to create the subWindow. Cause: The data is empty"); 7316 return; 7317 } 7318 windowClass = data; 7319 let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY); 7320 promise.then(() => { 7321 console.info('Succeeded in setting subwindow modal'); 7322 }).catch((err: BusinessError) => { 7323 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7324 }); 7325 }); 7326 } catch (exception) { 7327 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7328 } 7329 } 7330} 7331``` 7332 7333## setWindowDecorHeight<sup>11+</sup> 7334 7335setWindowDecorHeight(height: number): void 7336 7337<!--RP1--> 7338Sets the height of the title bar of this window. This API takes effect for the window that has a title bar or a three-button area on 2-in-1 devices. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7339<!--RP1End--> 7340 7341When the main window transitions into full-screen mode, hovering the mouse over the hot zone of the window's title bar region will cause a floating title bar to appear, with a fixed height of 37 vp. 7342 7343**Atomic service API**: This API can be used in atomic services since API version 12. 7344 7345**System capability**: SystemCapability.Window.SessionManager 7346 7347**Parameters** 7348 7349| Name| Type | Mandatory| Description | 7350| ------ | ------ | ---- | ------------------------------------------------------------ | 7351| height | number | Yes |Height of the title bar. It takes effect only for the window with the title bar. The value is an integer in the range [37,112]. The unit is vp. If a floating-point number is passed in, the value is rounded down. A value outside the range is invalid.| 7352 7353**Error codes** 7354 7355For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7356 7357| ID| Error Message | 7358| -------- | ------------------------------ | 7359| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7360| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7361| 1300002 | This window state is abnormal. | 7362 7363**Example** 7364 7365```ts 7366windowClass.setUIContent('pages/WindowPage').then(() => { 7367 let height: number = 50; 7368 try { 7369 windowClass?.setWindowDecorHeight(height); 7370 console.info(`Succeeded in setting the height of window decor: ${height}`); 7371 } catch (exception) { 7372 console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7373 } 7374}) 7375``` 7376 7377## setDecorButtonStyle<sup>14+</sup> 7378 7379setDecorButtonStyle(dectorStyle: DecorButtonStyle): void 7380 7381Sets the button style of the decoration bar. The setting takes effect only for the main window and child windows. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7382 7383**Atomic service API**: This API can be used in atomic services since API version 14. 7384 7385**System capability**: SystemCapability.Window.SessionManager 7386 7387**Device behavior differences**: In versions earlier than API version 18, this API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. Since API version 18, this API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7388 7389**Parameters** 7390 7391| Name | Type | Mandatory| Description | 7392| --------- | ------- | ---- | --------------------------------------------- | 7393| dectorStyle | [DecorButtonStyle](arkts-apis-window-i.md#decorbuttonstyle14) | Yes | Button style of the decoration bar.| 7394 7395**Error codes** 7396 7397For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7398 7399| ID| Error Message | 7400| -------- | ------------------------------ | 7401| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7402| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7403| 1300002 | This window state is abnormal. | 7404| 1300004 | Unauthorized operation. | 7405 7406**Example** 7407 7408```ts 7409// EntryAbility.ets 7410import { UIAbility } from '@kit.AbilityKit'; 7411import { ConfigurationConstant } from '@kit.AbilityKit'; 7412 7413export default class EntryAbility extends UIAbility { 7414 onWindowStageCreate(windowStage: window.WindowStage): void { 7415 try { 7416 windowStage.loadContent("pages/Index").then(() =>{ 7417 let windowClass = windowStage.getMainWindowSync(); 7418 let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; 7419 let style: window.DecorButtonStyle = { 7420 colorMode: colorMode, 7421 buttonBackgroundSize: 28, 7422 spacingBetweenButtons: 12, 7423 closeButtonRightMargin: 20, 7424 buttonIconSize: 20, 7425 buttonBackgroundCornerRadius: 4 7426 }; 7427 windowClass.setDecorButtonStyle(style); 7428 console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style)); 7429 }); 7430 } catch (exception) { 7431 console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7432 } 7433 } 7434} 7435``` 7436 7437## getDecorButtonStyle<sup>14+</sup> 7438 7439getDecorButtonStyle(): DecorButtonStyle 7440 7441Obtains the button style of the decoration bar. The setting takes effect only for the main window and child windows. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 7442 7443**Atomic service API**: This API can be used in atomic services since API version 14. 7444 7445**System capability**: SystemCapability.Window.SessionManager 7446 7447**Device behavior differences**: In versions earlier than API version 18, this API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. Since API version 18, this API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7448 7449**Return value** 7450 7451| Type | Description | 7452| ------------------------------------- | ------------------------------------------------------------ | 7453| [DecorButtonStyle](arkts-apis-window-i.md#decorbuttonstyle14) | Button style on the decoration bar of the current window. The decoration button area is located in the upper-right corner of the window.| 7454 7455**Error codes** 7456 7457For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7458 7459| ID| Error Message | 7460| -------- | ------------------------------ | 7461| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7462| 1300002 | This window state is abnormal. | 7463| 1300003 | This window manager service works abnormally. | 7464| 1300004 | Unauthorized operation. | 7465 7466**Example** 7467 7468```ts 7469try { 7470 let decorButtonStyle = windowClass.getDecorButtonStyle(); 7471 console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle)); 7472} catch (exception) { 7473 console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7474} 7475``` 7476 7477## getWindowDecorHeight<sup>11+</sup> 7478 7479getWindowDecorHeight(): number 7480 7481<!--RP2--> 7482Obtains the height of the title bar of this window. This API takes effect for the window that has a title bar or a three-button area on 2-in-1 devices. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7483<!--RP2End--> 7484 7485**Atomic service API**: This API can be used in atomic services since API version 12. 7486 7487**System capability**: SystemCapability.Window.SessionManager 7488 7489**Return value** 7490 7491| Type | Description | 7492| ------ | ------------------------------------------------------------ | 7493| number | Height of the title bar. The value is an integer in the range [37,112]. The unit is vp.| 7494 7495**Error codes** 7496 7497For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7498 7499| ID| Error Message | 7500| -------- | ------------------------------ | 7501| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7502| 1300002 | This window state is abnormal. | 7503 7504**Example** 7505 7506```ts 7507windowClass.setUIContent('pages/WindowPage').then(() => { 7508 try { 7509 let height = windowClass?.getWindowDecorHeight(); 7510 console.info(`Succeeded in getting the height of window decor: ${height}`); 7511 } catch (exception) { 7512 console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7513 } 7514}) 7515``` 7516 7517## getTitleButtonRect<sup>11+</sup> 7518 7519getTitleButtonRect(): TitleButtonRect 7520 7521Obtains the rectangle that holds the minimize, maximize, and close buttons on the title bar of the main window or the decorated child window. 7522 7523**Atomic service API**: This API can be used in atomic services since API version 12. 7524 7525**System capability**: SystemCapability.Window.SessionManager 7526 7527**Return value** 7528 7529| Type | Description | 7530| ------------------------------------- | ------------------------------------------------------------ | 7531| [TitleButtonRect](arkts-apis-window-i.md#titlebuttonrect11) | Rectangle obtained, which is located in the upper-right corner of the window.| 7532 7533**Error codes** 7534 7535For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7536 7537| ID| Error Message | 7538| -------- | ------------------------------ | 7539| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7540| 1300002 | This window state is abnormal. | 7541 7542**Example** 7543 7544```ts 7545// EntryAbility.ets 7546import { UIAbility } from '@kit.AbilityKit'; 7547import { BusinessError } from '@kit.BasicServicesKit'; 7548 7549export default class EntryAbility extends UIAbility { 7550 // ... 7551 onWindowStageCreate(windowStage: window.WindowStage): void { 7552 console.info('onWindowStageCreate'); 7553 let windowClass: window.Window | undefined = undefined; 7554 windowStage.getMainWindow((err: BusinessError, data) => { 7555 const errCode: number = err.code; 7556 if (errCode) { 7557 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7558 return; 7559 } 7560 windowClass = data; 7561 try { 7562 let titleButtonArea = windowClass.getTitleButtonRect(); 7563 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 7564 } catch (exception) { 7565 console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`); 7566 } 7567 }); 7568 } 7569} 7570``` 7571 7572## getWindowStatus<sup>12+</sup> 7573 7574getWindowStatus(): WindowStatusType 7575 7576Obtains the mode of this window. 7577 7578**Atomic service API**: This API can be used in atomic services since API version 12. 7579 7580**System capability**: SystemCapability.Window.SessionManager 7581 7582**Return value** 7583 7584| Type | Description | 7585| ------------------------------ | ----------------------------------------| 7586| [WindowStatusType](arkts-apis-window-e.md#windowstatustype11) | Window mode. | 7587 7588**Error codes** 7589 7590For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7591 7592| ID| Error Message| 7593| ------- | ------------------------------ | 7594| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7595| 1300002 | This window state is abnormal. | 7596 7597**Example** 7598 7599```ts 7600try { 7601 let windowStatusType = windowClass.getWindowStatus(); 7602} catch (exception) { 7603 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 7604} 7605``` 7606 7607## isFocused<sup>12+</sup> 7608 7609isFocused(): boolean 7610 7611Checks whether this window is focused. 7612 7613**System capability**: SystemCapability.WindowManager.WindowManager.Core 7614 7615**Atomic service API**: This API can be used in atomic services since API version 12. 7616 7617**Return value** 7618 7619| Type| Description| 7620| ------- | ------------------------------------------------------------------ | 7621| boolean | Check result for whether the window is focused. **true** if focused, **false** otherwise.| 7622 7623**Error codes** 7624 7625For details about the error codes, see [Window Error Codes](errorcode-window.md). 7626 7627| ID| Error Message| 7628| ------- | ------------------------------ | 7629| 1300002 | This window state is abnormal. | 7630 7631**Example** 7632 7633```ts 7634try { 7635 let focus = windowClass.isFocused(); 7636 console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus)); 7637} catch (exception) { 7638 console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`); 7639} 7640``` 7641 7642## createSubWindowWithOptions<sup>12+</sup> 7643 7644createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 7645 7646Creates a child window under the main window, another child window, or floating window. This API uses a promise to return the result. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 7647 7648**Model restriction**: This API can be used only in the stage model. 7649 7650**System capability**: SystemCapability.Window.SessionManager 7651 7652**Atomic service API**: This API can be used in atomic services since API version 12. 7653 7654**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, **undefined** is returned. 7655 7656**Parameters** 7657 7658| Name| Type | Mandatory| Description | 7659| ------ | ------ | ---- | -------------- | 7660| name | string | Yes | Name of the child window.| 7661| options | [SubWindowOptions](arkts-apis-window-i.md#subwindowoptions11) | Yes | Parameters used for creating the child window. | 7662 7663**Return value** 7664 7665| Type | Description | 7666| -------------------------------- | ------------------------------------------------ | 7667| Promise<[Window](arkts-apis-window-Window.md)> | Promise used to used to return the child window created.| 7668 7669**Error codes** 7670 7671For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7672 7673| ID| Error Message| 7674| ------- | ------------------------------ | 7675| 401 | Parameter error. Possible cause: Incorrect parameter types. | 7676| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7677| 1300002 | This window state is abnormal. | 7678| 1300003 | This window manager service works abnormally. | 7679| 1300004 | Unauthorized operation. | 7680 7681**Example** 7682 7683```ts 7684import { BusinessError } from '@kit.BasicServicesKit'; 7685 7686try { 7687 let options : window.SubWindowOptions = { 7688 title: 'title', 7689 decorEnabled: true, 7690 isModal: true 7691 }; 7692 let promise = windowClass.createSubWindowWithOptions('mySubWindow', options); 7693 promise.then((data) => { 7694 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7695 }).catch((err: BusinessError) => { 7696 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 7697 }); 7698} catch (exception) { 7699 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 7700} 7701``` 7702 7703## setParentWindow<sup>19+</sup> 7704 7705setParentWindow(windowId: number): Promise<void> 7706 7707Sets a new parent window for this child window. The new parent window can be a main window, another child window, or a floating window. This API uses a promise to return the result. 7708 7709If the child window is focused and the new parent window is in the foreground, the new parent window will be raised. 7710 7711If the child window is focused and the new parent window has a modal child window with a higher level, the focus will be transferred to that modal child window. 7712 7713**System capability**: SystemCapability.Window.SessionManager 7714 7715**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 7716 7717**Atomic service API**: This API can be used in atomic services since API version 19. 7718 7719**Parameters** 7720 7721| Name| Type | Mandatory| Description | 7722| ------ | ------ | ---- | -------------- | 7723| windowId | number | Yes | Parent window ID, which must be an integer. You are advised to call [getWindowProperties()](#getwindowproperties9) to obtain the parent window ID.| 7724 7725**Return value** 7726 7727| Type | Description | 7728| ------------------- | ------------------------| 7729| Promise<void> | Promise that returns no value.| 7730 7731**Error codes** 7732 7733For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7734 7735| ID| Error Message| 7736| ------- | ------------------------------ | 7737| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7738| 1300002 | This window state is abnormal. | 7739| 1300003 | This window manager service works abnormally. | 7740| 1300004 | Unauthorized operation. | 7741| 1300009 | The parent window is invaild. | 7742 7743**Example** 7744 7745```ts 7746import { BusinessError } from '@kit.BasicServicesKit'; 7747 7748try { 7749 let windowClass: window.Window = window.findWindow("subWindow"); 7750 let newParentWindow: window.Window = window.findWindow("newParentWindow"); 7751 let newParentWindowId: number = newParentWindow.getWindowProperties().id; 7752 let promise = windowClass.setParentWindow(newParentWindowId); 7753 promise.then(() => { 7754 console.info('Succeeded in setting the new parent window.'); 7755 }).catch((err: BusinessError) => { 7756 console.error(`Failed to set the new parent window. Cause code: ${err.code}, message: ${err.message}`); 7757 }); 7758} catch (exception) { 7759 console.error(`Failed to set the new parent window. Cause code: ${exception.code}, message: ${exception.message}`); 7760} 7761``` 7762 7763## getParentWindow<sup>19+</sup> 7764 7765getParentWindow(): Window 7766 7767Obtains the parent window of this child window. 7768 7769**System capability**: SystemCapability.Window.SessionManager 7770 7771**Device behavior differences**: This API can be properly called on 2-in-1 devices. If it is called on other device types, error code 801 is returned. 7772 7773**Atomic service API**: This API can be used in atomic services since API version 19. 7774 7775**Return value** 7776 7777| Type| Description| 7778| ----------------- | ------------------- | 7779| [Window](arkts-apis-window-Window.md) | Parent window.| 7780 7781**Error codes** 7782 7783For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7784 7785| ID| Error Message| 7786| ------- | ------------------------------ | 7787| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7788| 1300002 | This window state is abnormal. | 7789| 1300004 | Unauthorized operation. | 7790| 1300009 | The parent window is invaild. | 7791 7792**Example** 7793 7794```ts 7795try { 7796 let windowClass: window.Window = window.findWindow("subWindow"); 7797 let parentWindow: window.Window = windowClass.getParentWindow(); 7798 let properties = parentWindow.getWindowProperties(); 7799 console.info('Succeeded in obtaining parent window properties. Property: ' + JSON.stringify(properties)); 7800} catch (exception) { 7801 console.error(`Failed to get the parent window. Cause code: ${exception.code}, message: ${exception.message}`); 7802} 7803``` 7804 7805## setWindowTitleButtonVisible<sup>14+</sup> 7806 7807setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void 7808 7809Shows or hides the maximize, minimize, and close buttons on the title bar of the main window. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 7810 7811**Atomic service API**: This API can be used in atomic services since API version 14. 7812 7813**System capability**: SystemCapability.Window.SessionManager 7814 7815**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7816 7817**Parameters** 7818 7819| Name | Type | Mandatory| Description | 7820| --------- | ------- | ---- | --------------------------------------------- | 7821| isMaximizeButtonVisible | boolean | Yes | Whether to show the maximize button. **true** to show, **false** otherwise. If the maximize button is hidden, the corresponding restore button is also hidden in the maximize scenario.| 7822| isMinimizeButtonVisible | boolean | Yes | Whether to show the minimize button. **true** to show, **false** otherwise.| 7823| isCloseButtonVisible | boolean | No | Whether to show the close button. **true** to show, **false** otherwise.| 7824 7825**Error codes** 7826 7827For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7828 7829| ID| Error Message | 7830| -------- | ------------------------------ | 7831| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7832| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7833| 1300002 | This window state is abnormal. | 7834| 1300004 | Unauthorized operation. | 7835 7836**Example** 7837 7838```ts 7839// EntryAbility.ets 7840import { UIAbility } from '@kit.AbilityKit'; 7841import { BusinessError } from '@kit.BasicServicesKit'; 7842import { window } from '@kit.ArkUI'; 7843 7844export default class EntryAbility extends UIAbility { 7845 onWindowStageCreate(windowStage: window.WindowStage): void { 7846 // Load the page corresponding to the main window. 7847 windowStage.loadContent('pages/Index', (err) => { 7848 let mainWindow: window.Window | undefined = undefined; 7849 // Obtain the main window. 7850 windowStage.getMainWindow().then( 7851 data => { 7852 if (!data) { 7853 console.error('Failed to get main window. Cause: The data is undefined.'); 7854 return; 7855 } 7856 mainWindow = data; 7857 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7858 // Call setWindowTitleButtonVisible to hide the maximize, minimize, and close buttons on the title bar of the main window. 7859 mainWindow.setWindowTitleButtonVisible(false, false, false); 7860 } 7861 ).catch((err: BusinessError) => { 7862 if(err.code){ 7863 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7864 } 7865 }); 7866 }); 7867 } 7868} 7869``` 7870 7871## setWindowTopmost<sup>14+</sup> 7872 7873setWindowTopmost(isWindowTopmost: boolean): Promise<void> 7874 7875Places the main window above all the other windows of the application. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 7876 7877Applications use custom shortcut keys to pin or unpin the main window. 7878 7879**Atomic service API**: This API can be used in atomic services since API version 14. 7880 7881**System capability**: SystemCapability.Window.SessionManager 7882 7883**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 7884 7885**Required permissions**: ohos.permission.WINDOW_TOPMOST 7886 7887**Parameters** 7888 7889| Name | Type | Mandatory| Description | 7890| --------- | ------- | ---- | --------------------------------------------- | 7891| isWindowTopmost | boolean | Yes | Whether to pin the main window on top. **true** to pin, **false** otherwise.| 7892 7893**Return value** 7894 7895| Type | Description | 7896| ------------------- | ------------------------- | 7897| Promise<void> | Promise that returns no value.| 7898 7899**Error codes** 7900 7901For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7902 7903| ID| Error Message | 7904| -------- | ------------------------------ | 7905| 201 | Permission verification failed. The application does not have the permission required to call the API. | 7906| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7907| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7908| 1300002 | This window state is abnormal. | 7909| 1300004 | Unauthorized operation. | 7910 7911**Example** 7912 7913```ts 7914// ets/pages/Index.ets 7915import { window } from '@kit.ArkUI'; 7916import { common } from '@kit.AbilityKit'; 7917import { BusinessError } from '@kit.BasicServicesKit'; 7918 7919let windowClass: window.Window | undefined; 7920let keyUpEventAry: string[] = []; 7921 7922@Entry 7923@Component 7924struct Index { 7925 private context = (this.getUIContext()?.getHostContext() as common.UIAbilityContext); 7926 private windowStage = this.context.windowStage; 7927 7928 build() { 7929 RelativeContainer() { 7930 Button("Pin") 7931 .onClick(() => { 7932 try { 7933 windowClass = this.windowStage.getMainWindowSync(); 7934 // The value true means to pin the window on top, and false means to unpin the window. 7935 let isWindowTopmost: boolean = true; 7936 let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost); 7937 promiseTopmost.then(() => { 7938 console.info('Succeeded in setting the main window to be topmost.'); 7939 }).catch((err: BusinessError) => { 7940 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 7941 }); 7942 } catch (exception) { 7943 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`) 7944 } 7945 }) 7946 } 7947 .height('100%') 7948 .width('100%') 7949 .onKeyEvent((event) => { 7950 if(event) { 7951 if(event.type === KeyType.Down) { 7952 keyUpEventAry = []; 7953 } 7954 if(event.type === KeyType.Up) { 7955 keyUpEventAry.push(event.keyText); 7956 // Press Ctrl+T to pin or unpin the main window. 7957 if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) { 7958 let isWindowTopmost: boolean = false; 7959 windowClass.setWindowTopmost(isWindowTopmost); 7960 } 7961 } 7962 } 7963 }) 7964 } 7965} 7966``` 7967 7968## raiseToAppTop<sup>14+</sup> 7969 7970raiseToAppTop(): Promise<void> 7971 7972Brings a child window to the top. This action is limited to child windows of the same type under the same parent window within the current application. For child windows with a custom zLevel property, it only applies to child windows with the same zLevel value under the same parent window within the current application. This API uses a promise to return the result. 7973 7974Before calling this API, ensure that the child window has been created and [showWindow()](#showwindow9) has been successfully executed. 7975 7976**System capability**: SystemCapability.WindowManager.WindowManager.Core 7977 7978**Return value** 7979 7980| Type | Description | 7981| ------------------- | ------------------------- | 7982| Promise<void> | Promise that returns no value.| 7983 7984**Error codes** 7985 7986For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 7987 7988| ID| Error Message| 7989| ------- | ------------------------------ | 7990| 1300002 | This window state is abnormal. | 7991| 1300003 | This window manager service works abnormally. | 7992| 1300004 | Unauthorized operation. | 7993| 1300009 | The parent window is invalid. | 7994 7995**Example** 7996 7997```ts 7998// EntryAbility.ets 7999import { window } from '@kit.ArkUI'; 8000import { UIAbility } from '@kit.AbilityKit'; 8001import { BusinessError } from '@kit.BasicServicesKit'; 8002 8003export default class EntryAbility extends UIAbility { 8004 // ... 8005 onWindowStageCreate(windowStage: window.WindowStage): void { 8006 console.info('onWindowStageCreate'); 8007 // Create a child window. 8008 windowStage.createSubWindow('testSubWindow').then((subWindow) => { 8009 if (subWindow == null) { 8010 console.error('Failed to create the subWindow. Cause: The data is empty'); 8011 return; 8012 } 8013 subWindow.showWindow().then(() => { 8014 subWindow.raiseToAppTop().then(() => { 8015 console.info('Succeeded in raising window to app top'); 8016 }).catch((err: BusinessError)=>{ 8017 console.error(`Failed to raise window to app top. Cause code: ${err.code}, message: ${err.message}`); 8018 }); 8019 }); 8020 }); 8021 } 8022} 8023``` 8024 8025## setRaiseByClickEnabled<sup>14+</sup> 8026 8027setRaiseByClickEnabled(enable: boolean): Promise<void> 8028 8029Sets whether to enable a child window to raise itself by click. This API uses a promise to return the result. 8030 8031Generally, when a child window is clicked, it is brought to the forefront among sibling child windows of the same type that share the same parent window within the application. If the **enable** parameter is set to **false**, when the child window is clicked, it still stays in its existing position. 8032 8033Before calling this API, ensure that the child window has been created and [showWindow()](#showwindow9) has been successfully executed. 8034 8035**System capability**: SystemCapability.Window.SessionManager 8036 8037**Parameters** 8038 8039| Name | Type | Mandatory| Description | 8040| -------- | ------------------------- | ---- | ---------- | 8041| enable | boolean | Yes | Whether a child window can be raised by clicking. **true** if the child window can be raised by clicking, **false** otherwise.| 8042 8043**Return value** 8044 8045| Type | Description | 8046| ------------------- | ------------------------- | 8047| Promise<void> | Promise that returns no value.| 8048 8049**Error codes** 8050 8051For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8052 8053| ID| Error Message| 8054| ------- | ------------------------------ | 8055| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8056| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8057| 1300002 | This window state is abnormal. | 8058| 1300003 | This window manager service works abnormally. | 8059| 1300004 | Unauthorized operation. | 8060| 1300009 | The parent window is invalid. | 8061 8062**Example** 8063 8064```ts 8065// EntryAbility.ets 8066import { window } from '@kit.ArkUI'; 8067import { UIAbility } from '@kit.AbilityKit'; 8068import { BusinessError } from '@kit.BasicServicesKit'; 8069 8070export default class EntryAbility extends UIAbility { 8071 // ... 8072 onWindowStageCreate(windowStage: window.WindowStage): void { 8073 console.info('onWindowStageCreate'); 8074 // Create a child window. 8075 windowStage.createSubWindow("testSubWindow").then((subWindow) => { 8076 if (subWindow == null) { 8077 console.error('Failed to create the subWindow. Cause: The data is empty'); 8078 return; 8079 } 8080 subWindow.showWindow().then(() => { 8081 try { 8082 let enabled = false; 8083 subWindow.setRaiseByClickEnabled(enabled).then(() => { 8084 console.info('Succeeded in disabling the raise-by-click function.'); 8085 }).catch((err: BusinessError) => { 8086 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 8087 }); 8088 } catch (err) { 8089 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 8090 } 8091 }); 8092 }); 8093 } 8094} 8095``` 8096 8097## enableLandscapeMultiWindow<sup>12+</sup> 8098 8099enableLandscapeMultiWindow(): Promise<void> 8100 8101Enables the landscape multi-window mode for the UI page that supports the horizontal layout. You are not advised to call this API for the UI page that adopts the vertical layout. 8102 8103This API takes effect only for the main window of the application. In addition, **preferMultiWindowOrientation** must be set to **landscape_auto** in the [abilities](../../quick-start/module-configuration-file.md#abilities) tag in the **module.json5** file. 8104 8105**Atomic service API**: This API can be used in atomic services since API version 12. 8106 8107**System capability**: SystemCapability.Window.SessionManager 8108 8109**Return value** 8110 8111| Type | Description | 8112| ------------------- | ------------------------- | 8113| Promise<void> | Promise that returns no value.| 8114 8115**Error codes** 8116 8117For details about the error codes, see [Window Error Codes](errorcode-window.md). 8118 8119| ID| Error Message| 8120| ------- | -------------------------------------------- | 8121| 1300002 | This window state is abnormal. | 8122| 1300003 | This window manager service works abnormally. | 8123 8124**Example** 8125 8126```ts 8127// EntryAbility.ets 8128import { UIAbility } from '@kit.AbilityKit'; 8129import { BusinessError } from '@kit.BasicServicesKit'; 8130import { window } from '@kit.ArkUI'; 8131 8132export default class EntryAbility extends UIAbility { 8133 // ... 8134 onWindowStageCreate(windowStage: window.WindowStage): void { 8135 console.info('onWindowStageCreate'); 8136 let windowClass: window.Window | undefined = undefined; 8137 windowStage.getMainWindow((err: BusinessError, data) => { 8138 const errCode: number = err.code; 8139 if (errCode) { 8140 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8141 return; 8142 } 8143 windowClass = data; 8144 let promise = windowClass.enableLandscapeMultiWindow(); 8145 promise.then(() => { 8146 console.info('Succeeded in making multi-window become landscape.'); 8147 }).catch((err: BusinessError) => { 8148 console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`); 8149 }); 8150 }); 8151 } 8152} 8153``` 8154 8155## disableLandscapeMultiWindow<sup>12+</sup> 8156 8157disableLandscapeMultiWindow(): Promise<void> 8158 8159Disables the landscape multi-window mode for the UI page that supports the horizontal layout. 8160 8161This API takes effect only for the main window of the application. In addition, **preferMultiWindowOrientation** must be set to **landscape_auto** in the [abilities](../../quick-start/module-configuration-file.md#abilities) tag in the **module.json5** file. 8162 8163**Atomic service API**: This API can be used in atomic services since API version 12. 8164 8165**System capability**: SystemCapability.Window.SessionManager 8166 8167**Return value** 8168 8169| Type | Description | 8170| ------------------- | ------------------------- | 8171| Promise<void> | Promise that returns no value.| 8172 8173**Error codes** 8174 8175For details about the error codes, see [Window Error Codes](errorcode-window.md). 8176 8177| ID| Error Message| 8178| ------- | -------------------------------------------- | 8179| 1300002 | This window state is abnormal. | 8180| 1300003 | This window manager service works abnormally. | 8181 8182**Example** 8183 8184```ts 8185// EntryAbility.ets 8186import { UIAbility } from '@kit.AbilityKit'; 8187import { BusinessError } from '@kit.BasicServicesKit'; 8188import { window } from '@kit.ArkUI'; 8189 8190export default class EntryAbility extends UIAbility { 8191 // ... 8192 onWindowStageCreate(windowStage: window.WindowStage): void { 8193 console.info('onWindowStageCreate'); 8194 let windowClass: window.Window | undefined = undefined; 8195 windowStage.getMainWindow((err: BusinessError, data) => { 8196 const errCode: number = err.code; 8197 if (errCode) { 8198 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8199 return; 8200 } 8201 windowClass = data; 8202 let promise = windowClass.disableLandscapeMultiWindow(); 8203 promise.then(() => { 8204 console.info('Succeeded in making multi-window become not landscape.'); 8205 }).catch((err: BusinessError) => { 8206 console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`); 8207 }); 8208 }); 8209 } 8210} 8211``` 8212 8213## setDialogBackGestureEnabled<sup>12+</sup> 8214 8215setDialogBackGestureEnabled(enabled: boolean): Promise<void> 8216 8217Sets whether the modal window responds to the back gesture event. An error code is returned if this API is called for a non-modal window. 8218 8219**System capability**: SystemCapability.Window.SessionManager 8220 8221**Atomic service API**: This API can be used in atomic services since API version 12. 8222 8223**Parameters** 8224 8225| Name | Type | Mandatory| Description | 8226| ---------- | ------- | ---- | ------------------------------------------------------------ | 8227| enabled | boolean | Yes | Whether to respond to the back gesture event.<br>**true** means to respond to the back gesture event and trigger the **onBackPress** callback, **false** otherwise.<br>| 8228 8229**Return value** 8230 8231| Type | Description | 8232| ------------------- | ------------------------- | 8233| Promise<void> | Promise that returns no value.| 8234 8235**Error codes** 8236 8237For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8238 8239| ID| Error Message| 8240| ------- | -------------------------------------------- | 8241| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8242| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8243| 1300002 | This window state is abnormal. | 8244| 1300003 | This window manager service works abnormally. | 8245| 1300004 | Unauthorized operation. | 8246 8247**Example** 8248 8249```ts 8250// EntryAbility.ets 8251import { UIAbility } from '@kit.AbilityKit'; 8252import { BusinessError } from '@kit.BasicServicesKit'; 8253 8254export default class EntryAbility extends UIAbility { 8255 onWindowStageCreate(windowStage: window.WindowStage): void { 8256 console.info('onWindowStageCreate'); 8257 let windowClass: window.Window | undefined = undefined; 8258 let config: window.Configuration = { 8259 name: "test", 8260 windowType: window.WindowType.TYPE_DIALOG, 8261 ctx: this.context 8262 }; 8263 try { 8264 window.createWindow(config, (err: BusinessError, data) => { 8265 const errCode: number = err.code; 8266 if (errCode) { 8267 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 8268 return; 8269 } 8270 windowClass = data; 8271 windowClass.setUIContent("pages/Index"); 8272 let enabled = true; 8273 let promise = windowClass.setDialogBackGestureEnabled(enabled); 8274 promise.then(() => { 8275 console.info('Succeeded in setting dialog window to respond back gesture.'); 8276 }).catch((err: BusinessError) => { 8277 console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`); 8278 }); 8279 }); 8280 } catch (exception) { 8281 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 8282 } 8283 } 8284} 8285``` 8286 8287```ts 8288// ets/pages/Index.ets 8289@Entry 8290@Component 8291struct Index { 8292 @State message: string = 'Hello World' 8293 build() { 8294 RelativeContainer() { 8295 Text(this.message) 8296 .id('HelloWorld') 8297 .fontSize(50) 8298 .fontWeight(FontWeight.Bold) 8299 } 8300 .height('100%') 8301 .width('100%') 8302 } 8303 8304 onBackPress(): boolean | void { 8305 console.info('Succeeded in setting dialog window to respond back gesture.'); 8306 return true; 8307 } 8308} 8309``` 8310 8311## enableDrag<sup>20+</sup> 8312 8313enableDrag(enable: boolean): Promise<void> 8314 8315Enables or disables window dragging. This API uses a promise to return the result. 8316 8317After window dragging is enabled, the window can be resized using the mouse or touch operations. 8318 8319This API takes effect only for child windows and system windows on phones, tablets, and 2-in-1 devices. If it is called for other device types or window types, an error is reported. 8320 8321**System capability**: SystemCapability.Window.SessionManager 8322 8323**Parameters** 8324 8325| Name| Type| Mandatory| Description| 8326| -------- | ---------------------------- | -- | --------- | 8327| enable| boolean | Yes| Whether to enable dragging.<br>**true** to enable, **false** otherwise.<br>| 8328 8329**Return value** 8330 8331| Type | Description | 8332| ------------------- | ------------------------- | 8333| Promise<void> | Promise that returns no value. | 8334 8335**Error codes** 8336 8337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8338 8339| ID| Error Message| 8340| -------- | -------------------------------------------- | 8341| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8342| 1300002 | This window state is abnormal. | 8343| 1300003 | This window manager service works abnormally. | 8344| 1300004 | Unauthorized operation. | 8345 8346**Example** 8347 8348```ts 8349import { BusinessError } from '@kit.BasicServicesKit'; 8350 8351try { 8352 windowClass.enableDrag(true).then(() => { 8353 console.info('succeeded in setting window draggable'); 8354 }).catch((err: BusinessError) => { 8355 console.error(`Failed to set window draggable. Cause code: ${err.code}, message: ${err.message}`); 8356 }); 8357} catch (exception) { 8358 console.error(`Failed to set window draggable. Cause code: ${exception.code}, message: ${exception.message}`); 8359} 8360``` 8361 8362## startMoving<sup>14+</sup> 8363 8364startMoving(): Promise<void> 8365 8366Starts moving this window. This API uses a promise to return the result. 8367 8368The window moves along with the cursor or touch point only when this API is called in the callback function of [onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent), where the event type is **TouchType.Down**. 8369 8370In click-and-drag scenarios, if you do not want the drag to start as soon as you press down, you can call this API when the event type is [TouchType.Move](./arkui-ts/ts-appendix-enums.md#touchtype) (as long as **TouchType.Down** has already been triggered) to start the moving effect. 8371 8372On phones, thi API takes effect for child windows and system windows. 8373 8374On tablets not in free windows mode, this API takes effect for child windows and system windows; on tablets in free windows mode, it takes effect for main windows, child windows, and system windows. 8375 8376On 2-in-1 devices, this API takes effect for main windows, child windows, and system windows. 8377 8378If this API is called for other device types or window types, an error is reported. 8379 8380**System capability**: SystemCapability.Window.SessionManager 8381 8382**Atomic service API**: This API can be used in atomic services since API version 14. 8383 8384**Return value** 8385 8386| Type | Description | 8387| ------------------- | ------------------------- | 8388| Promise<void> | Promise that returns no value.| 8389 8390**Error codes** 8391 8392For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8393 8394| ID| Error Message| 8395| -------- | -------------------------------------------- | 8396| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8397| 1300001 | Repeated operation. | 8398| 1300002 | This window state is abnormal. | 8399| 1300003 | This window manager service works abnormally. | 8400| 1300004 | Unauthorized operation. | 8401 8402**Example** 8403 8404```ts 8405// ets/pages/Index.ets 8406import { BusinessError } from '@kit.BasicServicesKit'; 8407 8408@Entry 8409@Component 8410struct Index { 8411 private isTouchDown: boolean = false; 8412 build() { 8413 Row() { 8414 Column() { 8415 Blank('160') 8416 .color(Color.Blue) 8417 .onTouch((event: TouchEvent) => { 8418 if (event.type === TouchType.Down) { 8419 try { 8420 let windowClass: window.Window = window.findWindow("subWindow"); 8421 if (!windowClass) { 8422 console.error('Failed to find window.'); 8423 return; 8424 } 8425 windowClass.startMoving().then(() => { 8426 console.info('Succeeded in starting moving window.') 8427 }).catch((err: BusinessError) => { 8428 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8429 }); 8430 } catch (exception) { 8431 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8432 } 8433 } 8434 }) 8435 Blank('160') 8436 .color(Color.Red) 8437 .onTouch((event: TouchEvent) => { 8438 if(event.type == TouchType.Down){ 8439 this.isTouchDown = true; 8440 } else if (event.type === TouchType.Move && this.isTouchDown) { 8441 try { 8442 let context = this.getUIContext()?.getHostContext(); 8443 if (!context) { 8444 console.error('Failed to get host context.'); 8445 return; 8446 } 8447 window.getLastWindow(context).then((data)=>{ 8448 if (!data) { 8449 console.error('Failed to get last window.'); 8450 return; 8451 } 8452 let windowClass: window.Window = data; 8453 windowClass.startMoving().then(() => { 8454 console.info('Succeeded in starting moving window.') 8455 }).catch((err: BusinessError) => { 8456 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8457 }); 8458 }); 8459 } catch (exception) { 8460 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8461 } 8462 } else { 8463 this.isTouchDown = false; 8464 } 8465 }) 8466 }.width('100%') 8467 }.height('100%').width('100%') 8468 } 8469} 8470``` 8471 8472## startMoving<sup>15+</sup> 8473 8474startMoving(offsetX: number, offsetY: number): Promise<void> 8475 8476Specifies the cursor position within the window and moves the window. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 8477 8478When windows within the same application are split or merged, and the mouse is pressed down to move the new window directly, the cursor may move outside the window if it moves too quickly. This API allows you to set the cursor position within the window during movement. It first adjusts the window to the cursor position before starting to move the window. 8479 8480The window moves along with the cursor only when this API is called in the callback function of [onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent), where the event type is **TouchType.Down**. 8481 8482In click-and-drag scenarios, if you do not want the drag to start as soon as you press down, you can call this API when the event type is [TouchType.Move](./arkui-ts/ts-appendix-enums.md#touchtype) (as long as **TouchType.Down** has already been triggered) to start the moving effect. 8483 8484**System capability**: SystemCapability.Window.SessionManager 8485 8486**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 8487 8488**Atomic service API**: This API can be used in atomic services since API version 15. 8489 8490**Parameters** 8491 8492| Name | Type | Mandatory | Description | 8493| --------- | --------- | ------- |----------------------------------------------------| 8494| offsetX | number | Yes| X-axis offset of the cursor position relative to the upper-left corner of the window during movement, measured in px. This parameter only accepts integer values; any floating-point input will be rounded down. Negative values or values exceeding the window width are invalid. The window width can be obtained from [WindowProperties](arkts-apis-window-i.md#windowproperties).| 8495| offsetY | number | Yes| Y-axis offset of the cursor position relative to the upper-left corner of the window during movement, measured in px. This parameter only accepts integer values; any floating-point input will be rounded down. Negative values or values exceeding the window height are invalid. The window height can be obtained from [WindowProperties](arkts-apis-window-i.md#windowproperties).| 8496 8497**Return value** 8498 8499| Type | Description | 8500| ------------------- |----------------------------| 8501| Promise<void> | Promise that returns no value.| 8502 8503**Error codes** 8504 8505For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8506 8507| ID| Error Message| 8508| ---- | -------------------------------------------- | 8509| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8510| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8511| 1300001 | Repeated operation. | 8512| 1300002 | This window state is abnormal. | 8513| 1300003 | This window manager service works abnormally. | 8514| 1300004 | Unauthorized operation. | 8515 8516**Example** 8517 8518```ts 8519// ets/pages/Index.ets 8520import { BusinessError } from '@kit.BasicServicesKit'; 8521 8522@Entry 8523@Component 8524struct Index { 8525 private isTouchDown: boolean = false; 8526 build() { 8527 Row() { 8528 Column() { 8529 Blank('160') 8530 .color(Color.Blue) 8531 .onTouch((event: TouchEvent) => { 8532 if (event.type === TouchType.Down) { 8533 try { 8534 let windowClass: window.Window = window.findWindow("subWindow"); 8535 if (!windowClass) { 8536 console.error('Failed to find window.'); 8537 return; 8538 } 8539 windowClass.startMoving(100, 50).then(() => { 8540 console.info('Succeeded in starting moving window.') 8541 }).catch((err: BusinessError) => { 8542 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8543 }); 8544 } catch (exception) { 8545 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8546 } 8547 } 8548 }) 8549 Blank('160') 8550 .color(Color.Red) 8551 .onTouch((event: TouchEvent) => { 8552 if(event.type == TouchType.Down){ 8553 this.isTouchDown = true; 8554 } else if (event.type === TouchType.Move && this.isTouchDown) { 8555 try { 8556 let context = this.getUIContext()?.getHostContext(); 8557 if (!context) { 8558 console.error('Failed to get host context.'); 8559 return; 8560 } 8561 window.getLastWindow(context).then((data)=>{ 8562 let windowClass: window.Window = data; 8563 windowClass.startMoving(100, 50).then(() => { 8564 console.info('Succeeded in starting moving window.') 8565 }).catch((err: BusinessError) => { 8566 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8567 }); 8568 }); 8569 } catch (exception) { 8570 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8571 } 8572 } else { 8573 this.isTouchDown = false; 8574 } 8575 }) 8576 }.width('100%') 8577 }.height('100%').width('100%') 8578 } 8579} 8580``` 8581 8582## stopMoving<sup>15+</sup> 8583 8584stopMoving(): Promise<void> 8585 8586Stops window movement when a window is being dragged. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 8587 8588**System capability**: SystemCapability.Window.SessionManager 8589 8590**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 8591 8592**Atomic service API**: This API can be used in atomic services since API version 15. 8593 8594**Return value** 8595 8596| Type | Description | 8597| ------------------- | -------------------------| 8598| Promise<void> | Promise that returns no value.| 8599 8600**Error codes** 8601 8602For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8603 8604| ID| Error Message| 8605| -------- | -------------------------------------------- | 8606| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8607| 1300002 | This window state is abnormal. | 8608| 1300003 | This window manager service works abnormally. | 8609| 1300004 | Unauthorized operation. | 8610 8611**Example** 8612 8613```ts 8614// EntryAbility.ets 8615import { UIAbility } from '@kit.AbilityKit'; 8616import { window } from '@kit.ArkUI'; 8617import { BusinessError } from '@kit.BasicServicesKit'; 8618 8619export default class EntryAbility extends UIAbility { 8620 8621 onWindowStageCreate(windowStage: window.WindowStage) { 8622 try { 8623 let windowClass = windowStage.getMainWindowSync(); 8624 windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 8625 if (data.reason === window.RectChangeReason.MOVE) { 8626 windowClass.stopMoving().then(() => { 8627 console.info('Succeeded in stopping moving window.') 8628 }).catch((err: BusinessError) => { 8629 console.error(`Failed to stop moving. Cause code: ${err.code}, message: ${err.message}`); 8630 }); 8631 } 8632 }); 8633 } catch (exception) { 8634 console.error(`Failed to stop moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8635 } 8636 } 8637} 8638``` 8639 8640## setGestureBackEnabled<sup>13+<sup> 8641 8642setGestureBackEnabled(enabled: boolean): Promise<void> 8643 8644Sets whether to enable the back gesture feature in this window. This API takes effect only in full-screen mode of the main window and cannot be used on 2-in-1 devices. 8645When the back gesture feature is disabled, the application does not recognize the gesture hot zone for back redirection, causing the side-swipe gesture non-functional. However, after you switch to another application or return to the home screen, the gesture hot zone functions normally and the side-swipe gesture works properly. 8646When the back gesture feature is enabled, the application recognizes the gesture hot zone for back redirection, allowing the side-swipe gesture to function as expected. 8647 8648**System capability**: SystemCapability.Window.SessionManager 8649 8650**Atomic service API**: This API can be used in atomic services since API version 13. 8651 8652**Parameters** 8653 8654| Name | Type | Mandatory | Description | 8655| ---------- | --------- | -------- | --------------------------------------------- | 8656| enabled | boolean | Yes | Whether to enable the back gesture feature. **true** to enable, **false** otherwise.| 8657 8658**Return value** 8659 8660| Type | Description | 8661| ------------------- | ------------------------- | 8662| Promise<void> | Promise that returns no value.| 8663 8664**Error codes** 8665 8666For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8667 8668| ID| Error Message | 8669| -------- | ------------------------------------------------------------------------------------------------------------ | 8670| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8671| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8672| 1300002 | This window state is abnormal. | 8673| 1300003 | This window manager service works abnormally. | 8674| 1300004 | Unauthorized operation. | 8675 8676**Example** 8677 8678```ts 8679// EntryAbility.ets 8680import { UIAbility } from '@kit.AbilityKit'; 8681import { BusinessError } from '@kit.BasicServicesKit'; 8682import { window } from '@kit.ArkUI'; 8683 8684export default class EntryAbility extends UIAbility { 8685 // ... 8686 onWindowStageCreate(windowStage: window.WindowStage): void { 8687 console.info('onWindowStageCreate'); 8688 let windowClass: window.Window | undefined = undefined; 8689 windowStage.getMainWindow((err: BusinessError, data) => { 8690 const errCode: number = err.code; 8691 if (errCode) { 8692 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8693 return; 8694 } 8695 windowClass = data; 8696 8697 // Disable the back gesture feature in the current window. 8698 try { 8699 let gestureBackEnabled: boolean = false; 8700 let promise = windowClass.setGestureBackEnabled(gestureBackEnabled); 8701 promise.then(() => { 8702 console.info(`Succeeded in setting gesture back disabled`); 8703 }).catch((err: BusinessError) => { 8704 console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`); 8705 }); 8706 } catch(exception) { 8707 console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`); 8708 } 8709 }); 8710 } 8711} 8712``` 8713 8714## isGestureBackEnabled<sup>13+<sup> 8715 8716isGestureBackEnabled(): boolean 8717 8718Checks whether the back gesture feature is enabled in this window. This API takes effect only in full-screen mode of the main window and cannot be used on 2-in-1 devices. 8719 8720**System capability**: SystemCapability.Window.SessionManager 8721 8722**Atomic service API**: This API can be used in atomic services since API version 13. 8723 8724**Return value** 8725 8726| Type | Description | 8727| ------------------- | --------------------------------------------- | 8728| boolean | Whether the back gesture feature is enabled. **true** if enabled, **false** otherwise.| 8729 8730**Error codes** 8731 8732For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8733 8734| ID| Error Message | 8735| -------- | ------------------------------------------------------------------------------------------------------------ | 8736| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8737| 1300002 | This window state is abnormal. | 8738| 1300003 | This window manager service works abnormally. | 8739| 1300004 | Unauthorized operation. | 8740 8741**Example** 8742 8743```ts 8744// EntryAbility.ets 8745import { UIAbility } from '@kit.AbilityKit'; 8746import { BusinessError } from '@kit.BasicServicesKit'; 8747import { window } from '@kit.ArkUI'; 8748 8749export default class EntryAbility extends UIAbility { 8750 // ... 8751 onWindowStageCreate(windowStage: window.WindowStage): void { 8752 console.info('onWindowStageCreate'); 8753 let windowClass: window.Window | undefined = undefined; 8754 windowStage.getMainWindow((err: BusinessError, data) => { 8755 const errCode: number = err.code; 8756 if (errCode) { 8757 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8758 return; 8759 } 8760 windowClass = data; 8761 8762 // Check whether the back gesture feature is enabled in the current window. 8763 try { 8764 let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled(); 8765 console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`); 8766 } catch (exception) { 8767 console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 8768 } 8769 }); 8770 } 8771} 8772``` 8773 8774## setWindowShadowRadius<sup>17+</sup> 8775 8776setWindowShadowRadius(radius: number): void 8777 8778Sets the blur radius of the shadow on the edges of a child window or floating window. This API can be used only on 2-in-1 devices or tablets. 8779 8780**System capability**: SystemCapability.Window.SessionManager 8781 8782**Atomic service API**: This API can be used in atomic services since API version 17. 8783 8784**Parameters** 8785 8786| Name | Type | Mandatory| Description | 8787| ------- | ------ | ---- |-------------------------------------------------------------| 8788| radius | number | Yes | Radius of the shadow, measured in px. The value is a floating-point number greater than or equal to 0.0, and the value **0.0** means that the shadow is disabled for the window borders. | 8789 8790**Error codes** 8791 8792For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8793 8794| ID| Error Message| 8795| ------- | ------------------------------ | 8796| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8797| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8798| 1300002 | This window state is abnormal. | 8799| 1300004 | Unauthorized operation. | 8800 8801**Example** 8802 8803```ts 8804try { 8805 windowClass.setWindowShadowRadius(4.0); 8806} catch (exception) { 8807 console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`); 8808} 8809``` 8810 8811## setWindowCornerRadius<sup>17+</sup> 8812 8813setWindowCornerRadius(cornerRadius: number): Promise<void> 8814 8815Sets the radius of the rounded corners for a child window or floating window. This API uses a promise to return the result. 8816 8817If the radius of the rounded corner is too large, it may cause the three buttons (maximize, minimize, and close) to be clipped and make their hotspots less recognizable. Set an appropriate radius based on the window size. 8818 8819Before calling this API, you can call [getWindowCornerRadius()](#getwindowcornerradius17) to obtain the default radius of rounded corners of the window. 8820 8821> **NOTE** 8822> 8823> - Prior to API version 20, <!--RP6-->this API can be used only on 2-in-1 devices.<!--RP6End--> 8824> - From API version 20 onwards, this API can be used on phones, 2-in-1 devices, and tablets. 8825 8826**System capability**: SystemCapability.Window.SessionManager 8827 8828**Atomic service API**: This API can be used in atomic services since API version 17. 8829 8830**Parameters** 8831 8832| Name | Type | Mandatory| Description | 8833| ----------- | ------- | ---- |----------------------------------------------------| 8834| cornerRadius | number | Yes | Radius of the rounded corners, measured in vp. The value is a floating-point number greater than or equal to 0.0. The value **0.0** means that the window does not use rounded corners.| 8835 8836**Return value** 8837 8838| Type| Description| 8839| ---------------------- | ------------------------------------------------------------------------------------ | 8840| Promise<void> | Promise that returns no value.| 8841 8842**Error codes** 8843 8844For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8845 8846| ID| Error Message| 8847| ------- | ------------------------------ | 8848| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8849| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8850| 1300002 | This window state is abnormal. | 8851| 1300003 | This window manager service works abnormally. | 8852| 1300004 | Unauthorized operation. | 8853 8854**Example** 8855 8856```ts 8857import { BusinessError } from '@kit.BasicServicesKit'; 8858 8859try{ 8860 let promise = windowClass.setWindowCornerRadius(1.0); 8861 promise.then(() => { 8862 console.info('Succeeded in setting window corner radius.'); 8863 }).catch((err: BusinessError) => { 8864 console.error(`Failed to set window corner radius. Cause code: ${err.code}, message: ${err.message}`); 8865 }); 8866} catch (exception) { 8867 console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8868} 8869 8870``` 8871 8872## getWindowCornerRadius<sup>17+</sup> 8873 8874getWindowCornerRadius(): number 8875 8876Obtains the radius of rounded corners of a child window or floating window. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. If [setWindowCornerRadius()](#setwindowcornerradius17) is not called to set the radius of rounded corners, this API returns the default radius of rounded corners. 8877 8878**System capability**: SystemCapability.Window.SessionManager 8879 8880**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 8881 8882**Atomic service API**: This API can be used in atomic services since API version 17. 8883 8884**Return value** 8885 8886| Type| Description| 8887| ---------------------- | ------------------------------------------------------------------------------------ | 8888| number | Radius of the rounded corner of the child window or floating window, measured in vp.| 8889 8890**Error codes** 8891 8892For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8893 8894| ID| Error Message| 8895| ------- | ------------------------------ | 8896| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8897| 1300002 | This window state is abnormal. | 8898| 1300004 | Unauthorized operation. | 8899 8900**Example** 8901 8902```ts 8903try { 8904 let cornerRadius = windowClass.getWindowCornerRadius(); 8905} catch (exception) { 8906 console.error(`Failed to get corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8907} 8908``` 8909 8910## setExclusivelyHighlighted<sup>15+<sup> 8911 8912setExclusivelyHighlighted(exclusivelyHighlighted: boolean): Promise<void> 8913 8914Sets the exclusive highlight property for the window. When a window set to exclusive highlight gains focus, other windows in the current parent-child window chain that are in the highlighted state will lose their highlighted state. This API uses a promise to return the result. 8915 8916This API does not take effect for the main window, modal window, and dialog boxes. 8917 8918**System capability**: SystemCapability.Window.SessionManager 8919 8920**Atomic service API**: This API can be used in atomic services since API version 15. 8921 8922**Parameters** 8923 8924| Name| Type| Mandatory| Description| 8925| ----------- | ------- | -- | -------------------------------------------------------- | 8926| exclusivelyHighlighted | boolean | Yes| Whether to set exclusive highlight for the window. **true** to set exclusive highlight, **false** otherwise. | 8927 8928**Return value** 8929 8930| Type| Description| 8931| ---------------------- | ------------------------------------------------------------------------------------ | 8932| Promise<void> | Promise that returns no value.| 8933 8934**Error codes** 8935 8936For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8937 8938| ID| Error Message | 8939| -------- | ------------------------------------------------------------------------------------------------------------ | 8940| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8941| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8942| 1300002 | This window state is abnormal. | 8943| 1300003 | This window manager service works abnormally. | 8944| 1300004 | Unauthorized operation. | 8945 8946**Example** 8947 8948```ts 8949import { BusinessError } from '@kit.BasicServicesKit'; 8950 8951let exclusivelyHighlighted: boolean = true; 8952try { 8953 let promise = windowClass.setExclusivelyHighlighted(exclusivelyHighlighted); 8954 promise.then(() => { 8955 console.info('Succeeded in setting the window to be exclusively highlight.'); 8956 }).catch((err: BusinessError) => { 8957 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${err.code}, message: ${err.message}`); 8958 }); 8959} catch (exception) { 8960 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${exception.code}, message: ${exception.message}`); 8961} 8962``` 8963 8964## isWindowHighlighted<sup>18+<sup> 8965 8966isWindowHighlighted(): boolean 8967 8968Checks whether the window is active. To obtain the active state, call this API when the [WindowEventType](arkts-apis-window-e.md#windoweventtype10) lifecycle is **WINDOW_ACTIVE**. 8969 8970You can use [on('windowHighlightChange')](#onwindowhighlightchange15) to listen for status changes and then execute the corresponding service. 8971 8972**System capability**: SystemCapability.Window.SessionManager 8973 8974**Atomic service API**: This API can be used in atomic services since API version 18. 8975 8976**Return value** 8977 8978| Type | Description | 8979| ------------------- | --------------------------------------------- | 8980| boolean | Check result for whether the window is active. **true** if active, **false** otherwise.| 8981 8982**Error codes** 8983 8984For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 8985 8986| ID| Error Message | 8987| -------- | ------------------------------------------------------------------------------------------------------------ | 8988| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8989| 1300002 | This window state is abnormal. | 8990 8991**Example** 8992 8993```ts 8994import { BusinessError } from '@kit.BasicServicesKit'; 8995 8996try { 8997 let isHighlighted = windowClass.isWindowHighlighted(); 8998 console.info(`Succeeded in getting the window highlight status: ${isHighlighted}`); 8999} catch (exception) { 9000 console.error(`Failed to get the window highlight status.. Cause code: ${exception.code}, message: ${exception.message}`); 9001} 9002``` 9003 9004## setFollowParentMultiScreenPolicy<sup>17+<sup> 9005 9006setFollowParentMultiScreenPolicy(enabled: boolean): Promise<void> 9007 9008Sets whether a child window can span multiple screens and be simultaneously displayed while its parent window is being dragged or resized. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. This API uses a promise to return the result. 9009 9010By default, when a child window follows its parent window's layout changes (by using [moveWindowTo()](#movewindowto9)), it does not support spanning multiple screens and being simultaneously displayed. 9011 9012However, calling this API on the child window enables it to span multiple screens and be simultaneously displayed during the layout adjustment process. 9013 9014**System capability**: SystemCapability.Window.SessionManager 9015 9016**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 9017 9018**Atomic service API**: This API can be used in atomic services since API version 17. 9019 9020**Parameters** 9021 9022| Name| Type| Mandatory| Description| 9023| ----------- | ------- | -- | -------------------------------------------------------- | 9024| enabled | boolean | Yes| Whether the child window can span multiple screens and be simultaneously displayed while its parent window is being dragged or resized. **true** if supported, **false** otherwise. | 9025 9026**Return value** 9027 9028| Type| Description| 9029| ---------------------- | ------------------------------------------------------------------------------------ | 9030| Promise<void> | Promise that returns no value.| 9031 9032**Error codes** 9033 9034For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9035 9036| ID| Error Message | 9037| -------- | ------------------------------------------------------------------------------------------------------------ | 9038| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9039| 801 | Capability not supported.Function setFollowParentMultiScreenPolicy can not work correctly due to limited device capabilities.| 9040| 1300002 | This window state is abnormal. | 9041| 1300003 | This window manager service works abnormally. | 9042| 1300004 | Unauthorized operation. | 9043 9044**Example** 9045 9046```ts 9047import { BusinessError } from '@kit.BasicServicesKit'; 9048 9049try { 9050 let windowClass: window.Window = window.findWindow("subWindow"); 9051 let enabled: boolean = true; 9052 let promise = windowClass?.setFollowParentMultiScreenPolicy(enabled); 9053 promise.then(() => { 9054 console.info('Succeeded in setting the sub window supports multi-screen simultaneous display') 9055 }).catch((err: BusinessError) => { 9056 console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${err.code}, message: ${err.message}`); 9057 }); 9058} catch (exception) { 9059 console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${exception.code}, message: ${exception.message}`); 9060} 9061``` 9062 9063## setFollowParentWindowLayoutEnabled<sup>17+</sup> 9064 9065setFollowParentWindowLayoutEnabled(enabled: boolean): Promise<void> 9066 9067Sets whether the layout information (position and size) of a child window or modal window (a window with **WindowType** set to **TYPE_DIALOG**) follows the main window. This API uses a promise to return the result. 9068 90691. This API applies only to first-level child windows or modal windows of the main window. 9070 90712. Once this API is called on a child window or modal window, its layout information will immediately match the main window and remain synchronized. This effect will persist until this API is called again with **false**. 9072 90733. If this API is called on a child window or modal window, subsequent calls to APIs like **moveTo** or **resize** to modify the layout information will not take effect. 9074 90754. When a child window or modal window stops using this functionality, its layout information (position and size) may not be a specific value. The application needs to reset it. 9076 9077Once this API is successfully called, the [setRelativePositionToParentWindowEnabled()](#setrelativepositiontoparentwindowenabled20) API will no longer take effect. 9078 9079**Model restriction**: This API can be used only in the stage model. 9080 9081**Atomic service API**: This API can be used in atomic services since API version 17. 9082 9083**System capability**: SystemCapability.Window.SessionManager 9084 9085**Parameters** 9086 9087| Name| Type | Mandatory | Description | 9088| --- | --- | --- | --- | 9089| enabled | boolean | Yes | Whether to follow the layout of the main window. **true** to follow, **false** otherwise.| 9090 9091**Return value** 9092 9093| Type | Description | 9094| --- | --- | 9095| Promise<void> | Promise that returns no value.| 9096 9097**Error codes** 9098 9099For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9100 9101| ID| Error Message| 9102| --- | --- | 9103| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9104| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9105| 1300002 | This window state is abnormal. | 9106| 1300003 | This window manager service works abnormally. | 9107| 1300004 | Unauthorized operation. | 9108 9109**Example** 9110 9111```ts 9112// EntryAbility.ets 9113import { window } from '@kit.ArkUI'; 9114import { BusinessError } from '@kit.BasicServicesKit'; 9115import { UIAbility } from '@kit.AbilityKit'; 9116 9117export default class EntryAbility extends UIAbility { 9118 onWindowStageCreate(windowStage: window.WindowStage): void { 9119 windowStage.loadContent('pages/Index', (loadError) => { 9120 if (loadError.code) { 9121 console.error(`Failed to load the content. Cause code: ${loadError.code}, message: ${loadError.message}`); 9122 return; 9123 } 9124 console.info("Succeeded in loading the content."); 9125 windowStage.createSubWindow("subWindow").then((subWindow: window.Window) => { 9126 if (subWindow == null) { 9127 console.error("Failed to create the subWindow. Cause: The data is empty"); 9128 return; 9129 } 9130 subWindow.setFollowParentWindowLayoutEnabled(true).then(() => { 9131 console.info("after set follow parent window layout") 9132 }).catch((error: BusinessError) => { 9133 console.error(`setFollowParentWindowLayoutEnabled failed. ${error.code} ${error.message}`); 9134 }) 9135 }).catch((error: BusinessError) => { 9136 console.error(`createSubWindow failed. ${error.code} ${error.message}`); 9137 }) 9138 }); 9139 } 9140} 9141``` 9142 9143## setRelativePositionToParentWindowEnabled<sup>20+<sup> 9144 9145setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor, offsetX?: number, offsetY?: number): Promise<void> 9146 9147Sets whether a first-level child window can maintain a fixed relative position to the main window. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. This API uses a promise to return the result. 9148 9149The relative position is defined by the offset between the anchor points of the child window and the main window. Both the child window and the main window use the same type of anchor point. 9150 91511. This API applies only to level-1 child windows that are not maximized. 9152 91532. Once this API is called on a child window, its display position will immediately follow the main window and maintain a fixed relative position. This effect will persist until this API is called again with **false**. 9154 91553. If this API is called on a child window, subsequent calls to [moveWindowTo()](#movewindowto9) or [maximize()](#maximize12) to modify the window's position or size will not take effect. 9156 9157Once this API is successfully called, the [setFollowParentWindowLayoutEnabled()](#setfollowparentwindowlayoutenabled17) API will no longer take effect. 9158 9159**System capability**: SystemCapability.Window.SessionManager 9160 9161**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 9162 9163**Parameters** 9164 9165| Name| Type| Mandatory| Description| 9166| ----------- | ------- | -- | -------------------------------------------------------- | 9167| enabled | boolean | Yes| Whether to maintain a fixed relative position to the main window. **true** to maintain, **false** otherwise. | 9168| anchor | [WindowAnchor](arkts-apis-window-e.md#windowanchor20) | No| Type of anchor point used to maintain the relative position. This parameter takes effect only when **enabled** is set to **true**. The default value is **window.WindowAnchor.TopStart**, indicating that the default anchor point is the top-left corner of the window. | 9169| offsetX | number | No| X-axis offset between the anchor points of the child window and the main window, in px. This parameter takes effect only when **enabled** is set to **true**. Only integer values are supported, and Non-integer values are rounded down. The default value is **0**. | 9170| offsetY | number | No| Y-axis offset between the anchor points of the child window and the main window, in px. This parameter takes effect only when **enabled** is set to **true**. Only integer values are supported, and Non-integer values are rounded down. The default value is **0**. | 9171 9172**Return value** 9173 9174| Type| Description| 9175| ---------------------- | ------------------------------------------------ | 9176| Promise<void> | Promise that returns no value.| 9177 9178**Error codes** 9179 9180For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9181 9182| ID| Error Message | 9183| -------- | ------------------------------------------------------------------------------------------------------------ | 9184| 801 | Capability not supported.Function setRelativePositionToParentWindowEnabled can not work correctly due to limited device capabilities.| 9185| 1300002 | This window state is abnormal. | 9186| 1300003 | This window manager service works abnormally. | 9187| 1300004 | Unauthorized operation. | 9188| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. | 9189 9190**Example** 9191 9192```ts 9193import { window } from '@kit.ArkUI'; 9194import { BusinessError } from '@kit.BasicServicesKit'; 9195import { UIAbility } from '@kit.AbilityKit'; 9196 9197export default class EntryAbility extends UIAbility { 9198 onWindowStageCreate(windowStage: window.WindowStage): void { 9199 windowStage.loadContent('pages/Index', (loadError: BusinessError) => { 9200 if (loadError.code) { 9201 console.error(`Failed to load the content. Cause code: ${loadError.code}, message: ${loadError.message}`); 9202 return; 9203 } 9204 console.info("Succeeded in loading the content."); 9205 windowStage.createSubWindow("subWindow").then((subWindow: window.Window) => { 9206 if (subWindow == null) { 9207 console.error("Failed to create the subWindow. Cause: The data is empty"); 9208 return; 9209 } 9210 subWindow.setRelativePositionToParentWindowEnabled(true).then(() => { 9211 console.info("after set relative position to parent window enabled"); 9212 }).catch((error: BusinessError) => { 9213 console.error(`setRelativePositionToParentWindowEnabled failed. ${error.code} ${error.message}`); 9214 }) 9215 }).catch((error: BusinessError) => { 9216 console.error(`createSubWindow failed. ${error.code} ${error.message}`); 9217 }) 9218 }); 9219 } 9220} 9221``` 9222 9223## setWindowTransitionAnimation<sup>20+</sup> 9224 9225setWindowTransitionAnimation(transitionType: WindowTransitionType, animation: TransitionAnimation): Promise<void> 9226 9227Adds a transition animation to windows in specific scenarios. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 9228 9229Currently, this API can be used only on the main window of an application. 9230 9231**Model restriction**: This API can be used only in the stage model. 9232 9233**Atomic service API**: This API can be used in atomic services since API version 20. 9234 9235**System capability**: SystemCapability.Window.SessionManager 9236 9237**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 9238 9239**Parameters** 9240 9241| Name | Type | Mandatory| Description | 9242| -------------- | ----------------------------------------------- | ---- | -------------------------------------- | 9243| transitionType | [WindowTransitionType](arkts-apis-window-e.md#windowtransitiontype20) | Yes | Scene of the transition animation. Currently, only the destruction scene is supported.| 9244| animation | [TransitionAnimation](arkts-apis-window-i.md#transitionanimation20) | Yes | Configuration of the transition animation. | 9245 9246**Return value** 9247 9248| Type | Description | 9249| ------------------- | ------------------------- | 9250| Promise<void> | Promise that returns no value.| 9251 9252**Error codes** 9253 9254For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9255 9256| ID| Error Message | 9257| -------- | ------------------------------------------------------------ | 9258| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9259| 1300002 | This window state is abnormal. | 9260| 1300003 | This window manager service works abnormally. | 9261| 1300004 | Unauthorized operation. | 9262| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range; 2. Invalid parameter length. | 9263 9264**Example** 9265 9266```typescript 9267// EntryAbility.ets 9268import { BusinessError } from '@kit.BasicServicesKit'; 9269import { UIAbility } from '@kit.AbilityKit'; 9270import { window } from '@kit.ArkUI'; 9271 9272export default class EntryAbility extends UIAbility { 9273 // ... 9274 onWindowStageCreate(windowStage: window.WindowStage): void { 9275 console.info('onWindowStageCreate'); 9276 let windowClass: window.Window | undefined = undefined; 9277 windowStage.getMainWindow((err: BusinessError, data) => { 9278 const errCode: number = err.code; 9279 if (errCode) { 9280 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9281 return; 9282 } 9283 windowClass = data; 9284 try { 9285 const animationConfig: window.WindowAnimationConfig = { 9286 duration: 1000, 9287 curve: window.WindowAnimationCurve.LINEAR, 9288 }; 9289 const transitionAnimation: window.TransitionAnimation = { 9290 opacity: 0.5, 9291 config: animationConfig 9292 }; 9293 let promise = windowClass.setWindowTransitionAnimation(window.WindowTransitionType.DESTROY, transitionAnimation); 9294 promise.then((data) => { 9295 console.info('Succeeded in setting window transition animation. Cause:' + JSON.stringify(data)); 9296 }).catch((err: BusinessError) => { 9297 console.error(`Failed to set window transition animation. Cause code: ${err.code}, message: ${err.message}`); 9298 }); 9299 } catch (exception) { 9300 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 9301 } 9302 }) 9303 } 9304} 9305``` 9306 9307## getWindowTransitionAnimation<sup>20+</sup> 9308 9309getWindowTransitionAnimation(transitionType: WindowTransitionType): TransitionAnimation | undefined 9310 9311Obtains the window transition animation configuration in specific scenarios. This API works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode. 9312 9313Currently, this API can be used only on the main window of an application. 9314 9315**Model restriction**: This API can be used only in the stage model. 9316 9317**Atomic service API**: This API can be used in atomic services since API version 20. 9318 9319**System capability**: SystemCapability.Window.SessionManager 9320 9321**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned. 9322 9323**Parameters** 9324 9325| Name | Type | Mandatory| Description | 9326| -------------- | ----------------------------------------------- | ---- | -------------------------------------- | 9327| transitionType | [WindowTransitionType](arkts-apis-window-e.md#windowtransitiontype20) | Yes | Scene of the transition animation. Currently, only the destruction scene is supported.| 9328 9329**Return value** 9330 9331| Type | Description | 9332| --------------------------------------------- | -------------------------- | 9333| [TransitionAnimation](arkts-apis-window-i.md#transitionanimation20) \| undefined | Transition animation configuration in the corresponding scene. If the [setWindowTransitionAnimation](#setwindowtransitionanimation20) API is not used, undefined is returned.| 9334 9335**Error codes** 9336 9337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9338 9339| ID| Error Message | 9340| -------- | ------------------------------------------------------------ | 9341| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9342| 1300002 | This window state is abnormal. | 9343| 1300003 | This window manager service works abnormally. | 9344| 1300004 | Unauthorized operation. | 9345| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. | 9346 9347**Example** 9348 9349```typescript 9350// EntryAbility.ets 9351import { BusinessError } from '@kit.BasicServicesKit'; 9352import { UIAbility } from '@kit.AbilityKit'; 9353import { window } from '@kit.ArkUI'; 9354 9355export default class EntryAbility extends UIAbility { 9356 // ... 9357 onWindowStageCreate(windowStage: window.WindowStage): void { 9358 console.info('onWindowStageCreate'); 9359 let windowClass: window.Window | undefined = undefined; 9360 windowStage.getMainWindow((err: BusinessError, data) => { 9361 const errCode: number = err.code; 9362 if (errCode) { 9363 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9364 return; 9365 } 9366 windowClass = data; 9367 try { 9368 let transitionAnimationResult = windowClass.getWindowTransitionAnimation(window.WindowTransitionType.DESTROY); 9369 console.info('Succeeded in getting window transition animation: ' + JSON.stringify(transitionAnimationResult)); 9370 } catch (exception) { 9371 console.error(`Failed to obtain the window transition animation. Cause code: ${exception.code}, message: ${exception.message}`); 9372 } 9373 }) 9374 } 9375} 9376``` 9377 9378## setSubWindowZLevel<sup>18+</sup> 9379 9380setSubWindowZLevel(zLevel: number): Promise<void> 9381 9382Sets the z-level of the current child window. Child windows with modal properties are not supported. This API uses a promise to return the result. 9383 9384Changing the z-level of a child window using this API will not cause a focus switch. You are advised to use [shiftAppWindowFocus()](arkts-apis-window-f.md#windowshiftappwindowfocus11) for focus switching. 9385 9386**System capability**: SystemCapability.Window.SessionManager 9387 9388**Atomic service API**: This API can be used in atomic services since API version 18. 9389 9390**Parameters** 9391 9392| Name | Type | Mandatory| Description | 9393| :----------- | :---------------------------- | :--- | :----------------------------- | 9394| zLevel | number | Yes | Z-level of the child window. The default value is 0, and the value range is [–10000, 10000]. Only integers are supported, and floating-point numbers will be rounded down.| 9395 9396**Return value** 9397 9398| Type | Description | 9399| ------------------- | ------------------------- | 9400| Promise<void> | Promise that returns no value.| 9401 9402**Error codes** 9403 9404For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9405 9406| ID| Error Message | 9407| ------- | --------------------------------------------- | 9408| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 9409| 801 | Capability not supported. Function setSubWindowZLevel can not work correctly due to limited device capabilities. | 9410| 1300002 | This window state is abnormal. | 9411| 1300003 | This window manager service works abnormally. | 9412| 1300004 | Unauthorized operation. | 9413| 1300009 | The parent window is invalid. | 9414 9415**Example** 9416 9417```ts 9418// EntryAbility.ets 9419import { window } from '@kit.ArkUI'; 9420import { UIAbility } from '@kit.AbilityKit'; 9421import { BusinessError } from '@kit.BasicServicesKit'; 9422 9423export default class EntryAbility extends UIAbility { 9424 // ... 9425 onWindowStageCreate(windowStage: window.WindowStage): void { 9426 console.info('onWindowStageCreate'); 9427 let zLevel: number = 1; 9428 // Create a child window. 9429 try { 9430 windowStage.createSubWindow('testSubWindow').then((subWindow) => { 9431 if (subWindow == null) { 9432 console.error('Failed to create the sub window. Cause: The sub window is null'); 9433 return; 9434 } 9435 subWindow.setSubWindowZLevel(zLevel).then(() => { 9436 console.info('Succeeded in setting sub window zLevel.'); 9437 }).catch((err: BusinessError) => { 9438 console.error(`Failed to set sub window zLevel. Cause code: ${err.code}, message: ${err.message}`); 9439 }); 9440 }); 9441 } catch (err) { 9442 console.error(`Failed to create the sub window or set zLevel. Cause code: ${err.code}, message: ${err.message}`); 9443 } 9444 } 9445} 9446``` 9447 9448## getSubWindowZLevel<sup>18+</sup> 9449 9450getSubWindowZLevel(): number 9451 9452Obtains the z-level of the current child window. This API cannot be called by the main window or system window. 9453 9454**System capability**: SystemCapability.Window.SessionManager 9455 9456**Atomic service API**: This API can be used in atomic services since API version 18. 9457 9458**Return value** 9459 9460| Type | Description | 9461| ------------------- | --------------------------------------------- | 9462| number | Z-level of the child window.| 9463 9464**Error codes** 9465 9466For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9467 9468| ID| Error Message | 9469| -------- | ------------------------------------------------------------------------------------------------------------ | 9470| 801 | Capability not supported. Function getSubWindowZLevel can not work correctly due to limited device capabilities. | 9471| 1300002 | This window state is abnormal. | 9472| 1300004 | Unauthorized operation. | 9473 9474**Example** 9475 9476```ts 9477// EntryAbility.ets 9478import { window } from '@kit.ArkUI'; 9479import { UIAbility } from '@kit.AbilityKit'; 9480 9481export default class EntryAbility extends UIAbility { 9482 // ... 9483 onWindowStageCreate(windowStage: window.WindowStage): void { 9484 console.info('onWindowStageCreate'); 9485 let subWindowZLevel = -1; 9486 // Create a child window. 9487 windowStage.createSubWindow('testSubWindow').then((subWindow) => { 9488 if (subWindow == null) { 9489 console.error('Failed to create the sub window. Cause: The sub window is null'); 9490 return; 9491 } 9492 try { 9493 subWindowZLevel = subWindow.getSubWindowZLevel(); 9494 console.info(`Succeeded in obtaining sub window zLevel: ${subWindowZLevel}`); 9495 } catch (err) { 9496 console.error(`Failed to obtain the sub window zLevel. Cause code: ${err.code}, message: ${err.message}`); 9497 } 9498 }); 9499 } 9500} 9501``` 9502 9503 9504## setWindowSystemBarProperties<sup>(deprecated)</sup> 9505 9506setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 9507 9508Sets the properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar of the main window. This API uses an asynchronous callback to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 9509 9510This API does not take effect when it is called by a child window. 9511 9512> **NOTE** 9513> 9514> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowSystemBarProperties](#setwindowsystembarproperties9) in promise mode instead. 9515 9516**System capability**: SystemCapability.WindowManager.WindowManager.Core 9517 9518**Atomic service API**: This API can be used in atomic services since API version 12. 9519 9520**Parameters** 9521 9522| Name | Type | Mandatory| Description | 9523| ------------------- | ------------------------------------------- | ---- | ---------------------- | 9524| systemBarProperties | [SystemBarProperties](arkts-apis-window-i.md#systembarproperties) | Yes | <!--Del-->Properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar.| 9525| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9526 9527**Error codes** 9528 9529For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9530 9531| ID| Error Message | 9532| -------- | ------------------------------------------------------------------------------------------------------------ | 9533| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9534| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9535| 1300002 | This window state is abnormal. | 9536| 1300003 | This window manager service works abnormally. | 9537 9538**Example** 9539 9540```ts 9541// EntryAbility.ets 9542import { UIAbility } from '@kit.AbilityKit'; 9543import { BusinessError } from '@kit.BasicServicesKit'; 9544 9545export default class EntryAbility extends UIAbility { 9546 // ... 9547 onWindowStageCreate(windowStage: window.WindowStage): void { 9548 console.info('onWindowStageCreate'); 9549 let windowClass: window.Window | undefined = undefined; 9550 windowStage.getMainWindow((err: BusinessError, data) => { 9551 const errCode: number = err.code; 9552 if (errCode) { 9553 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9554 return; 9555 } 9556 windowClass = data; 9557 let SystemBarProperties: window.SystemBarProperties = { 9558 statusBarColor: '#ff00ff', 9559 navigationBarColor: '#00ff00', 9560 // The following properties are supported since API version 8. 9561 statusBarContentColor: '#ffffff', 9562 navigationBarContentColor: '#00ffff' 9563 }; 9564 try { 9565 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 9566 const errCode: number = err.code; 9567 if (errCode) { 9568 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9569 return; 9570 } 9571 console.info('Succeeded in setting the system bar properties.'); 9572 }); 9573 } catch (exception) { 9574 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 9575 } 9576 }); 9577 } 9578} 9579``` 9580 9581## setWindowSystemBarEnable<sup>(deprecated)</sup> 9582 9583setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 9584 9585<!--RP14-->Sets whether to show the status bar and three-button navigation bar in the main window. The visibility of the status bar and three-button navigation bar is controlled by **status** and **navigation**, respectively.<!--RP14End--> This API uses an asynchronous callback to return the result.<br>From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 9586 9587The return value does not indicate that the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> are shown or hidden. This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 9588 9589> **NOTE** 9590> 9591> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowSystemBarEnable](#setwindowsystembarenable9) in promise mode instead. 9592 9593**Atomic service API**: This API can be used in atomic services since API version 12. 9594 9595**System capability**: SystemCapability.WindowManager.WindowManager.Core 9596 9597**Parameters** 9598 9599| Name | Type | Mandatory| Description | 9600| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- | 9601| names | Array<'status'\|'navigation'> | Yes | Whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> in full-screen mode.<br>For example, to show all of them, set this parameter to **['status', 'navigation']**. If this parameter is set to [], they are hidden.| 9602| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9603 9604**Error codes** 9605 9606For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9607 9608| ID| Error Message | 9609| -------- | ------------------------------------------------------------------------------------------------------------ | 9610| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9611| 1300002 | This window state is abnormal. | 9612| 1300003 | This window manager service works abnormally. | 9613 9614**Example** 9615 9616```ts 9617// The following assumes that all of them are hidden. 9618// EntryAbility.ets 9619import { UIAbility } from '@kit.AbilityKit'; 9620import { BusinessError } from '@kit.BasicServicesKit'; 9621 9622export default class EntryAbility extends UIAbility { 9623 // ... 9624 onWindowStageCreate(windowStage: window.WindowStage): void { 9625 console.info('onWindowStageCreate'); 9626 let windowClass: window.Window | undefined = undefined; 9627 windowStage.getMainWindow((err: BusinessError, data) => { 9628 const errCode: number = err.code; 9629 if (errCode) { 9630 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9631 return; 9632 } 9633 windowClass = data; 9634 let names: Array<'status' | 'navigation'> = []; 9635 try { 9636 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 9637 const errCode: number = err.code; 9638 if (errCode) { 9639 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9640 return; 9641 } 9642 console.info('Succeeded in setting the system bar to be invisible.'); 9643 }); 9644 } catch (exception) { 9645 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 9646 } 9647 }); 9648 } 9649} 9650``` 9651 9652## setWindowLayoutFullScreen<sup>(deprecated)</sup> 9653 9654setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 9655 9656Sets whether the main window layout or the child window layout is immersive. This API uses an asynchronous callback to return the result. It does not work when called by a system window. 9657- An immersive layout means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 9658- A non-immersive layout means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 9659 9660> **NOTE** 9661> 9662> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setWindowLayoutFullScreen](#setwindowlayoutfullscreen9) in promise mode instead. 9663 9664**System capability**: SystemCapability.WindowManager.WindowManager.Core 9665 9666**Atomic service API**: This API can be used in atomic services since API version 12. 9667 9668**Parameters** 9669 9670| Name | Type | Mandatory| Description | 9671| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- | 9672| isLayoutFullScreen | boolean | Yes | Whether the layout of the window is immersive. (In immersive layout mode, the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> remain visible.) **true** if immersive, **false** otherwise.| 9673| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9674 9675**Error codes** 9676 9677For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md). 9678 9679| ID| Error Message | 9680| -------- | ------------------------------------------------------------------------------------------------------------ | 9681| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9682| 1300002 | This window state is abnormal. | 9683| 1300003 | This window manager service works abnormally. | 9684 9685**Example** 9686 9687```ts 9688// EntryAbility.ets 9689import { UIAbility } from '@kit.AbilityKit'; 9690import { BusinessError } from '@kit.BasicServicesKit'; 9691 9692export default class EntryAbility extends UIAbility { 9693 // ... 9694 onWindowStageCreate(windowStage: window.WindowStage): void { 9695 console.info('onWindowStageCreate'); 9696 let windowClass: window.Window | undefined = undefined; 9697 windowStage.getMainWindow((err: BusinessError, data) => { 9698 const errCode: number = err.code; 9699 if (errCode) { 9700 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9701 return; 9702 } 9703 windowClass = data; 9704 let isLayoutFullScreen = true; 9705 try { 9706 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 9707 const errCode: number = err.code; 9708 if (errCode) { 9709 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9710 return; 9711 } 9712 console.info('Succeeded in setting the window layout to full-screen mode.'); 9713 }); 9714 } catch (exception) { 9715 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 9716 } 9717 }); 9718 } 9719} 9720``` 9721 9722## show<sup>(deprecated)</sup> 9723 9724show(callback: AsyncCallback<void>): void 9725 9726Shows this window. This API uses an asynchronous callback to return the result. 9727 9728> **NOTE** 9729> 9730> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9) instead. 9731 9732**System capability**: SystemCapability.WindowManager.WindowManager.Core 9733 9734**Parameters** 9735 9736| Name | Type | Mandatory| Description | 9737| -------- | ------------------------- | ---- | ---------- | 9738| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 9739 9740**Example** 9741 9742```ts 9743import { BusinessError } from '@kit.BasicServicesKit'; 9744 9745windowClass.show((err: BusinessError) => { 9746 const errCode: number = err.code; 9747 if (errCode) { 9748 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 9749 return; 9750 } 9751 console.info('Succeeded in showing the window.'); 9752}); 9753``` 9754 9755## show<sup>(deprecated)</sup> 9756 9757show(): Promise<void> 9758 9759Shows this window. This API uses a promise to return the result. 9760 9761> **NOTE** 9762> 9763> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9-1) instead. 9764 9765**System capability**: SystemCapability.WindowManager.WindowManager.Core 9766 9767**Return value** 9768 9769| Type | Description | 9770| ------------------- | ------------------------- | 9771| Promise<void> | Promise that returns no value.| 9772 9773**Example** 9774 9775```ts 9776import { BusinessError } from '@kit.BasicServicesKit'; 9777 9778let promise = windowClass.show(); 9779promise.then(() => { 9780 console.info('Succeeded in showing the window.'); 9781}).catch((err: BusinessError) => { 9782 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 9783}); 9784``` 9785 9786## destroy<sup>(deprecated)</sup> 9787 9788destroy(callback: AsyncCallback<void>): void 9789 9790Destroys this window. This API uses an asynchronous callback to return the result. 9791 9792> **NOTE** 9793> 9794> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9) instead. 9795 9796**System capability**: SystemCapability.WindowManager.WindowManager.Core 9797 9798**Parameters** 9799 9800| Name | Type | Mandatory| Description | 9801| -------- | ------------------------- | ---- | ---------- | 9802| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 9803 9804**Example** 9805 9806```ts 9807import { BusinessError } from '@kit.BasicServicesKit'; 9808 9809windowClass.destroy((err: BusinessError) => { 9810 const errCode: number = err.code; 9811 if (err.code) { 9812 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 9813 return; 9814 } 9815 console.info('Succeeded in destroying the window.'); 9816}); 9817``` 9818 9819## destroy<sup>(deprecated)</sup> 9820 9821destroy(): Promise<void> 9822 9823Destroys this window. This API uses a promise to return the result. 9824 9825> **NOTE** 9826> 9827> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9-1) instead. 9828 9829**System capability**: SystemCapability.WindowManager.WindowManager.Core 9830 9831**Return value** 9832 9833| Type | Description | 9834| ------------------- | ------------------------- | 9835| Promise<void> | Promise that returns no value.| 9836 9837**Example** 9838 9839```ts 9840import { BusinessError } from '@kit.BasicServicesKit'; 9841 9842let promise = windowClass.destroy(); 9843promise.then(() => { 9844 console.info('Succeeded in destroying the window.'); 9845}).catch((err: BusinessError) => { 9846 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 9847}); 9848``` 9849 9850## moveTo<sup>(deprecated)</sup> 9851 9852moveTo(x: number, y: number, callback: AsyncCallback<void>): void 9853 9854Moves this window. This API uses an asynchronous callback to return the result. 9855 9856This operation is not supported in a window in full-screen mode. 9857 9858> **NOTE** 9859> 9860> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9) instead. 9861 9862**System capability**: SystemCapability.WindowManager.WindowManager.Core 9863 9864**Parameters** 9865 9866| Name | Type | Mandatory| Description | 9867| -------- | ------------------------- | ---- | ------------------------------------------------- | 9868| x | number | Yes | Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. Non-integer values are rounded down.| 9869| y | number | Yes | Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. Non-integer values are rounded down.| 9870| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9871 9872**Example** 9873 9874```ts 9875import { BusinessError } from '@kit.BasicServicesKit'; 9876 9877windowClass.moveTo(300, 300, (err: BusinessError) => { 9878 const errCode: number = err.code; 9879 if (errCode) { 9880 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9881 return; 9882 } 9883 console.info('Succeeded in moving the window.'); 9884}); 9885``` 9886 9887## moveTo<sup>(deprecated)</sup> 9888 9889moveTo(x: number, y: number): Promise<void> 9890 9891Moves this window. This API uses a promise to return the result. 9892 9893This operation is not supported in a window in full-screen mode. 9894 9895> **NOTE** 9896> 9897> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9-1) instead. 9898 9899**System capability**: SystemCapability.WindowManager.WindowManager.Core 9900 9901**Parameters** 9902 9903| Name| Type | Mandatory| Description | 9904| ------ | ------ | ---- | ------------------------------------------------- | 9905| x | number | Yes | Coordinate position along the x-axis to which the window is moved, measured in px. A positive value means the position is to the right of the x-axis origin; a negative value means it is to the left; the value **0** means it is at the x-axis origin. The value must be an integer. Non-integer values are rounded down.| 9906| y | number | Yes | Coordinate position along the y-axis to which the window is moved, measured in px. A positive value means the position is below the y-axis origin; a negative value means it is above; the value **0** means it is at the y-axis origin. The value must be an integer. Non-integer values are rounded down.| 9907 9908**Return value** 9909 9910| Type | Description | 9911| ------------------- | ------------------------- | 9912| Promise<void> | Promise that returns no value.| 9913 9914**Example** 9915 9916```ts 9917import { BusinessError } from '@kit.BasicServicesKit'; 9918 9919let promise = windowClass.moveTo(300, 300); 9920promise.then(() => { 9921 console.info('Succeeded in moving the window.'); 9922}).catch((err: BusinessError) => { 9923 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9924}); 9925``` 9926 9927## resetSize<sup>(deprecated)</sup> 9928 9929resetSize(width: number, height: number, callback: AsyncCallback<void>): void 9930 9931Changes the size of this window. This API uses an asynchronous callback to return the result. 9932 9933- The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 9934- The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 9935 9936The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 9937 9938The new window width and height you set must meet the following limits: 9939- If the window width or height is less than the minimum width or height limit, then the minimum width or height limit takes effect. 9940- If the window width or height is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 9941 9942This operation is not supported in a window in full-screen mode. 9943 9944> **NOTE** 9945> 9946> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9) instead. 9947 9948**System capability**: SystemCapability.WindowManager.WindowManager.Core 9949 9950**Parameters** 9951 9952| Name | Type | Mandatory| Description | 9953| -------- | ------------------------- | ---- | -------------------------- | 9954| width | number | Yes | New width of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 9955| height | number | Yes | New height of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 9956| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 9957 9958**Example** 9959 9960```ts 9961import { BusinessError } from '@kit.BasicServicesKit'; 9962 9963windowClass.resetSize(500, 1000, (err: BusinessError) => { 9964 const errCode: number = err.code; 9965 if (errCode) { 9966 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 9967 return; 9968 } 9969 console.info('Succeeded in changing the window size.'); 9970}); 9971``` 9972 9973## resetSize<sup>(deprecated)</sup> 9974 9975resetSize(width: number, height: number): Promise<void> 9976 9977Changes the size of this window. This API uses a promise to return the result. 9978 9979- The main window and child window have the following default size limits: [320, 1920] in width and [240, 1920] in height, both in units of vp. 9980- The minimum width and height of the main window and child window of the application depends on the configuration on the product side. You can call [getWindowLimits](#getwindowlimits11) to obtain size limits. 9981 9982The system window has the following size limits: (0, 1920] in width and (0, 1920] in height, both in units of vp. 9983 9984The new window width and height you set must meet the following limits: 9985- If the window width or height is less than the minimum width or height limit, then the minimum width or height limit takes effect. 9986- If the window width or height is greater than the maximum width or height limit, then the maximum width or height limit takes effect. 9987 9988This operation is not supported in a window in full-screen mode. 9989 9990> **NOTE** 9991> 9992> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9-1) instead. 9993 9994**System capability**: SystemCapability.WindowManager.WindowManager.Core 9995 9996**Parameters** 9997 9998| Name| Type | Mandatory| Description | 9999| ------ | ------ | ---- | -------------------------- | 10000| width | number | Yes | New width of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 10001| height | number | Yes | New height of the window, in px. The value must be an integer. If a floating-point number is passed in, the value is rounded down. A negative value is invalid.| 10002 10003**Return value** 10004 10005| Type | Description | 10006| ------------------- | ------------------------- | 10007| Promise<void> | Promise that returns no value.| 10008 10009**Example** 10010 10011```ts 10012import { BusinessError } from '@kit.BasicServicesKit'; 10013 10014let promise = windowClass.resetSize(500, 1000); 10015promise.then(() => { 10016 console.info('Succeeded in changing the window size.'); 10017}).catch((err: BusinessError) => { 10018 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 10019}); 10020``` 10021 10022## getProperties<sup>(deprecated)</sup> 10023 10024getProperties(callback: AsyncCallback<WindowProperties>): void 10025 10026Obtains the properties of this window. This API uses an asynchronous callback to return the result. 10027 10028> **NOTE** 10029> 10030> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 10031 10032**System capability**: SystemCapability.WindowManager.WindowManager.Core 10033 10034**Parameters** 10035 10036| Name | Type | Mandatory| Description | 10037| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 10038| callback | AsyncCallback<[WindowProperties](arkts-apis-window-i.md#windowproperties)> | Yes | Callback used to return the window properties.| 10039 10040**Example** 10041 10042```ts 10043import { BusinessError } from '@kit.BasicServicesKit'; 10044 10045windowClass.getProperties((err: BusinessError, data) => { 10046 const errCode: number = err.code; 10047 if (errCode) { 10048 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 10049 return; 10050 } 10051 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 10052}); 10053``` 10054 10055## getProperties<sup>(deprecated)</sup> 10056 10057getProperties(): Promise<WindowProperties> 10058 10059Obtains the properties of this window. This API uses a promise to return the result. 10060 10061> **NOTE** 10062> 10063> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 10064 10065**System capability**: SystemCapability.WindowManager.WindowManager.Core 10066 10067**Return value** 10068 10069| Type | Description | 10070| ---------------------------------------------------- | ------------------------------- | 10071| Promise<[WindowProperties](arkts-apis-window-i.md#windowproperties)> | Promise used to return the window properties.| 10072 10073**Example** 10074 10075```ts 10076import { BusinessError } from '@kit.BasicServicesKit'; 10077 10078let promise = windowClass.getProperties(); 10079promise.then((data) => { 10080 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 10081}).catch((err: BusinessError) => { 10082 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 10083}); 10084``` 10085 10086## getAvoidArea<sup>(deprecated)</sup> 10087 10088getAvoidArea(type: [AvoidAreaType](arkts-apis-window-e.md#avoidareatype7), callback: AsyncCallback<[AvoidArea](arkts-apis-window-i.md#avoidarea7)>): void 10089 10090Obtains 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. 10091 10092> **NOTE** 10093> 10094> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 10095 10096**System capability**: SystemCapability.WindowManager.WindowManager.Core 10097 10098**Parameters** 10099 10100| Name | Type | Mandatory| Description | 10101| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 10102| type | [AvoidAreaType](arkts-apis-window-e.md#avoidareatype7) | Yes | Type of the area.| 10103| callback | AsyncCallback<[AvoidArea](arkts-apis-window-i.md#avoidarea7)> | Yes | Callback used to return the area. | 10104 10105**Example** 10106 10107```ts 10108import { BusinessError } from '@kit.BasicServicesKit'; 10109 10110let type = window.AvoidAreaType.TYPE_SYSTEM; 10111windowClass.getAvoidArea(type, (err: BusinessError, data) => { 10112 const errCode: number = err.code; 10113 if (errCode) { 10114 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 10115 return; 10116 } 10117 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 10118}); 10119``` 10120 10121## getAvoidArea<sup>(deprecated)</sup> 10122 10123getAvoidArea(type: [AvoidAreaType](arkts-apis-window-e.md#avoidareatype7)): Promise<[AvoidArea](arkts-apis-window-i.md#avoidarea7)> 10124 10125Obtains 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. 10126 10127> **NOTE** 10128> 10129> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 10130 10131**System capability**: SystemCapability.WindowManager.WindowManager.Core 10132 10133**Parameters** 10134 10135| Name| Type | Mandatory| Description | 10136| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 10137| type | [AvoidAreaType](arkts-apis-window-e.md#avoidareatype7) | Yes | Type of the area.| 10138 10139**Return value** 10140 10141| Type | Description | 10142|-----------------------------------------| ----------------------------------- | 10143| Promise<[AvoidArea](arkts-apis-window-i.md#avoidarea7)> | Promise used to return the area.| 10144 10145**Example** 10146 10147```ts 10148import { BusinessError } from '@kit.BasicServicesKit'; 10149 10150let type = window.AvoidAreaType.TYPE_SYSTEM; 10151let promise = windowClass.getAvoidArea(type); 10152promise.then((data) => { 10153 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 10154}).catch((err: BusinessError) => { 10155 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 10156}); 10157``` 10158 10159## setFullScreen<sup>(deprecated)</sup> 10160 10161setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 10162 10163Sets whether the main window or the child window is in full-screen mode. This API uses an asynchronous callback to return the result. 10164- Full-screen mode means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 10165- Non-full-screen mode means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 10166 10167> **NOTE** 10168> 10169> 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. 10170 10171**System capability**: SystemCapability.WindowManager.WindowManager.Core 10172 10173**Parameters** 10174 10175| Name | Type | Mandatory| Description | 10176| ------------ | ------------------------- | ---- | ---------------------------------------------- | 10177| isFullScreen | boolean | Yes | Whether to set full-screen mode (full-screen mode affects the display of the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->). **true** to set full-screen mode, **false** otherwise.| 10178| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10179 10180**Example** 10181 10182```ts 10183// EntryAbility.ets 10184import { UIAbility } from '@kit.AbilityKit'; 10185import { BusinessError } from '@kit.BasicServicesKit'; 10186 10187export default class EntryAbility extends UIAbility { 10188 // ... 10189 onWindowStageCreate(windowStage: window.WindowStage): void { 10190 console.info('onWindowStageCreate'); 10191 let windowClass: window.Window | undefined = undefined; 10192 windowStage.getMainWindow((err: BusinessError, data) => { 10193 const errCode: number = err.code; 10194 if (errCode) { 10195 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10196 return; 10197 } 10198 windowClass = data; 10199 let isFullScreen: boolean = true; 10200 windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 10201 const errCode: number = err.code; 10202 if (errCode) { 10203 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10204 return; 10205 } 10206 console.info('Succeeded in enabling the full-screen mode.'); 10207 }); 10208 }); 10209 } 10210} 10211``` 10212 10213## setFullScreen<sup>(deprecated)</sup> 10214 10215setFullScreen(isFullScreen: boolean): Promise<void> 10216 10217Sets whether the main window or the child window is in full-screen mode. This API uses a promise to return the result. 10218- Full-screen mode means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 10219- Non-full-screen mode means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 10220 10221> **NOTE** 10222> 10223> 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. 10224 10225**System capability**: SystemCapability.WindowManager.WindowManager.Core 10226 10227**Parameters** 10228 10229| Name | Type | Mandatory| Description | 10230| ------------ | ------- | ---- | ---------------------------------------------- | 10231| isFullScreen | boolean | Yes | Whether to set full-screen mode (full-screen mode affects the display of the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->). **true** to set full-screen mode, **false** otherwise.| 10232 10233**Return value** 10234 10235| Type | Description | 10236| ------------------- | ------------------------- | 10237| Promise<void> | Promise that returns no value.| 10238 10239**Example** 10240 10241```ts 10242// EntryAbility.ets 10243import { UIAbility } from '@kit.AbilityKit'; 10244import { BusinessError } from '@kit.BasicServicesKit'; 10245 10246export default class EntryAbility extends UIAbility { 10247 // ... 10248 onWindowStageCreate(windowStage: window.WindowStage): void { 10249 console.info('onWindowStageCreate'); 10250 let windowClass: window.Window | undefined = undefined; 10251 windowStage.getMainWindow((err: BusinessError, data) => { 10252 const errCode: number = err.code; 10253 if (errCode) { 10254 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10255 return; 10256 } 10257 windowClass = data; 10258 let isFullScreen: boolean = true; 10259 let promise = windowClass.setFullScreen(isFullScreen); 10260 promise.then(() => { 10261 console.info('Succeeded in enabling the full-screen mode.'); 10262 }).catch((err: BusinessError) => { 10263 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10264 }); 10265 }); 10266 } 10267} 10268``` 10269 10270## setLayoutFullScreen<sup>(deprecated)</sup> 10271 10272setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 10273 10274Sets whether the main window layout or the child window layout is immersive. This API uses an asynchronous callback to return the result. 10275- An immersive layout means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 10276- A non-immersive layout means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 10277 10278> **NOTE** 10279> 10280> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) instead. 10281 10282**System capability**: SystemCapability.WindowManager.WindowManager.Core 10283 10284**Parameters** 10285 10286| Name | Type | Mandatory| Description | 10287| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 10288| isLayoutFullScreen | boolean | Yes | Whether the layout of the window is immersive. (Immersive layout mode does not affect the display of the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->.) **true** if immersive, **false** otherwise.| 10289| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10290 10291**Example** 10292 10293```ts 10294// EntryAbility.ets 10295import { UIAbility } from '@kit.AbilityKit'; 10296import { BusinessError } from '@kit.BasicServicesKit'; 10297 10298export default class EntryAbility extends UIAbility { 10299 // ... 10300 onWindowStageCreate(windowStage: window.WindowStage): void { 10301 console.info('onWindowStageCreate'); 10302 let windowClass: window.Window | undefined = undefined; 10303 windowStage.getMainWindow((err: BusinessError, data) => { 10304 const errCode: number = err.code; 10305 if (errCode) { 10306 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10307 return; 10308 } 10309 windowClass = data; 10310 let isLayoutFullScreen: boolean = true; 10311 windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 10312 const errCode: number = err.code; 10313 if (errCode) { 10314 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10315 return; 10316 } 10317 console.info('Succeeded in setting the window layout to full-screen mode.'); 10318 }); 10319 }); 10320 } 10321} 10322``` 10323 10324## setLayoutFullScreen<sup>(deprecated)</sup> 10325 10326setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 10327 10328Sets whether the main window layout or the child window layout is immersive. This API uses a promise to return the result. 10329- An immersive layout means that the layout does not avoid the status bar or <!--RP15-->three-button navigation bar<!--RP15End-->, and components may overlap with them. 10330- A non-immersive layout means that the layout avoids the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->, and components do not overlap with them. 10331 10332> **NOTE** 10333> 10334> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) instead. 10335 10336**System capability**: SystemCapability.WindowManager.WindowManager.Core 10337 10338**Parameters** 10339 10340| Name | Type | Mandatory| Description | 10341| ------------------ | ------- | ---- | ------------------------------------------------------------ | 10342| isLayoutFullScreen | boolean | Yes | Whether the layout of the window is immersive. (Immersive layout mode does not affect the display of the status bar and <!--RP15-->three-button navigation bar<!--RP15End-->.) **true** if immersive, **false** otherwise.| 10343 10344**Return value** 10345 10346| Type | Description | 10347| ------------------- | ------------------------- | 10348| Promise<void> | Promise that returns no value.| 10349 10350**Example** 10351 10352```ts 10353// EntryAbility.ets 10354import { UIAbility } from '@kit.AbilityKit'; 10355import { BusinessError } from '@kit.BasicServicesKit'; 10356 10357export default class EntryAbility extends UIAbility { 10358 // ... 10359 onWindowStageCreate(windowStage: window.WindowStage): void { 10360 console.info('onWindowStageCreate'); 10361 let windowClass: window.Window | undefined = undefined; 10362 windowStage.getMainWindow((err: BusinessError, data) => { 10363 const errCode: number = err.code; 10364 if (errCode) { 10365 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10366 return; 10367 } 10368 windowClass = data; 10369 let isLayoutFullScreen: boolean = true; 10370 let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 10371 promise.then(() => { 10372 console.info('Succeeded in setting the window layout to full-screen mode.'); 10373 }).catch((err: BusinessError) => { 10374 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10375 }); 10376 }); 10377 } 10378} 10379``` 10380 10381## setSystemBarEnable<sup>(deprecated)</sup> 10382 10383setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 10384 10385<!--RP14-->Sets whether to show the status bar and three-button navigation bar in the main window. The visibility of the status bar and three-button navigation bar is controlled by **status** and **navigation**, respectively.<!--RP14End--> This API uses an asynchronous callback to return the result.<br>From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 10386 10387The return value does not indicate that the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> are shown or hidden. This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 10388 10389> **NOTE** 10390> 10391> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) instead. 10392 10393**System capability**: SystemCapability.WindowManager.WindowManager.Core 10394 10395**Parameters** 10396 10397| Name | Type | Mandatory| Description | 10398| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10399| names | Array<'status'\|'navigation'> | Yes | Whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> in full-screen mode.<br>For example, to show all of them, set this parameter to **['status', 'navigation']**. If this parameter is set to [], they are hidden.| 10400| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10401 10402 10403**Example** 10404 10405```ts 10406// The following assumes that all of them are hidden. 10407// EntryAbility.ets 10408import { UIAbility } from '@kit.AbilityKit'; 10409import { BusinessError } from '@kit.BasicServicesKit'; 10410 10411export default class EntryAbility extends UIAbility { 10412 // ... 10413 onWindowStageCreate(windowStage: window.WindowStage): void { 10414 console.info('onWindowStageCreate'); 10415 let windowClass: window.Window | undefined = undefined; 10416 windowStage.getMainWindow((err: BusinessError, data) => { 10417 const errCode: number = err.code; 10418 if (errCode) { 10419 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10420 return; 10421 } 10422 windowClass = data; 10423 let names: Array<'status' | 'navigation'> = []; 10424 windowClass.setSystemBarEnable(names, (err: BusinessError) => { 10425 const errCode: number = err.code; 10426 if (errCode) { 10427 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 10428 return; 10429 } 10430 console.info('Succeeded in setting the system bar to be invisible.'); 10431 }); 10432 }); 10433 } 10434} 10435``` 10436 10437## setSystemBarEnable<sup>(deprecated)</sup> 10438 10439setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 10440 10441<!--RP14-->Sets whether to show the status bar and three-button navigation bar in the main window. The visibility of the status bar and three-button navigation bar is controlled by **status** and **navigation**, respectively.<!--RP14End--> This API uses a promise to return the result.<br>From API version 12, <!--RP5-->this API does not take effect on 2-in-1 devices.<!--RP5End--> 10442 10443The return value does not indicate that the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> are shown or hidden. This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 10444 10445> **NOTE** 10446> 10447> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) instead. 10448 10449**System capability**: SystemCapability.WindowManager.WindowManager.Core 10450 10451**Parameters** 10452 10453| Name| Type | Mandatory| Description | 10454| ------ | ---------------------------- | ---- | ------------------------ | 10455| names | Array<'status'\|'navigation'> | Yes | Whether to show the status bar and <!--RP15-->three-button navigation bar<!--RP15End--> in full-screen mode.<br>For example, to show all of them, set this parameter to **['status', 'navigation']**. If this parameter is set to [], they are hidden.| 10456 10457**Return value** 10458 10459| Type | Description | 10460| ------------------- | ------------------------- | 10461| Promise<void> | Promise that returns no value.| 10462 10463 10464**Example** 10465 10466```ts 10467// The following assumes that all of them are hidden. 10468// EntryAbility.ets 10469import { UIAbility } from '@kit.AbilityKit'; 10470import { BusinessError } from '@kit.BasicServicesKit'; 10471 10472export default class EntryAbility extends UIAbility { 10473 // ... 10474 onWindowStageCreate(windowStage: window.WindowStage): void { 10475 console.info('onWindowStageCreate'); 10476 let windowClass: window.Window | undefined = undefined; 10477 windowStage.getMainWindow((err: BusinessError, data) => { 10478 const errCode: number = err.code; 10479 if (errCode) { 10480 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10481 return; 10482 } 10483 windowClass = data; 10484 let names: Array<'status' | 'navigation'> = []; 10485 let promise = windowClass.setSystemBarEnable(names); 10486 promise.then(() => { 10487 console.info('Succeeded in setting the system bar to be invisible.'); 10488 }).catch((err: BusinessError) => { 10489 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 10490 }); 10491 }); 10492 } 10493} 10494``` 10495 10496## setSystemBarProperties<sup>(deprecated)</sup> 10497 10498setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 10499 10500Sets the properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar of the main window. This API uses an asynchronous callback to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 10501 10502This API does not take effect when it is called by a child window. The configuration does not take effect in non-full-screen mode (such as floating window or split-screen mode). 10503 10504> **NOTE** 10505> 10506> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9) instead. 10507 10508**System capability**: SystemCapability.WindowManager.WindowManager.Core 10509 10510**Parameters** 10511 10512| Name | Type | Mandatory| Description | 10513| ------------------- | ------------------------------------------- | ---- | ---------------------- | 10514| systemBarProperties | [SystemBarProperties](arkts-apis-window-i.md#systembarproperties) | Yes | <!--Del-->Properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar.| 10515| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10516 10517**Example** 10518 10519```ts 10520// EntryAbility.ets 10521import { UIAbility } from '@kit.AbilityKit'; 10522import { BusinessError } from '@kit.BasicServicesKit'; 10523 10524export default class EntryAbility extends UIAbility { 10525 // ... 10526 onWindowStageCreate(windowStage: window.WindowStage): void { 10527 console.info('onWindowStageCreate'); 10528 let windowClass: window.Window | undefined = undefined; 10529 windowStage.getMainWindow((err: BusinessError, data) => { 10530 const errCode: number = err.code; 10531 if (errCode) { 10532 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10533 return; 10534 } 10535 windowClass = data; 10536 let SystemBarProperties: window.SystemBarProperties = { 10537 statusBarColor: '#ff00ff', 10538 navigationBarColor: '#00ff00', 10539 // The following properties are supported since API version 8. 10540 statusBarContentColor: '#ffffff', 10541 navigationBarContentColor: '#00ffff' 10542 }; 10543 windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 10544 const errCode: number = err.code; 10545 if (errCode) { 10546 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 10547 return; 10548 } 10549 console.info('Succeeded in setting the system bar properties.'); 10550 }); 10551 }); 10552 } 10553} 10554``` 10555 10556## setSystemBarProperties<sup>(deprecated)</sup> 10557 10558setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 10559 10560Sets the properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar of the main window. This API uses a promise to return the result. <!--RP5-->This API does not take effect on 2-in-1 devices.<!--RP5End--> 10561 10562This API does not take effect when it is called by a child window. 10563 10564> **NOTE** 10565> 10566> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9) instead. 10567 10568**System capability**: SystemCapability.WindowManager.WindowManager.Core 10569 10570**Parameters** 10571 10572| Name | Type | Mandatory| Description | 10573| ------------------- | ------------------------------------------- | ---- | ---------------------- | 10574| systemBarProperties | [SystemBarProperties](arkts-apis-window-i.md#systembarproperties) | Yes | <!--Del-->Properties of the <!--Del-->three-button navigation bar and <!--DelEnd-->status bar.| 10575 10576**Return value** 10577 10578| Type | Description | 10579| ------------------- | ------------------------- | 10580| Promise<void> | Promise that returns no value.| 10581 10582**Example** 10583 10584```ts 10585// EntryAbility.ets 10586import { UIAbility } from '@kit.AbilityKit'; 10587import { BusinessError } from '@kit.BasicServicesKit'; 10588 10589export default class EntryAbility extends UIAbility { 10590 // ... 10591 onWindowStageCreate(windowStage: window.WindowStage): void { 10592 console.info('onWindowStageCreate'); 10593 let windowClass: window.Window | undefined = undefined; 10594 windowStage.getMainWindow((err: BusinessError, data) => { 10595 const errCode: number = err.code; 10596 if (errCode) { 10597 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10598 return; 10599 } 10600 windowClass = data; 10601 let SystemBarProperties: window.SystemBarProperties = { 10602 statusBarColor: '#ff00ff', 10603 navigationBarColor: '#00ff00', 10604 // The following properties are supported since API version 8. 10605 statusBarContentColor: '#ffffff', 10606 navigationBarContentColor: '#00ffff' 10607 }; 10608 let promise = windowClass.setSystemBarProperties(SystemBarProperties); 10609 promise.then(() => { 10610 console.info('Succeeded in setting the system bar properties.'); 10611 }).catch((err: BusinessError) => { 10612 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 10613 }); 10614 }); 10615 } 10616} 10617``` 10618 10619## loadContent<sup>(deprecated)</sup> 10620 10621loadContent(path: string, callback: AsyncCallback<void>): void 10622 10623Loads content from a page to this window. This API uses an asynchronous callback to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 10624 10625> **NOTE** 10626> 10627> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9) instead. 10628 10629**System capability**: SystemCapability.WindowManager.WindowManager.Core 10630 10631**Parameters** 10632 10633| Name | Type | Mandatory| Description | 10634| -------- | ------------------------- | ---- | -------------------- | 10635| 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.| 10636| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10637 10638**Example** 10639 10640```ts 10641import { BusinessError } from '@kit.BasicServicesKit'; 10642 10643windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 10644 const errCode: number = err.code; 10645 if (errCode) { 10646 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10647 return; 10648 } 10649 console.info('Succeeded in loading the content.'); 10650}); 10651``` 10652 10653## loadContent<sup>(deprecated)</sup> 10654 10655loadContent(path: string): Promise<void> 10656 10657Loads content from a page to this window. This API uses a promise to return the result. You are advised to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading the new content. Exercise caution when using it. The execution context of the current UI may be unclear. Therefore, you are advised not to perform UI-related operations within the callback. 10658 10659> **NOTE** 10660> 10661> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9-1) instead. 10662 10663**System capability**: SystemCapability.WindowManager.WindowManager.Core 10664 10665**Parameters** 10666 10667| Name| Type | Mandatory| Description | 10668| ------ | ------ | ---- | -------------------- | 10669| 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.| 10670 10671**Return value** 10672 10673| Type | Description | 10674| ------------------- | ------------------------- | 10675| Promise<void> | Promise that returns no value.| 10676 10677**Example** 10678 10679```ts 10680import { BusinessError } from '@kit.BasicServicesKit'; 10681 10682let promise = windowClass.loadContent('pages/page2/page3'); 10683promise.then(() => { 10684 console.info('Succeeded in loading the content.'); 10685}).catch((err: BusinessError) => { 10686 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10687}); 10688``` 10689 10690## isShowing<sup>(deprecated)</sup> 10691 10692isShowing(callback: AsyncCallback<boolean>): void 10693 10694Checks whether this window is displayed. This API uses an asynchronous callback to return the result. 10695 10696> **NOTE** 10697> 10698> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 10699 10700**System capability**: SystemCapability.WindowManager.WindowManager.Core 10701 10702**Parameters** 10703 10704| Name | Type | Mandatory| Description | 10705| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10706| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. **true** if the window is displayed, **false** otherwise.| 10707 10708**Example** 10709 10710```ts 10711import { BusinessError } from '@kit.BasicServicesKit'; 10712 10713windowClass.isShowing((err: BusinessError, data) => { 10714 const errCode: number = err.code; 10715 if (errCode) { 10716 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 10717 return; 10718 } 10719 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 10720}); 10721``` 10722 10723## isShowing<sup>(deprecated)</sup> 10724 10725isShowing(): Promise<boolean> 10726 10727Checks whether this window is displayed. This API uses a promise to return the result. 10728 10729> **NOTE** 10730> 10731> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 10732 10733**System capability**: SystemCapability.WindowManager.WindowManager.Core 10734 10735**Return value** 10736 10737| Type | Description | 10738| ---------------------- | ------------------------------------------------------------ | 10739| Promise<boolean> | Promise used to return the result. **true** if the window is displayed, **false** otherwise.| 10740 10741**Example** 10742 10743```ts 10744import { BusinessError } from '@kit.BasicServicesKit'; 10745 10746let promise = windowClass.isShowing(); 10747promise.then((data) => { 10748 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 10749}).catch((err: BusinessError) => { 10750 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 10751}); 10752``` 10753 10754## on('systemAvoidAreaChange')<sup>(deprecated)</sup> 10755 10756on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 10757 10758Subscribes to the event indicating changes to the area where this window cannot be displayed. 10759 10760> **NOTE** 10761> 10762> This API is supported since API version 7 and deprecated since API version 9. Use [on('avoidAreaChange')](#onavoidareachange9) instead. 10763 10764**System capability**: SystemCapability.WindowManager.WindowManager.Core 10765 10766**Parameters** 10767 10768| Name | Type | Mandatory| Description | 10769| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 10770| 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.| 10771| callback | Callback<[AvoidArea](arkts-apis-window-i.md#avoidarea7)> | Yes | Callback used to return the area. | 10772 10773 10774**Example** 10775 10776```ts 10777windowClass.on('systemAvoidAreaChange', (data) => { 10778 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 10779}); 10780``` 10781 10782## off('systemAvoidAreaChange')<sup>(deprecated)</sup> 10783 10784off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 10785 10786Unsubscribes from the event indicating changes to the area where this window cannot be displayed. 10787 10788> **NOTE** 10789> 10790> This API is supported since API version 7 and deprecated since API version 9. Use [off('avoidAreaChange')](#offavoidareachange9) instead. 10791 10792**System capability**: SystemCapability.WindowManager.WindowManager.Core 10793 10794**Parameters** 10795 10796| Name | Type | Mandatory| Description | 10797| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 10798| 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.| 10799| callback | Callback<[AvoidArea](arkts-apis-window-i.md#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. | 10800 10801**Example** 10802 10803```ts 10804const callback = (avoidArea: window.AvoidArea) => { 10805 // ... 10806} 10807windowClass.on('systemAvoidAreaChange', callback); 10808windowClass.off('systemAvoidAreaChange', callback); 10809// Unregister all the callbacks that have been registered through on(). 10810windowClass.off('systemAvoidAreaChange'); 10811``` 10812 10813## isSupportWideGamut<sup>(deprecated)</sup> 10814 10815isSupportWideGamut(callback: AsyncCallback<boolean>): void 10816 10817Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 10818 10819> **NOTE** 10820> 10821> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9) instead. 10822 10823**System capability**: SystemCapability.WindowManager.WindowManager.Core 10824 10825**Parameters** 10826 10827| Name | Type | Mandatory| Description | 10828| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10829| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. **true** if the wide-gamut color space is supported, **false** otherwise.| 10830 10831**Example** 10832 10833```ts 10834import { BusinessError } from '@kit.BasicServicesKit'; 10835 10836windowClass.isSupportWideGamut((err: BusinessError, data) => { 10837 const errCode: number = err.code; 10838 if (errCode) { 10839 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 10840 return; 10841 } 10842 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 10843}); 10844``` 10845 10846## isSupportWideGamut<sup>(deprecated)</sup> 10847 10848isSupportWideGamut(): Promise<boolean> 10849 10850Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 10851 10852> **NOTE** 10853> 10854> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1) instead. 10855 10856**System capability**: SystemCapability.WindowManager.WindowManager.Core 10857 10858**Return value** 10859 10860| Type | Description | 10861| ---------------------- | ------------------------------------------------------------ | 10862| Promise<boolean> | Promise used to return the result. **true** if the wide-gamut color space is supported, **false** otherwise.| 10863 10864**Example** 10865 10866```ts 10867import { BusinessError } from '@kit.BasicServicesKit'; 10868 10869let promise = windowClass.isSupportWideGamut(); 10870promise.then((data) => { 10871 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 10872}).catch((err: BusinessError) => { 10873 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 10874}); 10875``` 10876 10877## setColorSpace<sup>(deprecated)</sup> 10878 10879setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 10880 10881Sets a color space for this window. This API uses an asynchronous callback to return the result. 10882 10883> **NOTE** 10884> 10885> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9) instead. 10886 10887**System capability**: SystemCapability.WindowManager.WindowManager.Core 10888 10889**Parameters** 10890 10891| Name | Type | Mandatory| Description | 10892| ---------- | ------------------------- | ---- | ------------ | 10893| colorSpace | [ColorSpace](arkts-apis-window-e.md#colorspace8) | Yes | Color space to set.| 10894| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 10895 10896 10897**Example** 10898 10899```ts 10900import { BusinessError } from '@kit.BasicServicesKit'; 10901 10902windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 10903 const errCode: number = err.code; 10904 if (errCode) { 10905 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10906 return; 10907 } 10908 console.info('Succeeded in setting window colorspace.'); 10909}); 10910``` 10911 10912## setColorSpace<sup>(deprecated)</sup> 10913 10914setColorSpace(colorSpace:ColorSpace): Promise<void> 10915 10916Sets a color space for this window. This API uses a promise to return the result. 10917 10918> **NOTE** 10919> 10920> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9-1) instead. 10921 10922**System capability**: SystemCapability.WindowManager.WindowManager.Core 10923 10924**Parameters** 10925 10926| Name | Type | Mandatory| Description | 10927| ---------- | ------------------------- | ---- | -------------- | 10928| colorSpace | [ColorSpace](arkts-apis-window-e.md#colorspace8) | Yes | Color space to set.| 10929 10930**Return value** 10931 10932| Type | Description | 10933| ------------------- | ------------------------- | 10934| Promise<void> | Promise that returns no value.| 10935 10936 10937**Example** 10938 10939```ts 10940import { BusinessError } from '@kit.BasicServicesKit'; 10941 10942let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 10943promise.then(() => { 10944 console.info('Succeeded in setting window colorspace.'); 10945}).catch((err: BusinessError) => { 10946 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10947}); 10948``` 10949 10950## getColorSpace<sup>(deprecated)</sup> 10951 10952getColorSpace(callback: AsyncCallback<ColorSpace>): void 10953 10954Obtains the color space of this window. This API uses an asynchronous callback to return the result. 10955 10956> **NOTE** 10957> 10958> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 10959 10960**System capability**: SystemCapability.WindowManager.WindowManager.Core 10961 10962**Parameters** 10963 10964| Name | Type | Mandatory| Description | 10965| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 10966| callback | AsyncCallback<[ColorSpace](arkts-apis-window-e.md#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.| 10967 10968**Example** 10969 10970```ts 10971import { BusinessError } from '@kit.BasicServicesKit'; 10972 10973windowClass.getColorSpace((err: BusinessError, data) => { 10974 const errCode: number = err.code; 10975 if (errCode) { 10976 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10977 return; 10978 } 10979 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 10980}); 10981``` 10982 10983## getColorSpace<sup>(deprecated)</sup> 10984 10985getColorSpace(): Promise<ColorSpace> 10986 10987Obtains the color space of this window. This API uses a promise to return the result. 10988 10989> **NOTE** 10990> 10991> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 10992 10993**System capability**: SystemCapability.WindowManager.WindowManager.Core 10994 10995**Return value** 10996 10997| Type | Description | 10998| ---------------------------------------- | ------------------------------- | 10999| Promise<[ColorSpace](arkts-apis-window-e.md#colorspace8)> | Promise used to return the current color space.| 11000 11001**Example** 11002 11003```ts 11004import { BusinessError } from '@kit.BasicServicesKit'; 11005 11006let promise = windowClass.getColorSpace(); 11007promise.then((data) => { 11008 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 11009}).catch((err: BusinessError) => { 11010 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 11011}); 11012``` 11013 11014## setBackgroundColor<sup>(deprecated)</sup> 11015 11016setBackgroundColor(color: string, callback: AsyncCallback<void>): void 11017 11018Sets 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. 11019 11020> **NOTE** 11021> 11022> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 11023 11024**System capability**: SystemCapability.WindowManager.WindowManager.Core 11025 11026**Parameters** 11027 11028| Name | Type | Mandatory| Description | 11029| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 11030| 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'**.| 11031| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11032 11033 11034**Example** 11035 11036```ts 11037import { BusinessError } from '@kit.BasicServicesKit'; 11038 11039let color: string = '#00ff33'; 11040windowClass.setBackgroundColor(color, (err: BusinessError) => { 11041 const errCode: number = err.code; 11042 if (errCode) { 11043 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 11044 return; 11045 } 11046 console.info('Succeeded in setting the background color.'); 11047}); 11048``` 11049 11050## setBackgroundColor<sup>(deprecated)</sup> 11051 11052setBackgroundColor(color: string): Promise<void> 11053 11054Sets 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. 11055 11056> **NOTE** 11057> 11058> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 11059 11060**System capability**: SystemCapability.WindowManager.WindowManager.Core 11061 11062**Parameters** 11063 11064| Name| Type | Mandatory| Description | 11065| ------ | ------ | ---- | ------------------------------------------------------------ | 11066| 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'**.| 11067 11068**Return value** 11069 11070| Type | Description | 11071| ------------------- | ------------------------- | 11072| Promise<void> | Promise that returns no value.| 11073 11074 11075**Example** 11076 11077```ts 11078import { BusinessError } from '@kit.BasicServicesKit'; 11079 11080let color: string = '#00ff33'; 11081let promise = windowClass.setBackgroundColor(color); 11082promise.then(() => { 11083 console.info('Succeeded in setting the background color.'); 11084}).catch((err: BusinessError) => { 11085 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 11086}); 11087``` 11088 11089## setBrightness<sup>(deprecated)</sup> 11090 11091setBrightness(brightness: number, callback: AsyncCallback<void>): void 11092 11093Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 11094 11095When 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. 11096 11097> **NOTE** 11098> 11099> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9) instead. 11100 11101**System capability**: SystemCapability.WindowManager.WindowManager.Core 11102 11103**Parameters** 11104 11105| Name | Type | Mandatory| Description | 11106| ---------- | ------------------------- | ---- |---------------------------------------| 11107| brightness | number | Yes | Brightness to set. The value is a floating-point number in the range [0.0, 1.0] or is set to **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 11108| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11109 11110 11111**Example** 11112 11113```ts 11114import { BusinessError } from '@kit.BasicServicesKit'; 11115 11116let brightness: number = 1; 11117windowClass.setBrightness(brightness, (err: BusinessError) => { 11118 const errCode: number = err.code; 11119 if (errCode) { 11120 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 11121 return; 11122 } 11123 console.info('Succeeded in setting the brightness.'); 11124}); 11125``` 11126 11127## setBrightness<sup>(deprecated)</sup> 11128 11129setBrightness(brightness: number): Promise<void> 11130 11131Sets the screen brightness for this window. This API uses a promise to return the result. 11132 11133When 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. 11134 11135> **NOTE** 11136> 11137> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9-1) instead. 11138 11139**System capability**: SystemCapability.WindowManager.WindowManager.Core 11140 11141**Parameters** 11142 11143| Name | Type | Mandatory| Description | 11144| ---------- | ------ | ---- |------------------------------------------| 11145| brightness | number | Yes | Brightness to set. The value is a floating-point number in the range [0.0, 1.0] or is set to **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 11146 11147**Return value** 11148 11149| Type | Description | 11150| ------------------- | ------------------------- | 11151| Promise<void> | Promise that returns no value.| 11152 11153 11154**Example** 11155 11156```ts 11157import { BusinessError } from '@kit.BasicServicesKit'; 11158 11159let brightness: number = 1; 11160let promise = windowClass.setBrightness(brightness); 11161promise.then(() => { 11162 console.info('Succeeded in setting the brightness.'); 11163}).catch((err: BusinessError) => { 11164 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 11165}); 11166``` 11167 11168## setDimBehind<sup>(deprecated)</sup> 11169 11170setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 11171 11172Sets the dimness of the window that is not on top. This API uses an asynchronous callback to return the result. 11173 11174> **NOTE** 11175> 11176> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 11177 11178**System capability**: SystemCapability.WindowManager.WindowManager.Core 11179 11180**Parameters** 11181 11182| Name | Type | Mandatory| Description | 11183| -------------- | ------------------------- | ---- |----------------------------------------| 11184| 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.| 11185| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11186 11187**Example** 11188 11189```ts 11190import { BusinessError } from '@kit.BasicServicesKit'; 11191 11192windowClass.setDimBehind(0.5, (err: BusinessError) => { 11193 const errCode: number = err.code; 11194 if (errCode) { 11195 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 11196 return; 11197 } 11198 console.info('Succeeded in setting the dimness.'); 11199}); 11200``` 11201 11202## setDimBehind<sup>(deprecated)</sup> 11203 11204setDimBehind(dimBehindValue: number): Promise<void> 11205 11206Sets the dimness of the window that is not on top. This API uses a promise to return the result. 11207 11208> **NOTE** 11209> 11210> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 11211 11212**System capability**: SystemCapability.WindowManager.WindowManager.Core 11213 11214**Parameters** 11215 11216| Name | Type | Mandatory| Description | 11217| -------------- | ------ | ---- | -------------------------------------------------- | 11218| dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value **1** indicates the dimmest.| 11219 11220**Return value** 11221 11222| Type | Description | 11223| ------------------- | ------------------------- | 11224| Promise<void> | Promise that returns no value.| 11225 11226**Example** 11227 11228```ts 11229import { BusinessError } from '@kit.BasicServicesKit'; 11230 11231let promise = windowClass.setDimBehind(0.5); 11232promise.then(() => { 11233 console.info('Succeeded in setting the dimness.'); 11234}).catch((err: BusinessError) => { 11235 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 11236}); 11237``` 11238 11239## setFocusable<sup>(deprecated)</sup> 11240 11241setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 11242 11243Sets whether this window is focusable, that is, whether the window can gain focus after it is being operated or using other methods. This API uses an asynchronous callback to return the result. 11244 11245> **NOTE** 11246> 11247> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9) instead. 11248 11249**System capability**: SystemCapability.WindowManager.WindowManager.Core 11250 11251**Parameters** 11252 11253| Name | Type | Mandatory| Description | 11254| ----------- | ------------------------- | ---- | ---------------------------- | 11255| isFocusable | boolean | Yes | Whether the window can gain focus. **true** if the window can gain focus, **false** otherwise.| 11256| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11257 11258 11259**Example** 11260 11261```ts 11262import { BusinessError } from '@kit.BasicServicesKit'; 11263 11264let isFocusable: boolean = true; 11265windowClass.setFocusable(isFocusable, (err: BusinessError) => { 11266 const errCode: number = err.code; 11267 if (errCode) { 11268 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 11269 return; 11270 } 11271 console.info('Succeeded in setting the window to be focusable.'); 11272}); 11273``` 11274 11275## setFocusable<sup>(deprecated)</sup> 11276 11277setFocusable(isFocusable: boolean): Promise<void> 11278 11279Sets whether this window is focusable, that is, whether the window can gain focus after it is being clicked or using other methods. This API uses a promise to return the result. 11280 11281> **NOTE** 11282> 11283> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9-1) instead. 11284 11285**System capability**: SystemCapability.WindowManager.WindowManager.Core 11286 11287**Parameters** 11288 11289| Name | Type | Mandatory| Description | 11290| ----------- | ------- | ---- | ---------------------------- | 11291| isFocusable | boolean | Yes | Whether the window can gain focus. **true** if the window can gain focus, **false** otherwise.| 11292 11293**Return value** 11294 11295| Type | Description | 11296| ------------------- | ------------------------- | 11297| Promise<void> | Promise that returns no value.| 11298 11299 11300**Example** 11301 11302```ts 11303import { BusinessError } from '@kit.BasicServicesKit'; 11304 11305let isFocusable: boolean = true; 11306let promise = windowClass.setFocusable(isFocusable); 11307promise.then(() => { 11308 console.info('Succeeded in setting the window to be focusable.'); 11309}).catch((err: BusinessError) => { 11310 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 11311}); 11312``` 11313 11314## setKeepScreenOn<sup>(deprecated)</sup> 11315 11316setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 11317 11318Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 11319 11320> **NOTE** 11321> 11322> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9) instead. 11323 11324**System capability**: SystemCapability.WindowManager.WindowManager.Core 11325 11326**Parameters** 11327 11328| Name | Type | Mandatory| Description | 11329| -------------- | ------------------------- | ---- | ------------------------ | 11330| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. **true** to keep the screen always on, **false** otherwise.| 11331| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11332 11333 11334**Example** 11335 11336```ts 11337import { BusinessError } from '@kit.BasicServicesKit'; 11338 11339let isKeepScreenOn: boolean = true; 11340windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 11341 const errCode: number = err.code; 11342 if (errCode) { 11343 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 11344 return; 11345 } 11346 console.info('Succeeded in setting the screen to be always on.'); 11347}); 11348``` 11349 11350## setKeepScreenOn<sup>(deprecated)</sup> 11351 11352setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 11353 11354Sets whether to keep the screen always on. This API uses a promise to return the result. 11355 11356> **NOTE** 11357> 11358> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9-1) instead. 11359 11360**System capability**: SystemCapability.WindowManager.WindowManager.Core 11361 11362**Parameters** 11363 11364| Name | Type | Mandatory| Description | 11365| -------------- | ------- | ---- | ------------------------ | 11366| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. **true** to keep the screen always on, **false** otherwise.| 11367 11368**Return value** 11369 11370| Type | Description | 11371| ------------------- | ------------------------- | 11372| Promise<void> | Promise that returns no value.| 11373 11374**Example** 11375 11376```ts 11377import { BusinessError } from '@kit.BasicServicesKit'; 11378 11379let isKeepScreenOn: boolean = true; 11380let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 11381promise.then(() => { 11382 console.info('Succeeded in setting the screen to be always on.'); 11383}).catch((err: BusinessError) => { 11384 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 11385}); 11386``` 11387 11388## setOutsideTouchable<sup>(deprecated)</sup> 11389 11390setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 11391 11392Sets whether the area outside the child window is touchable. This API uses an asynchronous callback to return the result. 11393 11394> **NOTE** 11395> 11396> This API is supported since API version 7 and deprecated since API version 9. 11397> 11398> Since API version 9, the area outside the child window is touchable by default. This API is no longer supported and no substitute API is provided. 11399 11400**System capability**: SystemCapability.WindowManager.WindowManager.Core 11401 11402**Parameters** 11403 11404| Name | Type | Mandatory| Description | 11405| --------- | ------------------------- | ---- | ---------------- | 11406| touchable | boolean | Yes | Whether the area outside the child window is touchable. **true** if touchable, **false** otherwise.| 11407| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11408 11409**Example** 11410 11411```ts 11412import { BusinessError } from '@kit.BasicServicesKit'; 11413 11414windowClass.setOutsideTouchable(true, (err: BusinessError) => { 11415 const errCode: number = err.code; 11416 if (errCode) { 11417 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11418 return; 11419 } 11420 console.info('Succeeded in setting the area to be touchable.'); 11421}); 11422``` 11423 11424## setOutsideTouchable<sup>(deprecated)</sup> 11425 11426setOutsideTouchable(touchable: boolean): Promise<void> 11427 11428Sets whether the area outside the child window is touchable. This API uses a promise to return the result. 11429 11430> **NOTE** 11431> 11432> This API is supported since API version 7 and deprecated since API version 9. 11433> 11434> Since API version 9, the area outside the child window is touchable by default. This API is no longer supported and no substitute API is provided. 11435 11436**System capability**: SystemCapability.WindowManager.WindowManager.Core 11437 11438**Parameters** 11439 11440| Name | Type | Mandatory| Description | 11441| --------- | ------- | ---- | ---------------- | 11442| touchable | boolean | Yes | Whether the area outside the child window is touchable. **true** if touchable, **false** otherwise.| 11443 11444**Return value** 11445 11446| Type | Description | 11447| ------------------- | ------------------------- | 11448| Promise<void> | Promise that returns no value.| 11449 11450**Example** 11451 11452```ts 11453import { BusinessError } from '@kit.BasicServicesKit'; 11454 11455let promise = windowClass.setOutsideTouchable(true); 11456promise.then(() => { 11457 console.info('Succeeded in setting the area to be touchable.'); 11458}).catch((err: BusinessError) => { 11459 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11460}); 11461``` 11462 11463## setPrivacyMode<sup>(deprecated)</sup> 11464 11465setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 11466 11467Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 11468 11469A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 11470 11471> **NOTE** 11472> 11473> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9) instead. 11474 11475**System capability**: SystemCapability.WindowManager.WindowManager.Core 11476 11477**Parameters** 11478 11479| Name | Type | Mandatory| Description | 11480| ------------- | ------------------------- | ---- | -------------------- | 11481| isPrivacyMode | boolean | Yes | Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise.| 11482| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11483 11484**Example** 11485 11486```ts 11487import { BusinessError } from '@kit.BasicServicesKit'; 11488 11489let isPrivacyMode: boolean = true; 11490windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 11491 const errCode: number = err.code; 11492 if (errCode) { 11493 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 11494 return; 11495 } 11496 console.info('Succeeded in setting the window to privacy mode.'); 11497}); 11498``` 11499 11500## setPrivacyMode<sup>(deprecated)</sup> 11501 11502setPrivacyMode(isPrivacyMode: boolean): Promise<void> 11503 11504Sets whether this window is in privacy mode. This API uses a promise to return the result. 11505 11506A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 11507 11508> **NOTE** 11509> 11510> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9-1) instead. 11511 11512**System capability**: SystemCapability.WindowManager.WindowManager.Core 11513 11514**Parameters** 11515 11516| Name | Type | Mandatory| Description | 11517| ------------- | ------- | ---- | -------------------- | 11518| isPrivacyMode | boolean | Yes | Whether the window is in privacy mode. **true** if in privacy mode, **false** otherwise.| 11519 11520**Return value** 11521 11522| Type | Description | 11523| ------------------- | ------------------------- | 11524| Promise<void> | Promise that returns no value.| 11525 11526**Example** 11527 11528```ts 11529import { BusinessError } from '@kit.BasicServicesKit'; 11530 11531let isPrivacyMode: boolean = true; 11532let promise = windowClass.setPrivacyMode(isPrivacyMode); 11533promise.then(() => { 11534 console.info('Succeeded in setting the window to privacy mode.'); 11535}).catch((err: BusinessError) => { 11536 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 11537}); 11538``` 11539 11540## setTouchable<sup>(deprecated)</sup> 11541 11542setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 11543 11544Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 11545 11546> **NOTE** 11547> 11548> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9) instead. 11549 11550**System capability**: SystemCapability.WindowManager.WindowManager.Core 11551 11552**Parameters** 11553 11554| Name | Type | Mandatory| Description | 11555| ----------- | ------------------------- | ---- | -------------------- | 11556| isTouchable | boolean | Yes | Whether the window is touchable. **true** if touchable, **false** otherwise.| 11557| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 11558 11559 11560**Example** 11561 11562```ts 11563import { BusinessError } from '@kit.BasicServicesKit'; 11564 11565let isTouchable = true; 11566windowClass.setTouchable(isTouchable, (err: BusinessError) => { 11567 const errCode: number = err.code; 11568 if (errCode) { 11569 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11570 return; 11571 } 11572 console.info('Succeeded in setting the window to be touchable.'); 11573}); 11574``` 11575 11576## setTouchable<sup>(deprecated)</sup> 11577 11578setTouchable(isTouchable: boolean): Promise<void> 11579 11580Sets whether this window is touchable. This API uses a promise to return the result. 11581 11582> **NOTE** 11583> 11584> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9-1) instead. 11585 11586**System capability**: SystemCapability.WindowManager.WindowManager.Core 11587 11588**Parameters** 11589 11590| Name | Type | Mandatory| Description | 11591| ----------- | ------- | ---- | -------------------- | 11592| isTouchable | boolean | Yes | Whether the window is touchable. **true** if touchable, **false** otherwise.| 11593 11594**Return value** 11595 11596| Type | Description | 11597| ------------------- | ------------------------- | 11598| Promise<void> | Promise that returns no value.| 11599 11600 11601**Example** 11602 11603```ts 11604import { BusinessError } from '@kit.BasicServicesKit'; 11605 11606let isTouchable = true; 11607let promise = windowClass.setTouchable(isTouchable); 11608promise.then(() => { 11609 console.info('Succeeded in setting the window to be touchable.'); 11610}).catch((err: BusinessError) => { 11611 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11612}); 11613``` 11614