1e41f4b71Sopenharmony_ci# @ohos.display (屏幕属性) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci屏幕属性提供管理显示设备的一些基础能力,包括获取默认显示设备的信息,获取所有显示设备的信息以及监听显示设备的插拔行为。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## DisplayState 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci显示设备的状态枚举。 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 24e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 25e41f4b71Sopenharmony_ci| STATE_UNKNOWN | 0 | 表示显示设备状态未知。| 26e41f4b71Sopenharmony_ci| STATE_OFF | 1 | 表示显示设备状态为关闭。 | 27e41f4b71Sopenharmony_ci| STATE_ON | 2 | 表示显示设备状态为开启。| 28e41f4b71Sopenharmony_ci| STATE_DOZE | 3 | 表示显示设备为低电耗模式。| 29e41f4b71Sopenharmony_ci| STATE_DOZE_SUSPEND | 4 | 表示显示设备为睡眠模式,CPU为挂起状态。 | 30e41f4b71Sopenharmony_ci| STATE_VR | 5 | 表示显示设备为VR模式。| 31e41f4b71Sopenharmony_ci| STATE_ON_SUSPEND | 6 | 表示显示设备为开启状态,CPU为挂起状态。 | 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci## Orientation<sup>10+</sup> 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci显示设备当前显示的方向枚举。 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 42e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 43e41f4b71Sopenharmony_ci| PORTRAIT | 0 | 表示设备当前以竖屏方式显示。| 44e41f4b71Sopenharmony_ci| LANDSCAPE | 1 | 表示设备当前以横屏方式显示。 | 45e41f4b71Sopenharmony_ci| PORTRAIT_INVERTED | 2 | 表示设备当前以反向竖屏方式显示。| 46e41f4b71Sopenharmony_ci| LANDSCAPE_INVERTED | 3 | 表示设备当前以反向横屏方式显示。| 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci## FoldStatus<sup>10+</sup> 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci当前可折叠设备的折叠状态枚举。 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 58e41f4b71Sopenharmony_ci| FOLD_STATUS_UNKNOWN | 0 | 表示设备当前折叠状态未知。| 59e41f4b71Sopenharmony_ci| FOLD_STATUS_EXPANDED | 1 | 表示设备当前折叠状态为完全展开。| 60e41f4b71Sopenharmony_ci| FOLD_STATUS_FOLDED | 2 | 表示设备当前折叠状态为折叠。| 61e41f4b71Sopenharmony_ci| FOLD_STATUS_HALF_FOLDED | 3 | 表示设备当前折叠状态为半折叠。半折叠指完全展开和折叠之间的状态。| 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci## FoldDisplayMode<sup>10+</sup> 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci可折叠设备的显示模式枚举。 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 72e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 73e41f4b71Sopenharmony_ci| FOLD_DISPLAY_MODE_UNKNOWN | 0 | 表示设备当前折叠显示模式未知。| 74e41f4b71Sopenharmony_ci| FOLD_DISPLAY_MODE_FULL | 1 | 表示设备当前全屏显示。 | 75e41f4b71Sopenharmony_ci| FOLD_DISPLAY_MODE_MAIN | 2 | 表示设备当前主屏幕显示。| 76e41f4b71Sopenharmony_ci| FOLD_DISPLAY_MODE_SUB | 3 | 表示设备当前子屏幕显示。| 77e41f4b71Sopenharmony_ci| FOLD_DISPLAY_MODE_COORDINATION | 4 | 表示设备当前双屏协同显示。| 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci>**说明:**<br> 80e41f4b71Sopenharmony_ci>• 对于大屏内折产品,内屏显示状态为FOLD_DISPLAY_MODE_FULL,外屏显示状态为FOLD_DISPLAY_MODE_MAIN。<br> 81e41f4b71Sopenharmony_ci>• 对于小屏内折产品,内屏显示状态为FOLD_DISPLAY_MODE_FULL,外屏显示状态为FOLD_DISPLAY_MODE_SUB。 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci## FoldCreaseRegion<sup>10+</sup> 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci折叠折痕区域。 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 92e41f4b71Sopenharmony_ci| ------ | -------- | ---- | ---- | ------------------ | 93e41f4b71Sopenharmony_ci| displayId | number | 是 | 否 | 显示器ID,用于识别折痕所在的屏幕。 | 94e41f4b71Sopenharmony_ci| creaseRects | Array\<[Rect](#rect9)> | 是 | 否 | 折痕区域。 | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci## Rect<sup>9+</sup> 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci矩形区域。 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 105e41f4b71Sopenharmony_ci| ------ | -------- | ---- | ---- | ------------------ | 106e41f4b71Sopenharmony_ci| left | number | 是 | 是 | 矩形区域的左边界,单位为px,该参数应为整数。 | 107e41f4b71Sopenharmony_ci| top | number | 是 | 是 | 矩形区域的上边界,单位为px,该参数应为整数。 | 108e41f4b71Sopenharmony_ci| width | number | 是 | 是 | 矩形区域的宽度,单位为px,该参数应为整数。 | 109e41f4b71Sopenharmony_ci| height | number | 是 | 是 | 矩形区域的高度,单位为px,该参数应为整数。 | 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci## WaterfallDisplayAreaRects<sup>9+</sup> 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci瀑布屏曲面部分显示区域。 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 120e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | ---- | ------------------ | 121e41f4b71Sopenharmony_ci| left | [Rect](#rect9) | 是 | 否 | 瀑布曲面区域的左侧矩形区域。 | 122e41f4b71Sopenharmony_ci| top | [Rect](#rect9) | 是 | 否 | 瀑布曲面区域的顶部矩形区域。 | 123e41f4b71Sopenharmony_ci| right | [Rect](#rect9) | 是 | 否 | 瀑布曲面区域的右侧矩形区域。 | 124e41f4b71Sopenharmony_ci| bottom | [Rect](#rect9) | 是 | 否 | 瀑布曲面区域的底部矩形区域。 | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci## CutoutInfo<sup>9+</sup> 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci挖孔屏、刘海屏、瀑布屏等不可用屏幕区域信息。 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 135e41f4b71Sopenharmony_ci| --------------------------- | ------------- | ---- | ---- | ------------------ | 136e41f4b71Sopenharmony_ci| boundingRects | Array\<[Rect](#rect9)> | 是 | 否 | 挖孔、刘海等区域的边界矩形。 | 137e41f4b71Sopenharmony_ci| waterfallDisplayAreaRects | [WaterfallDisplayAreaRects](#waterfalldisplayarearects9) | 是 | 否 | 瀑布屏曲面部分显示区域。 | 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci## DisplayPhysicalResolution<sup>12+</sup> 140e41f4b71Sopenharmony_ci折叠设备的显示模式以及对应的物理屏幕分辨率信息。 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 147e41f4b71Sopenharmony_ci| --------------------------- | ------------- | ---- | ---- | ------------------ | 148e41f4b71Sopenharmony_ci| foldDisplayMode | [FoldDisplayMode](#folddisplaymode10) | 是 | 否 | 折叠设备的显示模式。 | 149e41f4b71Sopenharmony_ci| physicalWidth | number | 是 | 否 | 折叠设备的宽度,单位为px,该参数应为大于0的整数。| 150e41f4b71Sopenharmony_ci| physicalHeight | number | 是 | 否 | 折叠设备的高度,单位为px,该参数应为大于0的整数。| 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci## display.getDisplayByIdSync<sup>12+</sup> 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_cigetDisplayByIdSync(displayId: number): Display 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci根据displayId获取对应的display对象。 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**参数:** 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 165e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- |----------| 166e41f4b71Sopenharmony_ci| displayId | number | 是 | 屏幕id。该参数仅支持整数输入,该参数大于等于0。需要确保displayId准确才能成功获取到对应结果。可以通过[WindowProperties](js-apis-window.md#windowproperties)的displayId属性获取到准确的displayId作为入参。 | 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**返回值:** 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci| 类型 | 说明 | 171e41f4b71Sopenharmony_ci| ------------------------------| ----------------------------------------------| 172e41f4b71Sopenharmony_ci| [Display](#display) | 返回displayId对应的display对象。 | 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**错误码:** 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 179e41f4b71Sopenharmony_ci| ------- | ----------------------- | 180e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2. Incorrect parameter types. 3. Parameter verification failed.| 181e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**示例:** 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci```ts 186e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_citry { 191e41f4b71Sopenharmony_ci // 可以通过WindowProperties的displayId属性获取到准确的displayId作为入参 192e41f4b71Sopenharmony_ci let displayId = 0; 193e41f4b71Sopenharmony_ci displayClass = display.getDisplayByIdSync(displayId); 194e41f4b71Sopenharmony_ci} catch (exception) { 195e41f4b71Sopenharmony_ci console.error(`Failed to get display. Code: ${exception.code}, message: ${exception.message}`); 196e41f4b71Sopenharmony_ci} 197e41f4b71Sopenharmony_ci``` 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci## display.getAllDisplayPhysicalResolution<sup>12+</sup> 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_cigetAllDisplayPhysicalResolution(): Promise<Array<DisplayPhysicalResolution>> 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci获取当前折叠设备的显示模式以及对应的物理屏幕分辨率信息对象。 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**返回值:** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci| 类型 | 说明 | 212e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 213e41f4b71Sopenharmony_ci| Promise<Array<[DisplayPhysicalResolution](#displayphysicalresolution12)>> | Promise对象。返回当前所有的DisplayPhysicalResolution对象。 | 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**错误码:** 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 220e41f4b71Sopenharmony_ci| ------- | ----------------------- | 221e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**示例:** 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci```ts 226e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 227e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_cilet promise = display.getAllDisplayPhysicalResolution(); 230e41f4b71Sopenharmony_cipromise.then((resolutionObjects) => { 231e41f4b71Sopenharmony_ci console.info('Obtaining physical resolution length: ' + resolutionObjects.length); 232e41f4b71Sopenharmony_ci for (let i = 0; i < resolutionObjects.length; i++) { 233e41f4b71Sopenharmony_ci console.info(`resolutionObjects[${i}].foldDisplayMode: ${resolutionObjects[i].foldDisplayMode}`); 234e41f4b71Sopenharmony_ci console.info(`resolutionObjects[${i}].physicalWidth: ${resolutionObjects[i].physicalWidth}`); 235e41f4b71Sopenharmony_ci console.info(`resolutionObjects[${i}].physicalHeight: ${resolutionObjects[i].physicalHeight}`); 236e41f4b71Sopenharmony_ci } 237e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 238e41f4b71Sopenharmony_ci console.error(`Failed to obtain physical resolution. Code: ${err.code}, message: ${err.message}`); 239e41f4b71Sopenharmony_ci}); 240e41f4b71Sopenharmony_ci``` 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci## display.getDefaultDisplaySync<sup>9+</sup> 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_cigetDefaultDisplaySync(): Display 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci获取当前默认的display对象。 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**返回值:** 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci| 类型 | 说明 | 255e41f4b71Sopenharmony_ci| ------------------------------| ----------------------------------------------| 256e41f4b71Sopenharmony_ci| [Display](#display) | 返回默认的display对象。 | 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**错误码:** 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 263e41f4b71Sopenharmony_ci| ------- | ----------------------- | 264e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**示例:** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci```ts 269e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_cidisplayClass = display.getDefaultDisplaySync(); 274e41f4b71Sopenharmony_ci``` 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci## display.getAllDisplays<sup>9+</sup> 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_cigetAllDisplays(callback: AsyncCallback<Array<Display>>): void 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci获取当前所有的display对象,使用callback异步回调。 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci**参数:** 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 289e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | ------------------------------- | 290e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调函数。返回当前所有的display对象。 | 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**错误码:** 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 297e41f4b71Sopenharmony_ci| ------- | ----------------------- | 298e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**示例:** 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci```ts 303e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 304e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_cilet displayClass: Array<display.Display> = []; 307e41f4b71Sopenharmony_cidisplay.getAllDisplays((err: BusinessError, data: Array<display.Display>) => { 308e41f4b71Sopenharmony_ci displayClass = data; 309e41f4b71Sopenharmony_ci const errCode: number = err.code; 310e41f4b71Sopenharmony_ci if (errCode) { 311e41f4b71Sopenharmony_ci console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`); 312e41f4b71Sopenharmony_ci return; 313e41f4b71Sopenharmony_ci } 314e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); 315e41f4b71Sopenharmony_ci}); 316e41f4b71Sopenharmony_ci``` 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci## display.getAllDisplays<sup>9+</sup> 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_cigetAllDisplays(): Promise<Array<Display>> 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci获取当前所有的display对象,使用Promise异步回调。 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**返回值:** 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci| 类型 | 说明 | 331e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 332e41f4b71Sopenharmony_ci| Promise<Array<[Display](#display)>> | Promise对象。返回当前所有的display对象。 | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**错误码:** 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 339e41f4b71Sopenharmony_ci| ------- | ----------------------- | 340e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci**示例:** 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci```ts 345e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 346e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_cilet displayClass: Array<display.Display> =[]; 349e41f4b71Sopenharmony_cilet promise: Promise<Array<display.Display>> = display.getAllDisplays(); 350e41f4b71Sopenharmony_cipromise.then((data: Array<display.Display>) => { 351e41f4b71Sopenharmony_ci displayClass = data; 352e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); 353e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 354e41f4b71Sopenharmony_ci console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`); 355e41f4b71Sopenharmony_ci}); 356e41f4b71Sopenharmony_ci``` 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci## display.on('add'|'remove'|'change') 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_cion(type: 'add'|'remove'|'change', callback: Callback<number>): void 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci开启显示设备变化的监听。 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**参数:** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 371e41f4b71Sopenharmony_ci| -------- | -------- | -------- |---------------------------------------------------------------------------------------------------------------------------------| 372e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件。<br/>- type为"add",表示增加显示设备事件。例如:插入显示器。<br/>- type为"remove",表示移除显示设备事件。例如:移除显示器。<br/>- type为"change",表示改变显示设备事件。例如:显示器方向改变。 | 373e41f4b71Sopenharmony_ci| callback | Callback<number> | 是 | 回调函数。返回监听到的显示设备的id,该参数应为整数。 | 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci**错误码:** 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 380e41f4b71Sopenharmony_ci| ------- | ----------------------- | 381e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci**示例:** 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci```ts 386e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_cilet callback: Callback<number> = (data: number) => { 389e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 390e41f4b71Sopenharmony_ci}; 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_cidisplay.on("add", callback); 393e41f4b71Sopenharmony_ci``` 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci## display.off('add'|'remove'|'change') 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_cioff(type: 'add'|'remove'|'change', callback?: Callback<number>): void 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci关闭显示设备变化的监听。 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**参数:** 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 408e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 409e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件。<br/>- type为"add",表示增加显示设备事件。例如:插入显示器。<br/>- type为"remove",表示移除显示设备事件。例如:移除显示器。<br/>- type为"change",表示改变显示设备事件。例如:显示器方向改变。 | 410e41f4b71Sopenharmony_ci| callback | Callback<number> | 否 | 需要取消注册的回调函数。若无此参数,则取消注册当前type类型事件监听的所有回调函数。 | 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**错误码:** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 417e41f4b71Sopenharmony_ci| ------- | ----------------------- | 418e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**示例:** 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci```ts 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci// 如果通过on注册多个callback,同时关闭所有callback监听 425e41f4b71Sopenharmony_cidisplay.off("remove"); 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_cilet callback: Callback<number> = (data: number) => { 428e41f4b71Sopenharmony_ci console.info('Succeeded in unregistering the callback for display remove. Data: ' + JSON.stringify(data)) 429e41f4b71Sopenharmony_ci}; 430e41f4b71Sopenharmony_ci// 关闭传入的callback监听 431e41f4b71Sopenharmony_cidisplay.off('remove', callback); 432e41f4b71Sopenharmony_ci``` 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci## display.isFoldable<sup>10+</sup> 435e41f4b71Sopenharmony_ciisFoldable(): boolean 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci检查设备是否可折叠。 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci**返回值:** 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci| 类型 | 说明 | 446e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 447e41f4b71Sopenharmony_ci| boolean | boolean对象,返回当前设备是否可折叠的结果。false表示不可折叠,true表示可折叠。| 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**错误码:** 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 454e41f4b71Sopenharmony_ci| ------- | ----------------------- | 455e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**示例:** 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci```ts 460e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_cilet ret: boolean = false; 463e41f4b71Sopenharmony_ciret = display.isFoldable(); 464e41f4b71Sopenharmony_ci``` 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci## display.getFoldStatus<sup>10+</sup> 467e41f4b71Sopenharmony_cigetFoldStatus(): FoldStatus 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci获取可折叠设备的当前折叠状态。 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**返回值:** 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci| 类型 | 说明 | 478e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 479e41f4b71Sopenharmony_ci| [FoldStatus](#foldstatus10) | FoldStatus对象,返回当前可折叠设备的折叠状态。 | 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**错误码:** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 486e41f4b71Sopenharmony_ci| ------- | ----------------------- | 487e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci**示例:** 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci```ts 492e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_cilet data: display.FoldStatus = display.getFoldStatus(); 495e41f4b71Sopenharmony_ciconsole.info('Succeeded in obtaining fold status. Data: ' + JSON.stringify(data)); 496e41f4b71Sopenharmony_ci``` 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci## display.getFoldDisplayMode<sup>10+</sup> 499e41f4b71Sopenharmony_cigetFoldDisplayMode(): FoldDisplayMode 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci获取可折叠设备的显示模式。 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**返回值:** 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci| 类型 | 说明 | 510e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 511e41f4b71Sopenharmony_ci| [FoldDisplayMode](#folddisplaymode10) | FoldDisplayMode对象,返回当前可折叠设备的显示模式。 | 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci**错误码:** 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 518e41f4b71Sopenharmony_ci| ------- | ----------------------- | 519e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci**示例:** 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci```ts 524e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_cilet data: display.FoldDisplayMode = display.getFoldDisplayMode(); 527e41f4b71Sopenharmony_ciconsole.info('Succeeded in obtaining fold display mode. Data: ' + JSON.stringify(data)); 528e41f4b71Sopenharmony_ci``` 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci## display.getCurrentFoldCreaseRegion<sup>10+</sup> 531e41f4b71Sopenharmony_cigetCurrentFoldCreaseRegion(): FoldCreaseRegion 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci在当前显示模式下获取折叠折痕区域。 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**返回值:** 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci| 类型 | 说明 | 542e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 543e41f4b71Sopenharmony_ci| [FoldCreaseRegion](#foldcreaseregion10) | FoldCreaseRegion对象,返回设备在当前显示模式下的折叠折痕区域。 | 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci**错误码:** 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 550e41f4b71Sopenharmony_ci| ------- | ----------------------- | 551e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci**示例:** 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci```ts 556e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_cilet data: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion(); 559e41f4b71Sopenharmony_ciconsole.info('Succeeded in obtaining current fold crease region. Data: ' + JSON.stringify(data)); 560e41f4b71Sopenharmony_ci``` 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci## display.on('foldStatusChange')<sup>10+</sup> 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_cion(type: 'foldStatusChange', callback: Callback<FoldStatus>): void 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci开启折叠设备折叠状态变化的监听。 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci本接口监听设备物理折叠状态的变化,[display.on('foldDispla 569e41f4b71Sopenharmony_ciyModeChange')](#displayonfolddisplaymodechange10)则监听屏幕显示模式的变化。 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci两者存在差异,时序上物理折叠状态变化在前,底层会根据物理折叠状态匹配屏幕显示模式状态。 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci若需监听当前显示内容是显示在折叠设备的内屏还是外屏,请使用[display.on('foldDisplayModeChange')](#displayonfolddisplaymodechange10)。 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci**参数:** 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 582e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 583e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldStatusChange',表示折叠设备折叠状态发生变化。 | 584e41f4b71Sopenharmony_ci| callback | Callback<[FoldStatus](#foldstatus10)> | 是 | 回调函数。表示折叠设备折叠状态。 | 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**错误码:** 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 591e41f4b71Sopenharmony_ci| ------- | ----------------------- | 592e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 593e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci**示例:** 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci```ts 598e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci/** 601e41f4b71Sopenharmony_ci * 注册监听的callback参数要采用对象传递. 602e41f4b71Sopenharmony_ci * 若使用匿名函数注册,每次调用会创建一个新的底层对象,引起内存泄漏问题。 603e41f4b71Sopenharmony_ci*/ 604e41f4b71Sopenharmony_cilet callback: Callback<display.FoldStatus> = (data: display.FoldStatus) => { 605e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 606e41f4b71Sopenharmony_ci}; 607e41f4b71Sopenharmony_cidisplay.on('foldStatusChange', callback); 608e41f4b71Sopenharmony_ci``` 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci## display.off('foldStatusChange')<sup>10+</sup> 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_cioff(type: 'foldStatusChange', callback?: Callback<FoldStatus>): void 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci关闭折叠设备折叠状态变化的监听。 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**参数:** 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 623e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 624e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldStatusChange',表示折叠设备折叠状态发生变化。 | 625e41f4b71Sopenharmony_ci| callback | Callback<[FoldStatus](#foldstatus10)> | 否 | 需要取消注册的回调函数。若无此参数,则取消注册折叠状态变化监听的所有回调函数。 | 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci**错误码:** 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 632e41f4b71Sopenharmony_ci| ------- | ----------------------- | 633e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 634e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci**示例:** 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci```ts 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci// 如果通过on注册多个callback,同时关闭所有callback监听 641e41f4b71Sopenharmony_cidisplay.off('foldStatusChange'); 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_cilet callback: Callback<display.FoldStatus> = (data: display.FoldStatus) => { 644e41f4b71Sopenharmony_ci console.info('unregistering FoldStatus changes callback. Data: ' + JSON.stringify(data)); 645e41f4b71Sopenharmony_ci}; 646e41f4b71Sopenharmony_ci// 关闭传入的callback监听 647e41f4b71Sopenharmony_cidisplay.off('foldStatusChange', callback); 648e41f4b71Sopenharmony_ci``` 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci## display.on('foldAngleChange')<sup>12+</sup> 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_cion(type: 'foldAngleChange', callback: Callback<Array<number>>): void 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci开启折叠设备折叠角度变化的监听。 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**参数:** 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 663e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 664e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldAngleChange',表示折叠设备折叠角度发生变化。| 665e41f4b71Sopenharmony_ci| callback | Callback<Array<number>> | 是 | 回调函数。表示折叠设备屏幕折叠角度值(0度~180度)。| 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**错误码:** 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 672e41f4b71Sopenharmony_ci| ------- | ----------------------- | 673e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 674e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci**示例:** 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci```ts 679e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_cilet callback: Callback<Array<number>> = (angles: Array<number>) => { 682e41f4b71Sopenharmony_ci console.info('Listening fold angles length: ' + angles.length); 683e41f4b71Sopenharmony_ci}; 684e41f4b71Sopenharmony_cidisplay.on('foldAngleChange', callback); 685e41f4b71Sopenharmony_ci``` 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci## display.off('foldAngleChange')<sup>12+</sup> 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_cioff(type: 'foldAngleChange', callback?: Callback<Array<number>>): void 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci关闭折叠设备折叠角度变化的监听。 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci**参数:** 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 700e41f4b71Sopenharmony_ci| -------- |-------------------------------------------| ---- | ------------------------------------------------------- | 701e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldAngleChange'表示折叠设备折叠角度发生变化。| 702e41f4b71Sopenharmony_ci| callback | Callback<Array<number>> | 否 | 需要取消注册的回调函数。若无此参数,则取消注册折叠角度变化监听的所有回调函数。| 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**错误码:** 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 709e41f4b71Sopenharmony_ci| ------- | ----------------------- | 710e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 711e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**示例:** 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci```ts 716e41f4b71Sopenharmony_cidisplay.off('foldAngleChange'); 717e41f4b71Sopenharmony_ci``` 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci## display.on('captureStatusChange')<sup>12+</sup> 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_cion(type: 'captureStatusChange', callback: Callback<boolean>): void 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci开启屏幕截屏、投屏、录屏状态变化的监听。 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci**参数:** 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 732e41f4b71Sopenharmony_ci| -------- |-------------------------------------------| ---- | ------------------------------------------------------- | 733e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'captureStatusChange'表示设备截屏、投屏或者录屏状态发生变化。| 734e41f4b71Sopenharmony_ci| callback | Callback<boolean> | 是 | 回调函数。表示设备截屏、投屏、录屏状态发生变化。true表示设备开始截屏、投屏或者录屏,false表示结束截屏、投屏、录屏。| 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci**错误码:** 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 741e41f4b71Sopenharmony_ci| ------- | ----------------------- | 742e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 743e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**示例:** 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci```ts 748e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_cilet callback: Callback<boolean> = (captureStatus: boolean) => { 751e41f4b71Sopenharmony_ci console.info('Listening capture status: ' + captureStatus); 752e41f4b71Sopenharmony_ci}; 753e41f4b71Sopenharmony_cidisplay.on('captureStatusChange', callback); 754e41f4b71Sopenharmony_ci``` 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ci## display.off('captureStatusChange')<sup>12+</sup> 757e41f4b71Sopenharmony_ci 758e41f4b71Sopenharmony_cioff(type: 'captureStatusChange', callback?: Callback<boolean>): void 759e41f4b71Sopenharmony_ci 760e41f4b71Sopenharmony_ci关闭屏幕截屏、投屏、录屏状态变化的监听。 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 765e41f4b71Sopenharmony_ci 766e41f4b71Sopenharmony_ci**参数:** 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 769e41f4b71Sopenharmony_ci| -------- |-------------------------------------------| ---- | ------------------------------------------------------- | 770e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'captureStatusChange'表示设备截屏、投屏、录屏状态发生变化。| 771e41f4b71Sopenharmony_ci| callback | Callback<boolean> | 否 | 需要取消注册的回调函数。若无此参数,则取消注册截屏、投屏、录屏状态变化监听的所有回调函数。| 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci**错误码:** 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 778e41f4b71Sopenharmony_ci| ------- | ----------------------- | 779e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 780e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci**示例:** 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci```ts 785e41f4b71Sopenharmony_cidisplay.off('captureStatusChange'); 786e41f4b71Sopenharmony_ci``` 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci## display.isCaptured<sup>12+</sup> 789e41f4b71Sopenharmony_ciisCaptured(): boolean 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci检查设备是否正在截屏、投屏、录屏。 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci**返回值:** 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci| 类型 | 说明 | 800e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 801e41f4b71Sopenharmony_ci| boolean | boolean值,返回当前设备是否有截屏、投屏或者录屏。true表示有截屏、投屏、录屏,否则返回false。| 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci**错误码:** 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 808e41f4b71Sopenharmony_ci| ------- | ----------------------- | 809e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci**示例:** 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci```ts 814e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_cilet ret: boolean = false; 817e41f4b71Sopenharmony_ciret = display.isCaptured(); 818e41f4b71Sopenharmony_ci``` 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci## display.on('foldDisplayModeChange')<sup>10+</sup> 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_cion(type: 'foldDisplayModeChange', callback: Callback<FoldDisplayMode>): void 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci开启折叠设备屏幕显示模式变化的监听。 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ci本接口监听设备屏幕显示模式的变化,[display.on('foldStatusChange')](#displayonfoldstatuschange10)则监听设备物理折叠状态的变化。 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci两者存在差异,时序上物理折叠状态变化在前,底层会根据物理折叠状态匹配屏幕显示模式状态。 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci**参数:** 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 837e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 838e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldDisplayModeChange',表示折叠设备屏幕显示模式发生变化。 | 839e41f4b71Sopenharmony_ci| callback | Callback<[FoldDisplayMode](#folddisplaymode10)> | 是 | 回调函数。表示折叠设备屏幕显示模式。 | 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**错误码:** 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 846e41f4b71Sopenharmony_ci| ------- | ----------------------- | 847e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 848e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci**示例:** 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci```ts 853e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci/** 856e41f4b71Sopenharmony_ci * 注册监听的callback参数要采用对象传递. 857e41f4b71Sopenharmony_ci * 若使用匿名函数注册,每次调用会创建一个新的底层对象,引起内存泄漏问题。 858e41f4b71Sopenharmony_ci*/ 859e41f4b71Sopenharmony_cilet callback: Callback<display.FoldDisplayMode> = (data: display.FoldDisplayMode) => { 860e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 861e41f4b71Sopenharmony_ci}; 862e41f4b71Sopenharmony_cidisplay.on('foldDisplayModeChange', callback); 863e41f4b71Sopenharmony_ci``` 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_ci## display.off('foldDisplayModeChange')<sup>10+</sup> 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_cioff(type: 'foldDisplayModeChange', callback?: Callback<FoldDisplayMode>): void 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci关闭折叠设备屏幕显示模式变化的监听。 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**参数:** 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 878e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 879e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'foldDisplayModeChange',表示折叠设备屏幕显示模式发生变化。 | 880e41f4b71Sopenharmony_ci| callback | Callback<[FoldDisplayMode](#folddisplaymode10)> | 否 | 需要取消注册的回调函数。若无此参数,则取消注册屏幕显示模式变化监听的所有回调函数。 | 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci**错误码:** 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 887e41f4b71Sopenharmony_ci| ------- | ----------------------- | 888e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 889e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**示例:** 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci```ts 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci// 如果通过on注册多个callback,同时关闭所有callback监听 896e41f4b71Sopenharmony_cidisplay.off('foldDisplayModeChange'); 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_cilet callback: Callback<display.FoldDisplayMode> = (data: display.FoldDisplayMode) => { 899e41f4b71Sopenharmony_ci console.info('unregistering FoldDisplayMode changes callback. Data: ' + JSON.stringify(data)); 900e41f4b71Sopenharmony_ci}; 901e41f4b71Sopenharmony_ci// 关闭传入的callback监听 902e41f4b71Sopenharmony_cidisplay.off('foldDisplayModeChange', callback); 903e41f4b71Sopenharmony_ci``` 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ci## display.getDefaultDisplay<sup>(deprecated)</sup> 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_cigetDefaultDisplay(callback: AsyncCallback<Display>): void 909e41f4b71Sopenharmony_ci 910e41f4b71Sopenharmony_ci获取当前默认的display对象,使用callback异步回调。 911e41f4b71Sopenharmony_ci 912e41f4b71Sopenharmony_ci> **说明:** 913e41f4b71Sopenharmony_ci> 914e41f4b71Sopenharmony_ci> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci**参数:** 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 921e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 922e41f4b71Sopenharmony_ci| callback | AsyncCallback<[Display](#display)> | 是 | 回调函数。返回当前默认的display对象。 | 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci**示例:** 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_ci```ts 927e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 928e41f4b71Sopenharmony_ci 929e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 930e41f4b71Sopenharmony_cidisplay.getDefaultDisplay((err: BusinessError, data: display.Display) => { 931e41f4b71Sopenharmony_ci const errCode: number = err.code; 932e41f4b71Sopenharmony_ci if (errCode) { 933e41f4b71Sopenharmony_ci console.error(`Failed to obtain the default display object. Code: ${err.code}, message: ${err.message}`); 934e41f4b71Sopenharmony_ci return; 935e41f4b71Sopenharmony_ci } 936e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); 937e41f4b71Sopenharmony_ci displayClass = data; 938e41f4b71Sopenharmony_ci}); 939e41f4b71Sopenharmony_ci``` 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci## display.getDefaultDisplay<sup>(deprecated)</sup> 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_cigetDefaultDisplay(): Promise<Display> 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci获取当前默认的display对象,使用Promise异步回调。 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci> **说明:** 948e41f4b71Sopenharmony_ci> 949e41f4b71Sopenharmony_ci> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci**返回值:** 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ci| 类型 | 说明 | 956e41f4b71Sopenharmony_ci| ---------------------------------- | ---------------------------------------------- | 957e41f4b71Sopenharmony_ci| Promise<[Display](#display)> | Promise对象。返回当前默认的display对象。 | 958e41f4b71Sopenharmony_ci 959e41f4b71Sopenharmony_ci**示例:** 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ci```ts 962e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 965e41f4b71Sopenharmony_cilet promise: Promise<display.Display> = display.getDefaultDisplay(); 966e41f4b71Sopenharmony_cipromise.then((data: display.Display) => { 967e41f4b71Sopenharmony_ci displayClass = data; 968e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); 969e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 970e41f4b71Sopenharmony_ci console.error(`Failed to obtain the default display object. Code: ${err.code}, message: ${err.message}`); 971e41f4b71Sopenharmony_ci}); 972e41f4b71Sopenharmony_ci``` 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ci## display.getAllDisplay<sup>(deprecated)</sup> 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_cigetAllDisplay(callback: AsyncCallback<Array<Display>>): void 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci获取当前所有的display对象,使用callback异步回调。 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci> **说明:** 981e41f4b71Sopenharmony_ci> 982e41f4b71Sopenharmony_ci> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9)。 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci**参数:** 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 989e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | ------------------------------- | 990e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调函数。返回当前所有的display对象。 | 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ci**示例:** 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ci```ts 995e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_cidisplay.getAllDisplay((err: BusinessError, data: Array<display.Display>) => { 998e41f4b71Sopenharmony_ci const errCode: number = err.code; 999e41f4b71Sopenharmony_ci if (errCode) { 1000e41f4b71Sopenharmony_ci console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`); 1001e41f4b71Sopenharmony_ci return; 1002e41f4b71Sopenharmony_ci } 1003e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); 1004e41f4b71Sopenharmony_ci}); 1005e41f4b71Sopenharmony_ci``` 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci## display.getAllDisplay<sup>(deprecated)</sup> 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_cigetAllDisplay(): Promise<Array<Display>> 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci获取当前所有的display对象,使用Promise异步回调。 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci> **说明:** 1014e41f4b71Sopenharmony_ci> 1015e41f4b71Sopenharmony_ci> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9-1)。 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci**返回值:** 1020e41f4b71Sopenharmony_ci 1021e41f4b71Sopenharmony_ci| 类型 | 说明 | 1022e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------- | 1023e41f4b71Sopenharmony_ci| Promise<Array<[Display](#display)>> | Promise对象。返回当前所有的display对象。 | 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci**示例:** 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ci```ts 1028e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_cilet promise: Promise<Array<display.Display>> = display.getAllDisplay(); 1031e41f4b71Sopenharmony_cipromise.then((data: Array<display.Display>) => { 1032e41f4b71Sopenharmony_ci console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)); 1033e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1034e41f4b71Sopenharmony_ci console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`); 1035e41f4b71Sopenharmony_ci}); 1036e41f4b71Sopenharmony_ci``` 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci## Display 1039e41f4b71Sopenharmony_ci屏幕实例。描述display对象的属性和方法。 1040e41f4b71Sopenharmony_ci 1041e41f4b71Sopenharmony_ci下列API示例中都需先使用[getAllDisplays()](#displaygetalldisplays9)、[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)中的任一方法获取到Display实例,再通过此实例调用对应方法。 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci### 属性 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 1048e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |---------------------------------------------------------------------------------------------------------------| 1049e41f4b71Sopenharmony_ci| id | number | 是 | 否 | 显示设备的id号,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1050e41f4b71Sopenharmony_ci| name | string | 是 | 否 | 显示设备的名称。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1051e41f4b71Sopenharmony_ci| alive | boolean | 是 | 否 | 显示设备是否启用。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1052e41f4b71Sopenharmony_ci| state | [DisplayState](#displaystate) | 是 | 否 | 显示设备的状态。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1053e41f4b71Sopenharmony_ci| refreshRate | number | 是 | 否 | 显示设备的刷新率,该参数应为整数,单位为hz。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1054e41f4b71Sopenharmony_ci| rotation | number | 是 | 否 | 显示设备的屏幕顺时针旋转角度。<br>值为0时,表示显示设备屏幕顺时针旋转为0°;<br>值为1时,表示显示设备屏幕顺时针旋转为90°;<br>值为2时,表示显示设备屏幕顺时针旋转为180°;<br>值为3时,表示显示设备屏幕顺时针旋转为270°。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1055e41f4b71Sopenharmony_ci| width | number | 是 | 否 | 显示设备的屏幕宽度,单位为px,该参数应为整数。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1056e41f4b71Sopenharmony_ci| height | number | 是 | 否 | 显示设备的屏幕高度,单位为px,该参数应为整数。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1057e41f4b71Sopenharmony_ci| densityDPI | number | 是 | 否 | 显示设备屏幕的物理像素密度,表示每英寸上的像素点数。该参数为浮点数,单位为px。一般取值160.0、480.0等,实际能取到的值取决于不同设备设置里提供的可选值。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1058e41f4b71Sopenharmony_ci| orientation<sup>10+</sup> | [Orientation](#orientation10) | 是 | 否 | 表示屏幕当前显示的方向。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1059e41f4b71Sopenharmony_ci| densityPixels | number | 是 | 否 | 显示设备逻辑像素的密度,代表物理像素与逻辑像素的缩放系数,计算方式为:<br>该参数为浮点数,受densityDPI范围限制,取值范围在[0.5,4.0]。一般取值1.0、3.0等,实际取值取决于不同设备提供的densityDPI。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1060e41f4b71Sopenharmony_ci| scaledDensity | number | 是 | 否 | 显示设备的显示字体的缩放因子。该参数为浮点数,通常与densityPixels相同。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1061e41f4b71Sopenharmony_ci| xDPI | number | 是 | 否 | x方向中每英寸屏幕的确切物理像素值,该参数为浮点数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1062e41f4b71Sopenharmony_ci| yDPI | number | 是 | 否 | y方向中每英寸屏幕的确切物理像素值,该参数为浮点数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1063e41f4b71Sopenharmony_ci| colorSpaces<sup>11+</sup> | Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md)> | 是 | 否 | 显示设备支持的所有色域类型。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1064e41f4b71Sopenharmony_ci| hdrFormats<sup>11+</sup> | Array<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md)> | 是 | 否 | 显示设备支持的所有HDR格式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1065e41f4b71Sopenharmony_ci| availableWidth<sup>12+</sup> | number | 是 | 否 | 2in1设备上屏幕的可用区域宽度,单位为px,该参数为大于0的整数。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1066e41f4b71Sopenharmony_ci| availableHeight<sup>12+</sup> | number | 是 | 否 | 2in1设备上屏幕的可用区域高度,单位为px,该参数为大于0的整数。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci### getCutoutInfo<sup>9+</sup> 1069e41f4b71Sopenharmony_cigetCutoutInfo(callback: AsyncCallback<CutoutInfo>): void 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ci获取挖孔屏、刘海屏、瀑布屏等不可用屏幕区域信息。使用callback异步回调。建议应用布局规避该区域。 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**参数:** 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1080e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------------------------------------------ | 1081e41f4b71Sopenharmony_ci| callback | AsyncCallback<[CutoutInfo](#cutoutinfo9)> | 是 | 回调函数。返回描述不可用屏幕区域的CutoutInfo对象。 | 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**错误码:** 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1088e41f4b71Sopenharmony_ci| ------- | ----------------------- | 1089e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_ci**示例:** 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ci```ts 1094e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 1097e41f4b71Sopenharmony_cidisplayClass = display.getDefaultDisplaySync(); 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_cidisplayClass.getCutoutInfo((err: BusinessError, data: display.CutoutInfo) => { 1100e41f4b71Sopenharmony_ci const errCode: number = err.code; 1101e41f4b71Sopenharmony_ci if (errCode) { 1102e41f4b71Sopenharmony_ci console.error(`Failed to get cutoutInfo. Code: ${err.code}, message: ${err.message}`); 1103e41f4b71Sopenharmony_ci return; 1104e41f4b71Sopenharmony_ci } 1105e41f4b71Sopenharmony_ci console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data)); 1106e41f4b71Sopenharmony_ci}); 1107e41f4b71Sopenharmony_ci``` 1108e41f4b71Sopenharmony_ci### getCutoutInfo<sup>9+</sup> 1109e41f4b71Sopenharmony_cigetCutoutInfo(): Promise<CutoutInfo> 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci获取挖孔屏、刘海屏、瀑布屏等不可用屏幕区域信息。使用Promise异步回调。建议应用布局规避该区域。 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci**返回值:** 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci| 类型 | 说明 | 1120e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1121e41f4b71Sopenharmony_ci| Promise<[CutoutInfo](#cutoutinfo9)> | Promise对象。返回描述不可用屏幕区域的CutoutInfo对象。 | 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci**错误码:** 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[屏幕错误码](errorcode-display.md)。 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1128e41f4b71Sopenharmony_ci| ------- | ----------------------- | 1129e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci**示例:** 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci```ts 1134e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 1137e41f4b71Sopenharmony_cidisplayClass = display.getDefaultDisplaySync(); 1138e41f4b71Sopenharmony_cilet promise: Promise<display.CutoutInfo> = displayClass.getCutoutInfo(); 1139e41f4b71Sopenharmony_cipromise.then((data: display.CutoutInfo) => { 1140e41f4b71Sopenharmony_ci console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data)); 1141e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1142e41f4b71Sopenharmony_ci console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`); 1143e41f4b71Sopenharmony_ci}); 1144e41f4b71Sopenharmony_ci``` 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ci### getAvailableArea<sup>12+</sup> 1147e41f4b71Sopenharmony_cigetAvailableArea(): Promise<Rect> 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci获取当前2in1设备屏幕的可用区域,使用Promise异步回调。 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci**返回值:** 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci| 类型 | 说明 | 1158e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1159e41f4b71Sopenharmony_ci| Promise<[Rect](#rect9)> | Promise对象。返回当前屏幕可用矩形区域。 | 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci**错误码:** 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1166e41f4b71Sopenharmony_ci| ------- | ----------------------- | 1167e41f4b71Sopenharmony_ci| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1168e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 1169e41f4b71Sopenharmony_ci 1170e41f4b71Sopenharmony_ci**示例:** 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci```ts 1173e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1174e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 1177e41f4b71Sopenharmony_citry { 1178e41f4b71Sopenharmony_ci displayClass = display.getDefaultDisplaySync(); 1179e41f4b71Sopenharmony_ci let promise = displayClass.getAvailableArea(); 1180e41f4b71Sopenharmony_ci promise.then((data) => { 1181e41f4b71Sopenharmony_ci console.info('Succeeded get the available area in this display. data: ' + JSON.stringify(data)); 1182e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1183e41f4b71Sopenharmony_ci console.error(`Failed to get the available area in this display. Code: ${err.code}, message: ${err.message}`); 1184e41f4b71Sopenharmony_ci }) 1185e41f4b71Sopenharmony_ci} catch (exception) { 1186e41f4b71Sopenharmony_ci console.error(`Failed to obtain the default display object. Code: ${exception.code}, message: ${exception.message}`); 1187e41f4b71Sopenharmony_ci} 1188e41f4b71Sopenharmony_ci``` 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci### on('availableAreaChange')<sup>12+</sup> 1191e41f4b71Sopenharmony_cion(type: 'availableAreaChange', callback: Callback<Rect>): void 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ci开启当前2in1设备屏幕的可用区域监听。当前2in1设备屏幕有可用区域变化时,触发回调函数,返回可用区域。 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci**参数:** 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1202e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 1203e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'availableAreaChange',表示屏幕可用区域变更。 | 1204e41f4b71Sopenharmony_ci| callback | Callback<[Rect](#rect9)> | 是 | 回调函数,返回改变后的可用区域。 | 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci**错误码:** 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1211e41f4b71Sopenharmony_ci| ------- | ----------------------- | 1212e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 1213e41f4b71Sopenharmony_ci| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1214e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 1215e41f4b71Sopenharmony_ci 1216e41f4b71Sopenharmony_ci**示例:** 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci```ts 1219e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 1220e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_cilet callback: Callback<display.Rect> = (data: display.Rect) => { 1223e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 1224e41f4b71Sopenharmony_ci}; 1225e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 1226e41f4b71Sopenharmony_citry { 1227e41f4b71Sopenharmony_ci displayClass = display.getDefaultDisplaySync(); 1228e41f4b71Sopenharmony_ci displayClass.on("availableAreaChange", callback); 1229e41f4b71Sopenharmony_ci} catch (exception) { 1230e41f4b71Sopenharmony_ci console.error(`Failed to register callback. Code: ${exception.code}, message: ${exception.message}`); 1231e41f4b71Sopenharmony_ci} 1232e41f4b71Sopenharmony_ci``` 1233e41f4b71Sopenharmony_ci 1234e41f4b71Sopenharmony_ci### off('availableAreaChange')<sup>12+</sup> 1235e41f4b71Sopenharmony_ci 1236e41f4b71Sopenharmony_cioff(type: 'availableAreaChange', callback?: Callback<Rect>): void 1237e41f4b71Sopenharmony_ci 1238e41f4b71Sopenharmony_ci关闭当前2in1设备屏幕可用区域变化的监听。 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Window.SessionManager 1243e41f4b71Sopenharmony_ci 1244e41f4b71Sopenharmony_ci**参数:** 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1247e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 1248e41f4b71Sopenharmony_ci| type | string | 是 | 监听事件,固定为'availableAreaChange',表示屏幕可用区域变更。 | 1249e41f4b71Sopenharmony_ci| callback | Callback<[Rect](#rect9)> | 否 | 回调函数,已经注册的回调函数,不填默认删除所有回调 | 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci**错误码:** 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1256e41f4b71Sopenharmony_ci| ------- | ----------------------- | 1257e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 1258e41f4b71Sopenharmony_ci| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1259e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci**示例:** 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ci```ts 1264e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 1265e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_cilet callback: Callback<display.Rect> = (data: display.Rect) => { 1268e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 1269e41f4b71Sopenharmony_ci}; 1270e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 1271e41f4b71Sopenharmony_citry { 1272e41f4b71Sopenharmony_ci displayClass = display.getDefaultDisplaySync(); 1273e41f4b71Sopenharmony_ci displayClass.off("availableAreaChange", callback); 1274e41f4b71Sopenharmony_ci} catch (exception) { 1275e41f4b71Sopenharmony_ci console.error(`Failed to unregister callback. Code: ${exception.code}, message: ${exception.message}`); 1276e41f4b71Sopenharmony_ci} 1277e41f4b71Sopenharmony_ci```