1# @ohos.display (屏幕属性)(系统接口)
2
3屏幕属性提供管理显示设备的一些基础能力,包括获取默认显示设备的信息,获取所有显示设备的信息以及监听显示设备的插拔行为。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohso.display (屏幕属性)](js-apis-display.md)。
10
11## 导入模块
12
13```ts
14import { display } from '@kit.ArkUI';
15```
16
17## display.hasPrivateWindow<sup>9+</sup>
18
19hasPrivateWindow(displayId: number): boolean
20
21查询指定display对象上是否有可见的隐私窗口。可通过[setWindowPrivacyMode()](js-apis-window.md#setwindowprivacymode9)接口设置隐私窗口。隐私窗口内容将无法被截屏或录屏。
22
23**系统接口:** 此接口为系统接口。
24
25**系统能力:** SystemCapability.WindowManager.WindowManager.Core
26
27**参数:**
28
29| 参数名 | 类型                      | 必填 | 说明       |
30| ------ | ------------------------- | ---- |----------|
31| id     | number                    | 是   | 显示设备的id,该参数仅支持整数输入。该参数大于等于0。 |
32
33**返回值:**
34
35| 类型                             | 说明                                                                    |
36| -------------------------------- |-----------------------------------------------------------------------|
37|boolean | 查询的display对象上是否有可见的隐私窗口。<br>true表示此display对象上有可见的隐私窗口,false表示此display对象上没有可见的隐私窗口。</br> |
38
39**错误码:**
40
41以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
42
43| 错误码ID | 错误信息 |
44| ------- | -------------------------------------------- |
45| 202     | Permission verification failed. A non-system application calls a system API.|
46| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
47| 1400003 | This display manager service works abnormally. |
48
49**示例:**
50
51```ts
52import { display } from '@kit.ArkUI';
53
54let displayClass: display.Display | null = null;
55try {
56  displayClass = display.getDefaultDisplaySync();
57
58  let ret: boolean = true;
59  try {
60    ret = display.hasPrivateWindow(displayClass.id);
61  } catch (exception) {
62    console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception));
63  }
64  if (ret == undefined) {
65    console.log("Failed to check has privateWindow or not.");
66  }
67  if (ret) {
68    console.log("There has privateWindow.");
69  } else if (!ret) {
70    console.log("There has no privateWindow.");
71  }
72} catch (exception) {
73  console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
74}
75```
76
77## display.on('privateModeChange')<sup>10+</sup>
78
79on(type: 'privateModeChange', callback: Callback&lt;boolean&gt;): void
80
81开启屏幕隐私模式变化的监听。当屏幕前台有隐私窗口,则屏幕处于隐私模式,屏幕中的隐私窗口内容无法被截屏或录屏。
82
83**系统接口:** 此接口为系统接口。
84
85**系统能力:** SystemCapability.WindowManager.WindowManager.Core
86
87**参数:**
88
89| 参数名   | 类型                                       | 必填 | 说明                                                    |
90| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
91| type     | string                                   | 是   | 监听事件,固定为'privateModeChange',表示屏幕隐私模式状态发生变化。 |
92| callback | Callback&lt;boolean&gt; | 是   | 回调函数。表示屏幕隐私模式是否改变。true表示屏幕由非隐私窗口模式变为隐私模式,false表示屏幕由隐私模式变为非隐私模式。 |
93
94**错误码:**
95
96以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
97
98| 错误码ID | 错误信息 |
99| ------- | ----------------------- |
100| 202     | Permission verification failed. A non-system application calls a system API.|
101| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
102
103**示例:**
104
105```ts
106import { Callback } from '@kit.BasicServicesKit';
107
108let callback: Callback<boolean> = (data: boolean) => {
109  console.info('Listening enabled. Data: ' + JSON.stringify(data));
110};
111try {
112  display.on("privateModeChange", callback);
113} catch (exception) {
114  console.error('Failed to register callback. Code: ' + JSON.stringify(exception));
115}
116```
117
118## display.off('privateModeChange')<sup>10+</sup>
119
120off(type: 'privateModeChange', callback?: Callback&lt;boolean&gt;): void
121
122关闭屏幕隐私模式变化的监听。当屏幕前台有隐私窗口,则屏幕处于隐私模式,屏幕中的隐私窗口内容无法被截屏或录屏。
123
124**系统接口:** 此接口为系统接口。
125
126**系统能力:** SystemCapability.WindowManager.WindowManager.Core
127
128**参数:**
129
130| 参数名   | 类型                                       | 必填 | 说明                                                    |
131| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
132| type     | string                                   | 是   | 监听事件,固定为'privateModeChange',表示屏幕隐私模式状态发生变化。 |
133| callback | Callback&lt;boolean&gt; | 否   | 回调函数。表示屏幕隐私模式是否改变。true表示屏幕由非隐私模式变为隐私模式,false表示屏幕由隐私模式变为非隐私模式。 |
134
135**错误码:**
136
137以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
138
139| 错误码ID | 错误信息 |
140| ------- | ----------------------- |
141| 202     | Permission verification failed. A non-system application calls a system API.|
142| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
143
144**示例:**
145
146```ts
147try {
148  display.off("privateModeChange");
149} catch (exception) {
150  console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception));
151}
152```
153
154## display.setFoldDisplayMode<sup>10+</sup>
155setFoldDisplayMode(mode: FoldDisplayMode): void
156
157更改可折叠设备的显示模式。
158
159**系统接口:** 此接口为系统接口。
160
161**系统能力:** SystemCapability.Window.SessionManager
162
163**参数:**
164
165| 参数名   | 类型                                       | 必填 | 说明                                                    |
166| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
167| mode     | [FoldDisplayMode](js-apis-display.md#folddisplaymode10)    | 是   | 可折叠设备的显示模式。 |
168
169**错误码:**
170
171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
172
173| 错误码ID | 错误信息 |
174| ------- | ----------------------- |
175| 202     | Permission verification failed. A non-system application calls a system API.|
176| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
177| 1400003 | This display manager service works abnormally. |
178
179**示例:**
180
181```ts
182import { display } from '@kit.ArkUI';
183
184try {
185  let mode: display.FoldDisplayMode = display.FoldDisplayMode.FOLD_DISPLAY_MODE_FULL;
186  display.setFoldDisplayMode(mode);
187} catch (exception) {
188  console.error('Failed to change the fold display mode. Code: ' + JSON.stringify(exception));
189}
190```
191
192## display.setFoldStatusLocked<sup>11+</sup>
193setFoldStatusLocked(locked: boolean): void
194
195设置可折叠设备当前折叠状态的锁定状态。
196
197**系统接口:** 此接口为系统接口。
198
199**系统能力:** SystemCapability.Window.SessionManager
200
201**参数:**
202
203| 参数名   | 类型                                       | 必填 | 说明                                                    |
204| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
205| locked     | boolean    | 是   | 可折叠设备的折叠状态是否锁定。true表示锁定,false表示不锁定。 |
206
207**错误码:**
208
209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
210
211| 错误码ID | 错误信息 |
212| ------- | ----------------------- |
213| 202     | Permission verification failed. A non-system application calls a system API.|
214| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
215| 1400003 | This display manager service works abnormally. |
216
217**示例:**
218
219```ts
220import { display } from '@kit.ArkUI';
221
222try {
223  let locked: boolean = false;
224  display.setFoldStatusLocked(locked);
225} catch (exception) {
226  console.error('Failed to change the fold status locked mode. Code: ' + JSON.stringify(exception));
227}
228```
229
230## Display
231屏幕实例。描述display对象的属性和方法。
232
233下列API示例中都需先使用[getAllDisplays()](js-apis-display.md#displaygetalldisplays9)、[getDefaultDisplaySync()](js-apis-display.md#displaygetdefaultdisplaysync9)中的任一方法获取到Display实例,再通过此实例调用对应方法。
234
235### hasImmersiveWindow<sup>11+</sup>
236hasImmersiveWindow(callback: AsyncCallback&lt;boolean&gt;): void
237
238判断当前屏幕是否包含沉浸式窗口,使用callback异步回调。
239
240**系统接口:** 此接口为系统接口。
241
242**系统能力:** SystemCapability.Window.SessionManager
243
244**参数:**
245
246| 参数名      | 类型                        | 必填 | 说明                                                         |
247| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
248| callback    | AsyncCallback&lt;boolean&gt;   | 是   | 回调函数。返回true表示当前屏幕包含沉浸式窗口,false表示不包含。 |
249
250**错误码:**
251
252以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
253
254| 错误码ID | 错误信息 |
255| ------- | ----------------------- |
256| 202     | Permission verification failed. A non-system application calls a system API.|
257| 801 | Capability not supported on this device. |
258| 1400001 | Invalid display or screen. |
259| 1400003 | This display manager service works abnormally. |
260
261**示例:**
262
263```ts
264import { BusinessError } from '@kit.BasicServicesKit';
265import { display } from '@kit.ArkUI';
266
267let displayClass: display.Display | null = null;
268displayClass = display.getDefaultDisplaySync();
269displayClass.hasImmersiveWindow((err: BusinessError, data) => {
270    const errCode: number = err.code;
271    if (errCode) {
272      console.error('Failed to check whether there is immersive window. Code: ' + JSON.stringify(err));
273      return;
274    }
275    console.info('Succeeded in checking whether there is immersive window. data: ' + JSON.stringify(data));
276});
277```
278### hasImmersiveWindow<sup>11+</sup>
279hasImmersiveWindow(): Promise&lt;boolean&gt;
280
281判断当前屏幕是否包含沉浸式窗口,使用Promise异步回调。
282
283**系统接口:** 此接口为系统接口。
284
285**系统能力:** SystemCapability.Window.SessionManager
286
287**返回值:**
288
289| 类型                | 说明                      |
290| ------------------- | ------------------------- |
291| Promise&lt;boolean&gt; | Promise对象。返回true表示当前屏幕包含沉浸式窗口,false表示不包含。 |
292
293**错误码:**
294
295以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
296
297| 错误码ID | 错误信息 |
298| ------- | ----------------------- |
299| 202     | Permission verification failed. A non-system application calls a system API.|
300| 801 | Capability not supported on this device. |
301| 1400001 | Invalid display or screen. |
302| 1400003 | This display manager service works abnormally. |
303
304**示例:**
305
306```ts
307import { BusinessError } from '@kit.BasicServicesKit';
308import { display } from '@kit.ArkUI';
309
310let displayClass: display.Display | null = null;
311displayClass = display.getDefaultDisplaySync();
312let promise = displayClass.hasImmersiveWindow();
313promise.then((data) => {
314  console.info('Succeeded in checking whether there is immersive window. data: ' + JSON.stringify(data));
315}).catch((err: BusinessError) => {
316  console.error('Failed to check whether there is immersive window. Code: ' + JSON.stringify(err));
317})
318```
319