1e41f4b71Sopenharmony_ci# @ohos.screen (屏幕)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供管理屏幕的一些基础能力,包括获取屏幕对象,监听屏幕变化,创建和销毁虚拟屏幕等。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 
9e41f4b71Sopenharmony_ci> - 本模块接口为系统接口。
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { screen } from '@kit.ArkUI';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## screen.getAllScreens
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_cigetAllScreens(callback: AsyncCallback<Array<Screen>>): void
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci获取所有的屏幕,使用callback异步回调。
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**参数:**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| 参数名   | 类型                                                | 必填 | 说明                                   |
28e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------- | ---- | -------------------------------------- |
29e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[Screen](#screen)>> | 是   | 回调函数。返回当前获取的屏幕对象集合。 |
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**错误码:**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
36e41f4b71Sopenharmony_ci| ------- | ----------------------- |
37e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
38e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**示例:**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci```ts
43e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_cilet screenClass: screen.Screen | null = null;
46e41f4b71Sopenharmony_ciscreen.getAllScreens((err: BusinessError, data: Array<screen.Screen>) => {
47e41f4b71Sopenharmony_ci  const errCode: number = err.code;
48e41f4b71Sopenharmony_ci  if (errCode) {
49e41f4b71Sopenharmony_ci    console.error(`Failed to get all screens. Code:${err.code},message is ${err.message}`);
50e41f4b71Sopenharmony_ci    return;
51e41f4b71Sopenharmony_ci  }
52e41f4b71Sopenharmony_ci  console.info('Succeeded in getting all screens. Data:' + JSON.stringify(data));
53e41f4b71Sopenharmony_ci  screenClass = data[0];
54e41f4b71Sopenharmony_ci});
55e41f4b71Sopenharmony_ci```
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci## screen.getAllScreens
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_cigetAllScreens(): Promise&lt;Array&lt;Screen&gt;&gt;
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci获取所有的屏幕,使用Promise异步回调。
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**返回值:** 
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci| 类型                                          | 说明                                      |
68e41f4b71Sopenharmony_ci| --------------------------------------------- | ----------------------------------------- |
69e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;[Screen](#screen)&gt;&gt; | Promise对象。返回当前获取的屏幕对象集合。 |
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**错误码:**
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
76e41f4b71Sopenharmony_ci| ------- | ----------------------- |
77e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
78e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**示例:**
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci```ts
83e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_cilet screenClass: screen.Screen | null = null;
86e41f4b71Sopenharmony_cilet promise: Promise<Array<screen.Screen>> = screen.getAllScreens();
87e41f4b71Sopenharmony_cipromise.then((data: Array<screen.Screen>) => {
88e41f4b71Sopenharmony_ci  screenClass = data[0];
89e41f4b71Sopenharmony_ci  console.log('Succeeded in getting all screens. Data:' + JSON.stringify(data));
90e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
91e41f4b71Sopenharmony_ci  console.log('Failed to get all screens. Cause: ' + JSON.stringify(err));
92e41f4b71Sopenharmony_ci});
93e41f4b71Sopenharmony_ci```
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci## screen.on('connect' | 'disconnect' | 'change')
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_cion(eventType: 'connect' | 'disconnect' | 'change', callback: Callback&lt;number&gt;): void
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci开启屏幕状态变化的监听。
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**参数:**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| 参数名    | 类型                   | 必填 | 说明                                                        |
106e41f4b71Sopenharmony_ci| --------- | ---------------------- | ---- | ----------------------------------------------------------- |
107e41f4b71Sopenharmony_ci| eventType | string                 | 是   | 监听事件。<br/>-eventType为"connect"表示屏幕连接事件。<br/>-eventType为"disconnect"表示断开屏幕连接事件。<br/>-eventType为"change"表示屏幕状态改变事件。 |
108e41f4b71Sopenharmony_ci| callback  | Callback&lt;number&gt; | 是   | 回调函数。返回屏幕的id,该参数应为整数。                                    |
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**错误码:**
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
115e41f4b71Sopenharmony_ci| ------- | ----------------------- |
116e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
117e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**示例:**
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci```ts
122e41f4b71Sopenharmony_cilet callback: Callback<number> = (data: number) => {
123e41f4b71Sopenharmony_ci  console.info('Succeeded in registering the callback for screen changes. Data: ' + JSON.stringify(data))
124e41f4b71Sopenharmony_ci};
125e41f4b71Sopenharmony_ciscreen.on('connect', callback);
126e41f4b71Sopenharmony_ci```
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci## screen.off('connect' | 'disconnect' | 'change')
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_cioff(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback&lt;number&gt;): void
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci关闭屏幕状态变化的监听。
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**参数:**
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci| 参数名    | 类型                   | 必填 | 说明                                                         |
139e41f4b71Sopenharmony_ci| --------- | ---------------------- | ---- | ------------------------------------------------------------ |
140e41f4b71Sopenharmony_ci| eventType | string                 | 是   | 监听事件。<br/>-eventType为"connect"表示屏幕连接事件。<br/>-eventType为"disconnect"表示断开屏幕连接事件。<br/>-eventType为"change"表示屏幕状态改变事件。 |
141e41f4b71Sopenharmony_ci| callback  | Callback&lt;number&gt; | 否   | 回调函数。返回屏幕的id,该参数应为整数。                                     |
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**错误码:**
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
148e41f4b71Sopenharmony_ci| ------- | ----------------------- |
149e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
150e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**示例:**
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci```ts
155e41f4b71Sopenharmony_cilet callback: Callback<number> = (data: number) => {
156e41f4b71Sopenharmony_ci  console.info('Succeeded in unregistering the callback for screen changes. Data: ' + JSON.stringify(data))
157e41f4b71Sopenharmony_ci};
158e41f4b71Sopenharmony_ciscreen.off('connect', callback);
159e41f4b71Sopenharmony_ciscreen.off('connect');
160e41f4b71Sopenharmony_ci```
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci## screen.makeExpand
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_cimakeExpand(options:Array&lt;ExpandOption&gt;, callback: AsyncCallback&lt;number&gt;): void
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci将屏幕设置为扩展模式,使用callback异步回调。
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**参数:**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci| 参数名   | 类型                                       | 必填 | 说明                         |
173e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | ---- |----------------------------|
174e41f4b71Sopenharmony_ci| options  | Array&lt;[ExpandOption](#expandoption)&gt; | 是   | 设置扩展屏幕的参数集合。               |
175e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt;                     | 是   | 回调函数。返回扩展屏幕的群组id,其中id应为整数。 |
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**错误码:**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
182e41f4b71Sopenharmony_ci| ------- | ----------------------- |
183e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
184e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
185e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**示例:**
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci```ts
190e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_cilet groupId: number | null = null;
193e41f4b71Sopenharmony_ciclass ExpandOption {
194e41f4b71Sopenharmony_ci  screenId: number = 0;
195e41f4b71Sopenharmony_ci  startX: number = 0;
196e41f4b71Sopenharmony_ci  startY: number = 0;
197e41f4b71Sopenharmony_ci}
198e41f4b71Sopenharmony_cilet mainScreenOption: ExpandOption = { screenId: 0, startX: 0, startY: 0 };
199e41f4b71Sopenharmony_cilet otherScreenOption: ExpandOption = { screenId: 1, startX: 1080, startY: 0 };
200e41f4b71Sopenharmony_cilet expandOptionArray : ExpandOption[] = [ mainScreenOption, otherScreenOption ];
201e41f4b71Sopenharmony_ciscreen.makeExpand(expandOptionArray, (err: BusinessError, data: number) => {
202e41f4b71Sopenharmony_ci  const errCode: number = err.code;
203e41f4b71Sopenharmony_ci  if (errCode) {
204e41f4b71Sopenharmony_ci    console.error(`Failed to expand the screen. Code:${err.code},message is ${err.message}`);
205e41f4b71Sopenharmony_ci    return;
206e41f4b71Sopenharmony_ci  }
207e41f4b71Sopenharmony_ci  groupId = data;
208e41f4b71Sopenharmony_ci  console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
209e41f4b71Sopenharmony_ci});
210e41f4b71Sopenharmony_ci```
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci## screen.makeExpand
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_cimakeExpand(options:Array&lt;ExpandOption&gt;): Promise&lt;number&gt;
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci将屏幕设置为扩展模式,使用Promise异步回调。
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci**参数:**
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci| 参数名  | 类型                                       | 必填 | 说明                     |
223e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ | ---- | ------------------------ |
224e41f4b71Sopenharmony_ci| options | Array&lt;[ExpandOption](#expandoption)&gt; | 是   | 设置扩展屏幕的参数集合。 |
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci**返回值:**
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci| 类型                  | 说明                              |
229e41f4b71Sopenharmony_ci| --------------------- |---------------------------------|
230e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回扩展屏幕的群组id,其中id应为整数。 |
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**错误码:**
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
237e41f4b71Sopenharmony_ci| ------- | ----------------------- |
238e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
239e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
240e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**示例:**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci```ts
245e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ciclass ExpandOption {
248e41f4b71Sopenharmony_ci  screenId: number = 0;
249e41f4b71Sopenharmony_ci  startX: number = 0;
250e41f4b71Sopenharmony_ci  startY: number = 0;
251e41f4b71Sopenharmony_ci}
252e41f4b71Sopenharmony_cilet mainScreenOption: ExpandOption = { screenId: 0, startX: 0, startY: 0 };
253e41f4b71Sopenharmony_cilet otherScreenOption: ExpandOption = { screenId: 1, startX: 1080, startY: 0 };
254e41f4b71Sopenharmony_cilet expandOptionArray : ExpandOption[] = [ mainScreenOption, otherScreenOption ];
255e41f4b71Sopenharmony_ciscreen.makeExpand(expandOptionArray).then((
256e41f4b71Sopenharmony_ci  data: number) => {
257e41f4b71Sopenharmony_ci  console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
258e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
259e41f4b71Sopenharmony_ci  console.error(`Failed to expand the screen. Code:${err.code},message is ${err.message}`);
260e41f4b71Sopenharmony_ci});
261e41f4b71Sopenharmony_ci```
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci## screen.stopExpand<sup>10+</sup>
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_cistopExpand(expandScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;void&gt;): void
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci停止屏幕的扩展模式,使用callback异步回调。
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci**参数:**
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                                      |
274e41f4b71Sopenharmony_ci| ------------ | --------------------------- | --- |-----------------------------------------|
275e41f4b71Sopenharmony_ci| expandScreen | Array&lt;number&gt;         | 是   | 扩展屏幕id集合,其中id应为整数。 expandScreen数组大小不应超过1000。  |
276e41f4b71Sopenharmony_ci| callback     | AsyncCallback&lt;void&gt; | 是   | 回调函数。当停止屏幕扩展模式成功,err为undefined,否则为错误对象。 |
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci**错误码:**
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
283e41f4b71Sopenharmony_ci| ------- | ----------------------- |
284e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
285e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
286e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci**示例:**
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci```ts
291e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_cilet expandScreenIds: Array<number> = [1, 2, 3];
294e41f4b71Sopenharmony_ciscreen.stopExpand(expandScreenIds, (err: BusinessError) => {
295e41f4b71Sopenharmony_ci  const errCode: number = err.code;
296e41f4b71Sopenharmony_ci  if (errCode) {
297e41f4b71Sopenharmony_ci    console.error(`Failed to stop expand screens. Code:${err.code},message is ${err.message}`);
298e41f4b71Sopenharmony_ci    return;
299e41f4b71Sopenharmony_ci  }
300e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping expand screens.');
301e41f4b71Sopenharmony_ci});
302e41f4b71Sopenharmony_ci```
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci## screen.stopExpand<sup>10+</sup>
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_cistopExpand(expandScreen:Array&lt;number&gt;): Promise&lt;void&gt;
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci停止屏幕的扩展模式,使用Promise异步回调。
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci**参数:**
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                 |
315e41f4b71Sopenharmony_ci| ------------ | ------------------- | --- |--------------------|
316e41f4b71Sopenharmony_ci| expandScreen | Array&lt;number&gt; | 是   | 扩展屏幕id集合,其中id应为整数。expandScreen数组大小不应超过1000。 |
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**返回值:**
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci| 类型 | 说明 |
321e41f4b71Sopenharmony_ci| --------------------- | ----------------------- |
322e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci**错误码:**
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
329e41f4b71Sopenharmony_ci| ------- | ----------------------- |
330e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
331e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
332e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci**示例:**
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci```ts
337e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_cilet expandScreenIds: Array<number> = [1, 2, 3];
340e41f4b71Sopenharmony_ciscreen.stopExpand(expandScreenIds).then(() => {
341e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping expand screens.');
342e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
343e41f4b71Sopenharmony_ci  console.error(`Failed to stop expand screens. Code:${err.code},message is ${err.message}`);
344e41f4b71Sopenharmony_ci});
345e41f4b71Sopenharmony_ci```
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci## screen.makeMirror
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_cimakeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci将屏幕设置为镜像模式,使用callback异步回调。
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci**参数:**
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci| 参数名       | 类型                        | 必填 | 说明                 |
358e41f4b71Sopenharmony_ci| ------------ | --------------------------- | ---- |--------------------|
359e41f4b71Sopenharmony_ci| mainScreen   | number                      | 是   | 主屏幕id,该参数仅支持整数输入。  |
360e41f4b71Sopenharmony_ci| mirrorScreen | Array&lt;number&gt;         | 是   | 镜像屏幕id集合,其中id应为整数。 |
361e41f4b71Sopenharmony_ci| callback     | AsyncCallback&lt;number&gt; | 是   | 回调函数。返回镜像屏幕的群组id,其中id应为整数。  |
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci**错误码:**
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
368e41f4b71Sopenharmony_ci| ------- | ----------------------- |
369e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
370e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
371e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**示例:**
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci```ts
376e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_cilet mainScreenId: number = 0;
379e41f4b71Sopenharmony_cilet mirrorScreenIds: Array<number> = [1, 2, 3];
380e41f4b71Sopenharmony_ciscreen.makeMirror(mainScreenId, mirrorScreenIds, (err: BusinessError, data: number) => {
381e41f4b71Sopenharmony_ci  const errCode: number = err.code;
382e41f4b71Sopenharmony_ci  if (errCode) {
383e41f4b71Sopenharmony_ci    console.error(`Failed to set screen mirroring. Code:${err.code},message is ${err.message}`);
384e41f4b71Sopenharmony_ci    return;
385e41f4b71Sopenharmony_ci  }
386e41f4b71Sopenharmony_ci  console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
387e41f4b71Sopenharmony_ci});
388e41f4b71Sopenharmony_ci```
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci## screen.makeMirror
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_cimakeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;): Promise&lt;number&gt;
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci将屏幕设置为镜像模式,使用Promise异步回调。
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci**参数:**
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci| 参数名       | 类型                | 必填 | 说明                 |
401e41f4b71Sopenharmony_ci| ------------ | ------------------- | ---- |--------------------|
402e41f4b71Sopenharmony_ci| mainScreen   | number              | 是   | 主屏幕id,该参数仅支持整数输入。  |
403e41f4b71Sopenharmony_ci| mirrorScreen | Array&lt;number&gt; | 是   | 镜像屏幕id集合。其中id应为整数。 |
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci**返回值:**
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci| 类型                  | 说明                              |
408e41f4b71Sopenharmony_ci| --------------------- |---------------------------------|
409e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回镜像屏幕的群组id,其中id应为整数。 |
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci**错误码:**
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
416e41f4b71Sopenharmony_ci| ------- | ----------------------- |
417e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
418e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
419e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci**示例:**
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci```ts
424e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_cilet mainScreenId: number = 0;
427e41f4b71Sopenharmony_cilet mirrorScreenIds: Array<number> = [1, 2, 3];
428e41f4b71Sopenharmony_ciscreen.makeMirror(mainScreenId, mirrorScreenIds).then((data: number) => {
429e41f4b71Sopenharmony_ci  console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
430e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
431e41f4b71Sopenharmony_ci  console.error(`Failed to set screen mirroring. Code:${err.code},message is ${err.message}`);
432e41f4b71Sopenharmony_ci});
433e41f4b71Sopenharmony_ci```
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci## screen.stopMirror<sup>10+</sup>
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_cistopMirror(mirrorScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;void&gt;): void
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci停止屏幕的镜像模式,使用callback异步回调。
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci**参数:**
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                                      |
446e41f4b71Sopenharmony_ci| ------------ | --------------------------- | --- |-----------------------------------------|
447e41f4b71Sopenharmony_ci| mirrorScreen | Array&lt;number&gt;         | 是   | 镜像屏幕id集合,其中id应为整数。 mirrorScreen数组大小不应超过1000。 |
448e41f4b71Sopenharmony_ci| callback     | AsyncCallback&lt;void&gt; | 是   | 回调函数。当停止屏幕镜像模式成功,err为undefined,否则为错误对象。 |
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_ci**错误码:**
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
455e41f4b71Sopenharmony_ci| ------- | ----------------------- |
456e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
457e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
458e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci**示例:**
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci```ts
463e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_cilet mirrorScreenIds: Array<number> = [1, 2, 3];
466e41f4b71Sopenharmony_ciscreen.stopMirror(mirrorScreenIds, (err: BusinessError) => {
467e41f4b71Sopenharmony_ci  const errCode: number = err.code;
468e41f4b71Sopenharmony_ci  if (errCode) {
469e41f4b71Sopenharmony_ci    console.error(`Failed to stop mirror screens. Code:${err.code},message is ${err.message}`);
470e41f4b71Sopenharmony_ci    return;
471e41f4b71Sopenharmony_ci  }
472e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping mirror screens.');
473e41f4b71Sopenharmony_ci});
474e41f4b71Sopenharmony_ci```
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci## screen.stopMirror<sup>10+</sup>
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_cistopMirror(mirrorScreen:Array&lt;number&gt;): Promise&lt;void&gt;
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci停止屏幕的镜像模式,使用Promise异步回调。
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci**参数:**
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                 |
487e41f4b71Sopenharmony_ci| ------------ | ------------------- | --- |--------------------|
488e41f4b71Sopenharmony_ci| mirrorScreen | Array&lt;number&gt; | 是   | 镜像屏幕id集合,其中id应为整数。mirrorScreen数组大小不应超过1000。 |
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci**返回值:**
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci| 类型 | 说明 |
493e41f4b71Sopenharmony_ci| --------------------- | ----------------------- |
494e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**错误码:**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
501e41f4b71Sopenharmony_ci| ------- | ----------------------- |
502e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
503e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
504e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
505e41f4b71Sopenharmony_ci
506e41f4b71Sopenharmony_ci**示例:**
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci```ts
509e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_cilet mirrorScreenIds: Array<number> = [1, 2, 3];
512e41f4b71Sopenharmony_ciscreen.stopMirror(mirrorScreenIds).then(() => {
513e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping mirror screens.');
514e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
515e41f4b71Sopenharmony_ci  console.error(`Failed to stop mirror screens.Code:${err.code},message is ${err.message}`);
516e41f4b71Sopenharmony_ci});
517e41f4b71Sopenharmony_ci```
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci## screen.createVirtualScreen
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_cicreateVirtualScreen(options:VirtualScreenOption, callback: AsyncCallback&lt;Screen&gt;): void
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_ci创建虚拟屏幕,使用callback异步回调。
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CAPTURE_SCREEN
528e41f4b71Sopenharmony_ci
529e41f4b71Sopenharmony_ci**参数:**
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci| 参数名   | 类型                                        | 必填 | 说明                               |
532e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ---------------------------------- |
533e41f4b71Sopenharmony_ci| options  | [VirtualScreenOption](#virtualscreenoption) | 是   | 用于创建虚拟屏幕的参数。           |
534e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;[Screen](#screen)&gt;      | 是   | 回调函数,返回创建的虚拟屏幕对象。 |
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci**错误码:**
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
541e41f4b71Sopenharmony_ci| ------- | ----------------------- |
542e41f4b71Sopenharmony_ci| 201 | Permission verification failed. |
543e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
544e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
545e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci**示例:**
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci```ts
550e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_cilet screenClass: screen.Screen | null = null;
553e41f4b71Sopenharmony_ciclass VirtualScreenOption {
554e41f4b71Sopenharmony_ci  name : string = '';
555e41f4b71Sopenharmony_ci  width : number =  0;
556e41f4b71Sopenharmony_ci  height : number = 0;
557e41f4b71Sopenharmony_ci  density : number = 0;
558e41f4b71Sopenharmony_ci  surfaceId : string = '';
559e41f4b71Sopenharmony_ci}
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_cilet option : VirtualScreenOption = { 
562e41f4b71Sopenharmony_ci  name: 'screen01',
563e41f4b71Sopenharmony_ci  width: 1080,
564e41f4b71Sopenharmony_ci  height: 2340,
565e41f4b71Sopenharmony_ci  density: 2,
566e41f4b71Sopenharmony_ci  surfaceId: ''
567e41f4b71Sopenharmony_ci};
568e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option, (err: BusinessError, data: screen.Screen) => {
569e41f4b71Sopenharmony_ci  const errCode: number = err.code;
570e41f4b71Sopenharmony_ci  if (errCode) {
571e41f4b71Sopenharmony_ci    console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
572e41f4b71Sopenharmony_ci    return;
573e41f4b71Sopenharmony_ci  }
574e41f4b71Sopenharmony_ci  screenClass = data;
575e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
576e41f4b71Sopenharmony_ci});
577e41f4b71Sopenharmony_ci```
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ci## screen.createVirtualScreen
580e41f4b71Sopenharmony_ci
581e41f4b71Sopenharmony_cicreateVirtualScreen(options:VirtualScreenOption): Promise&lt;Screen&gt;
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci创建虚拟屏幕,使用Promise异步回调。
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CAPTURE_SCREEN
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci**参数:** 
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci| 参数名  | 类型                                        | 必填 | 说明                     |
592e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | ------------------------ |
593e41f4b71Sopenharmony_ci| options | [VirtualScreenOption](#virtualscreenoption) | 是   | 用于创建虚拟屏幕的参数。 |
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci**返回值:**
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci| 类型                             | 说明                                  |
598e41f4b71Sopenharmony_ci| -------------------------------- | ------------------------------------- |
599e41f4b71Sopenharmony_ci| Promise&lt;[Screen](#screen)&gt; | Promise对象。返回创建的虚拟屏幕对象。 |
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci**错误码:**
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
606e41f4b71Sopenharmony_ci| ------- | ----------------------- |
607e41f4b71Sopenharmony_ci| 201 | Permission verification failed. |
608e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
609e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
610e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci**示例:**
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_ci```ts
615e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_cilet screenClass: screen.Screen | null = null;
618e41f4b71Sopenharmony_ciclass VirtualScreenOption {
619e41f4b71Sopenharmony_ci  name : string = '';
620e41f4b71Sopenharmony_ci  width : number =  0;
621e41f4b71Sopenharmony_ci  height : number = 0;
622e41f4b71Sopenharmony_ci  density : number = 0;
623e41f4b71Sopenharmony_ci  surfaceId : string = '';
624e41f4b71Sopenharmony_ci}
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_cilet option : VirtualScreenOption = { 
627e41f4b71Sopenharmony_ci  name: 'screen01',
628e41f4b71Sopenharmony_ci  width: 1080,
629e41f4b71Sopenharmony_ci  height: 2340,
630e41f4b71Sopenharmony_ci  density: 2,
631e41f4b71Sopenharmony_ci  surfaceId: ''
632e41f4b71Sopenharmony_ci};
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
635e41f4b71Sopenharmony_ci  screenClass = data;
636e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
637e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
638e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
639e41f4b71Sopenharmony_ci});
640e41f4b71Sopenharmony_ci```
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci## screen.destroyVirtualScreen
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_cidestroyVirtualScreen(screenId:number, callback: AsyncCallback&lt;void&gt;): void
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci销毁虚拟屏幕,使用callback异步回调。
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**参数:**
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci| 参数名   | 类型                      | 必填 | 说明                                                         |
653e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
654e41f4b71Sopenharmony_ci| screenId | number                    | 是   | 屏幕的id,该参数仅支持整数输入。                                                   |
655e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当销毁虚拟屏幕成功,err为undefined,否则为错误对象。 |
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci**错误码:**
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
662e41f4b71Sopenharmony_ci| ------- | ----------------------------- |
663e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
664e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
665e41f4b71Sopenharmony_ci| 1400002 | Unauthorized operation. |
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci**示例:**
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci```ts
670e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_cilet screenId: number = 1;
673e41f4b71Sopenharmony_ciscreen.destroyVirtualScreen(screenId, (err: BusinessError) => {
674e41f4b71Sopenharmony_ci  const errCode: number = err.code;
675e41f4b71Sopenharmony_ci  if (errCode) {
676e41f4b71Sopenharmony_ci    console.error(`Failed to destroy the virtual screen. Code:${err.code},message is ${err.message}`);
677e41f4b71Sopenharmony_ci    return;
678e41f4b71Sopenharmony_ci  }
679e41f4b71Sopenharmony_ci  console.info('Succeeded in destroying the virtual screen.');
680e41f4b71Sopenharmony_ci});
681e41f4b71Sopenharmony_ci```
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci## screen.destroyVirtualScreen
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_cidestroyVirtualScreen(screenId:number): Promise&lt;void&gt;
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci销毁虚拟屏幕,使用Promise异步回调。
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci**参数:**
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci| 参数名   | 类型   | 必填 | 说明       |
694e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------- |
695e41f4b71Sopenharmony_ci| screenId | number | 是   | 屏幕的id,该参数仅支持整数输入。 |
696e41f4b71Sopenharmony_ci
697e41f4b71Sopenharmony_ci**返回值:**
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci| 类型                | 说明                      |
700e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
701e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**错误码:**
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
708e41f4b71Sopenharmony_ci| ------- | ----------------------------- |
709e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
710e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
711e41f4b71Sopenharmony_ci| 1400002 | Unauthorized operation. |
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci**示例:**
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci```ts
716e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_cilet screenId: number = 1;
719e41f4b71Sopenharmony_ciscreen.destroyVirtualScreen(screenId).then(() => {
720e41f4b71Sopenharmony_ci  console.info('Succeeded in destroying the virtual screen.');
721e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
722e41f4b71Sopenharmony_ci  console.error(`Failed to destroy the virtual screen.Code:${err.code},message is ${err.message}`);
723e41f4b71Sopenharmony_ci});
724e41f4b71Sopenharmony_ci```
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci## screen.setVirtualScreenSurface
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_cisetVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback&lt;void&gt;): void
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci设置虚拟屏幕的surface,使用callback异步回调。
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CAPTURE_SCREEN,仅系统应用可用。
735e41f4b71Sopenharmony_ci
736e41f4b71Sopenharmony_ci**参数:**
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_ci| 参数名    | 类型                      | 必填 | 说明                                                         |
739e41f4b71Sopenharmony_ci| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
740e41f4b71Sopenharmony_ci| screenId  | number                    | 是   | 屏幕的id,该参数仅支持整数输入。                                                   |
741e41f4b71Sopenharmony_ci| surfaceId | string                    | 是   | 代表虚拟屏幕的surface标识符,surfaceId值可自行定义。                                                |
742e41f4b71Sopenharmony_ci| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置虚拟屏幕surface成功,err为undefined,否则为错误对象。 |
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci**错误码:**
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
749e41f4b71Sopenharmony_ci| ------- | ----------------------- |
750e41f4b71Sopenharmony_ci| 201 | Permission verification failed. |
751e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
752e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
753e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
754e41f4b71Sopenharmony_ci
755e41f4b71Sopenharmony_ci**示例:**
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci```ts
758e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
759e41f4b71Sopenharmony_ci
760e41f4b71Sopenharmony_cilet screenId: number = 1;
761e41f4b71Sopenharmony_cilet surfaceId: string = '2048';
762e41f4b71Sopenharmony_ciscreen.setVirtualScreenSurface(screenId, surfaceId, (err: BusinessError) => {
763e41f4b71Sopenharmony_ci  const errCode: number = err.code;
764e41f4b71Sopenharmony_ci  if (errCode) {
765e41f4b71Sopenharmony_ci    console.error(`Failed to set the surface for the virtual screen. Code:${err.code},message is ${err.message}`);
766e41f4b71Sopenharmony_ci    return;
767e41f4b71Sopenharmony_ci  }
768e41f4b71Sopenharmony_ci  console.info('Succeeded in setting the surface for the virtual screen.');
769e41f4b71Sopenharmony_ci});
770e41f4b71Sopenharmony_ci```
771e41f4b71Sopenharmony_ci
772e41f4b71Sopenharmony_ci## screen.setVirtualScreenSurface
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_cisetVirtualScreenSurface(screenId:number, surfaceId: string): Promise&lt;void&gt;
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci设置虚拟屏幕的surface,使用Promise异步回调。
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CAPTURE_SCREEN,仅系统应用可用。
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci**参数:**
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ci| 参数名    | 类型   | 必填 | 说明          |
785e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------- |
786e41f4b71Sopenharmony_ci| screenId  | number | 是   | 屏幕的id,该参数仅支持整数输入。    |
787e41f4b71Sopenharmony_ci| surfaceId | string | 是   | 代表虚拟屏幕的surface标识符,surfaceId值可自行定义。 |
788e41f4b71Sopenharmony_ci
789e41f4b71Sopenharmony_ci**返回值:**
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci| 类型                | 说明                      |
792e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
793e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_ci**错误码:**
796e41f4b71Sopenharmony_ci
797e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
798e41f4b71Sopenharmony_ci
799e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
800e41f4b71Sopenharmony_ci| ------- | ----------------------- |
801e41f4b71Sopenharmony_ci| 201 | Permission verification failed. |
802e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
803e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
804e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. |
805e41f4b71Sopenharmony_ci
806e41f4b71Sopenharmony_ci**示例:**
807e41f4b71Sopenharmony_ci
808e41f4b71Sopenharmony_ci```ts
809e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_cilet screenId: number = 1;
812e41f4b71Sopenharmony_cilet surfaceId: string = '2048';
813e41f4b71Sopenharmony_ciscreen.setVirtualScreenSurface(screenId, surfaceId).then(() => {
814e41f4b71Sopenharmony_ci  console.info('Succeeded in setting the surface for the virtual screen.');
815e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
816e41f4b71Sopenharmony_ci  console.error(`Failed to set the surface for the virtual screen. Code:${err.code},message is ${err.message}`);
817e41f4b71Sopenharmony_ci});
818e41f4b71Sopenharmony_ci```
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_ci## screen.isScreenRotationLocked
821e41f4b71Sopenharmony_ci
822e41f4b71Sopenharmony_ciisScreenRotationLocked(): Promise&lt;boolean&gt;
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci查询当前自动转屏是否锁定,使用Promise异步回调。
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ci**返回值:**
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci| 类型                   | 说明                                  |
831e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------- |
832e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | Promise对象。返回true表示当前自动转屏处于锁定状态;返回false表示当前自动转屏不处于锁定状态。 |
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ci**错误码:**
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
839e41f4b71Sopenharmony_ci| ------- | ----------------------- |
840e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**示例:**
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci```ts
845e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ciscreen.isScreenRotationLocked().then((isLocked: boolean) => {
848e41f4b71Sopenharmony_ci  console.info('Succeeded in getting the screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
849e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
850e41f4b71Sopenharmony_ci  console.error(`Failed to get the screen rotation lock status. Code:${err.code},message is ${err.message}`);
851e41f4b71Sopenharmony_ci});
852e41f4b71Sopenharmony_ci```
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci## screen.isScreenRotationLocked
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_ciisScreenRotationLocked(callback: AsyncCallback&lt;boolean&gt;): void
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci查询当前自动转屏是否锁定,使用callback异步回调。
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**参数:**
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci| 参数名    | 类型                          | 必填 | 说明                                                         |
865e41f4b71Sopenharmony_ci| --------- | ---------------------------- | ---- | ------------------------------------------------------------ |
866e41f4b71Sopenharmony_ci| callback  | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前自动转屏处于锁定状态;返回false表示当前自动转屏不处于锁定状态。 |
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci**错误码:**
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
873e41f4b71Sopenharmony_ci| ------- | ----------------------- |
874e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
875e41f4b71Sopenharmony_ci
876e41f4b71Sopenharmony_ci**示例:**
877e41f4b71Sopenharmony_ci
878e41f4b71Sopenharmony_ci```ts
879e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ciscreen.isScreenRotationLocked((err: BusinessError, isLocked: boolean) => {
882e41f4b71Sopenharmony_ciconst errCode: number = err.code;
883e41f4b71Sopenharmony_ciif (errCode) {
884e41f4b71Sopenharmony_ci  console.error(`Failed to get the screen rotation lock status. Code:${err.code},message is ${err.message}`);
885e41f4b71Sopenharmony_ci  return;
886e41f4b71Sopenharmony_ci}
887e41f4b71Sopenharmony_ciconsole.info('Succeeded in getting the screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
888e41f4b71Sopenharmony_ci});
889e41f4b71Sopenharmony_ci```
890e41f4b71Sopenharmony_ci
891e41f4b71Sopenharmony_ci## screen.setScreenRotationLocked
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_cisetScreenRotationLocked(isLocked: boolean): Promise&lt;void&gt;
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_ci设置自动转屏开关是否锁定,使用Promise异步回调。
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci**参数:**
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_ci| 参数名    | 类型   | 必填 | 说明          |
902e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------- |
903e41f4b71Sopenharmony_ci| isLocked  | boolean | 是   | 自动转屏开关是否锁定。true为锁定,false为未锁定. |
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ci**返回值:**
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci| 类型                | 说明                      |
908e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
909e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci**错误码:**
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
914e41f4b71Sopenharmony_ci
915e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
916e41f4b71Sopenharmony_ci| ------- | ----------------------- |
917e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
918e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
919e41f4b71Sopenharmony_ci
920e41f4b71Sopenharmony_ci**示例:**
921e41f4b71Sopenharmony_ci
922e41f4b71Sopenharmony_ci```ts
923e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_cilet isLocked: boolean = false;
926e41f4b71Sopenharmony_ciscreen.setScreenRotationLocked(isLocked).then(() => {
927e41f4b71Sopenharmony_ci  console.info('Succeeded in unlocking auto rotate');
928e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
929e41f4b71Sopenharmony_ci  console.error(`Failed to unlock auto rotate. Code:${err.code},message is ${err.message}`);
930e41f4b71Sopenharmony_ci});
931e41f4b71Sopenharmony_ci```
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci## screen.setScreenRotationLocked
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_cisetScreenRotationLocked(isLocked: boolean, callback: AsyncCallback&lt;void&gt;): void
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ci设置自动转屏开关是否锁定,使用callback异步回调。
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci**参数:**
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci| 参数名    | 类型                      | 必填 | 说明                                                         |
944e41f4b71Sopenharmony_ci| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
945e41f4b71Sopenharmony_ci| isLocked  | boolean                   | 是   | 自动转屏开关是否锁定。true为锁定,false为未锁定.                 |
946e41f4b71Sopenharmony_ci| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置自动转屏是否锁定成功,err为undefined,否则为错误对象。 |
947e41f4b71Sopenharmony_ci
948e41f4b71Sopenharmony_ci**错误码:**
949e41f4b71Sopenharmony_ci
950e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
951e41f4b71Sopenharmony_ci
952e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
953e41f4b71Sopenharmony_ci| ------- | ----------------------- |
954e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
955e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci**示例:**
958e41f4b71Sopenharmony_ci
959e41f4b71Sopenharmony_ci```ts
960e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
961e41f4b71Sopenharmony_ci
962e41f4b71Sopenharmony_cilet isLocked: boolean = false;
963e41f4b71Sopenharmony_ciscreen.setScreenRotationLocked(isLocked, (err: BusinessError) => {
964e41f4b71Sopenharmony_ci  const errCode: number = err.code;
965e41f4b71Sopenharmony_ci  if (errCode) {
966e41f4b71Sopenharmony_ci    console.error(`Failed to unlock auto rotate. Code:${err.code},message is ${err.message}`);
967e41f4b71Sopenharmony_ci    return;
968e41f4b71Sopenharmony_ci  }
969e41f4b71Sopenharmony_ci  console.info('Succeeded in unlocking auto rotate.');
970e41f4b71Sopenharmony_ci});
971e41f4b71Sopenharmony_ci```
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci## ExpandOption
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci扩展屏幕的参数。
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci| 名称     | 类型 | 可读 | 可写 | 说明                |
980e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ---- | ------------------- |
981e41f4b71Sopenharmony_ci| screenId | number   | 是   | 是   | 屏幕的id,该参数应为整数。          |
982e41f4b71Sopenharmony_ci| startX   | number   | 是   | 是   | 屏幕的起始X轴坐标,该参数应为整数。 |
983e41f4b71Sopenharmony_ci| startY   | number   | 是   | 是   | 屏幕的起始Y轴坐标,该参数应为整数。 |
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci## VirtualScreenOption
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci创建虚拟屏幕的参数。
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
990e41f4b71Sopenharmony_ci
991e41f4b71Sopenharmony_ci| 名称      | 类型 | 可读 | 可写 | 说明                       |
992e41f4b71Sopenharmony_ci| --------- | -------- | ---- | ---- |--------------------------|
993e41f4b71Sopenharmony_ci| name      | string   | 是   | 是   | 指定虚拟屏幕的名称。               |
994e41f4b71Sopenharmony_ci| width     | number   | 是   | 是   | 指定虚拟屏幕的宽度,单位为px,该参数应为整数。 |
995e41f4b71Sopenharmony_ci| height    | number   | 是   | 是   | 指定虚拟屏幕的高度,单位为px,该参数应为整数。 |
996e41f4b71Sopenharmony_ci| density   | number   | 是   | 是   | 指定虚拟屏幕的密度,单位为px,该参数为浮点数。 |
997e41f4b71Sopenharmony_ci| surfaceId | string   | 是   | 是   | 指定虚拟屏幕的surfaceId。        |
998e41f4b71Sopenharmony_ci
999e41f4b71Sopenharmony_ci## Screen
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci屏幕实例。
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_ci下列API示例中都需先使用[getAllScreens()](#screengetallscreens)、[createVirtualScreen()](#screencreatevirtualscreen)中的任一方法获取到Screen实例,再通过此实例调用对应方法。
1004e41f4b71Sopenharmony_ci
1005e41f4b71Sopenharmony_ci### 属性
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ci| 名称              | 类型                                       | 可读 | 可写 | 说明                                                          |
1010e41f4b71Sopenharmony_ci| ----------------- | ---------------------------------------------- | ---- | ---- |-------------------------------------------------------------|
1011e41f4b71Sopenharmony_ci| id                | number                                         | 是   | 否   | 屏幕的id,该参数应为整数。                                              |
1012e41f4b71Sopenharmony_ci| parent            | number                                         | 是   | 否   | 屏幕所属群组的id,该参数应为整数。                                          |
1013e41f4b71Sopenharmony_ci| supportedModeInfo | Array&lt;[ScreenModeInfo](#screenmodeinfo)&gt; | 是   | 否   | 屏幕支持的模式集合。                                                  |
1014e41f4b71Sopenharmony_ci| activeModeIndex   | number                                         | 是   | 否   | 当前屏幕所处模式索引。模式索引的当前值和值的范围,会根据屏幕当前分辨率、刷新率和设备硬件差异产生变化。该参数应为整数。 |
1015e41f4b71Sopenharmony_ci| orientation       | [Orientation](#orientation)                     | 是   | 否   | 屏幕方向。                                                       |
1016e41f4b71Sopenharmony_ci| sourceMode<sup>10+</sup> | [ScreenSourceMode](#screensourcemode10)            | 是   | 否   | 屏幕来源模式。                                                     |
1017e41f4b71Sopenharmony_ci
1018e41f4b71Sopenharmony_ci### setOrientation
1019e41f4b71Sopenharmony_ci
1020e41f4b71Sopenharmony_cisetOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_ci设置屏幕方向,使用callback异步回调。
1023e41f4b71Sopenharmony_ci
1024e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1025e41f4b71Sopenharmony_ci
1026e41f4b71Sopenharmony_ci| 参数名      | 类型                        | 必填 | 说明                                                         |
1027e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
1028e41f4b71Sopenharmony_ci| orientation | [Orientation](#orientation) | 是   | 屏幕方向。orientation值必须来自Orientation枚举方向。                |
1029e41f4b71Sopenharmony_ci| callback    | AsyncCallback&lt;void&gt;   | 是   | 回调函数。当设置屏幕方向成功,err为undefined,否则为错误对象。 |
1030e41f4b71Sopenharmony_ci
1031e41f4b71Sopenharmony_ci**错误码:**
1032e41f4b71Sopenharmony_ci
1033e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1034e41f4b71Sopenharmony_ci
1035e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1036e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1037e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1038e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
1039e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1040e41f4b71Sopenharmony_ci
1041e41f4b71Sopenharmony_ci**示例:**
1042e41f4b71Sopenharmony_ci
1043e41f4b71Sopenharmony_ci```ts
1044e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1047e41f4b71Sopenharmony_ci  name : string = '';
1048e41f4b71Sopenharmony_ci  width : number =  0;
1049e41f4b71Sopenharmony_ci  height : number = 0;
1050e41f4b71Sopenharmony_ci  density : number = 0;
1051e41f4b71Sopenharmony_ci  surfaceId : string = '';
1052e41f4b71Sopenharmony_ci}
1053e41f4b71Sopenharmony_ci
1054e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1055e41f4b71Sopenharmony_ci  name: 'screen01',
1056e41f4b71Sopenharmony_ci  width: 1080,
1057e41f4b71Sopenharmony_ci  height: 2340,
1058e41f4b71Sopenharmony_ci  density: 2,
1059e41f4b71Sopenharmony_ci  surfaceId: ''
1060e41f4b71Sopenharmony_ci};
1061e41f4b71Sopenharmony_ci
1062e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1063e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1064e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1065e41f4b71Sopenharmony_ci  screenClass.setOrientation(screen.Orientation.VERTICAL, (err: BusinessError) => {
1066e41f4b71Sopenharmony_ci    const errCode: number = err.code;
1067e41f4b71Sopenharmony_ci    if (errCode) {
1068e41f4b71Sopenharmony_ci      console.error(`Failed to set the vertical orientation. Code:${err.code},message is ${err.message}`);
1069e41f4b71Sopenharmony_ci      return;
1070e41f4b71Sopenharmony_ci    }
1071e41f4b71Sopenharmony_ci    console.info('Succeeded in setting the vertical orientation.');
1072e41f4b71Sopenharmony_ci  });
1073e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1074e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1075e41f4b71Sopenharmony_ci});
1076e41f4b71Sopenharmony_ci```
1077e41f4b71Sopenharmony_ci
1078e41f4b71Sopenharmony_ci### setOrientation
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_cisetOrientation(orientation: Orientation): Promise&lt;void&gt;
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_ci设置屏幕方向,使用Promise异步回调。
1083e41f4b71Sopenharmony_ci
1084e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1085e41f4b71Sopenharmony_ci
1086e41f4b71Sopenharmony_ci| 参数名      | 类型                        | 必填 | 说明       |
1087e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ---------- |
1088e41f4b71Sopenharmony_ci| orientation | [Orientation](#orientation) | 是   | 屏幕方向。orientation值必须来自Orientation枚举方向。 |
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci**返回值:**
1091e41f4b71Sopenharmony_ci
1092e41f4b71Sopenharmony_ci| 类型                | 说明                      |
1093e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
1094e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1095e41f4b71Sopenharmony_ci
1096e41f4b71Sopenharmony_ci**错误码:**
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1099e41f4b71Sopenharmony_ci
1100e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1101e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1102e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1103e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
1104e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1105e41f4b71Sopenharmony_ci
1106e41f4b71Sopenharmony_ci**示例:**
1107e41f4b71Sopenharmony_ci
1108e41f4b71Sopenharmony_ci```ts
1109e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1110e41f4b71Sopenharmony_ci
1111e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1112e41f4b71Sopenharmony_ci  name : string = '';
1113e41f4b71Sopenharmony_ci  width : number =  0;
1114e41f4b71Sopenharmony_ci  height : number = 0;
1115e41f4b71Sopenharmony_ci  density : number = 0;
1116e41f4b71Sopenharmony_ci  surfaceId : string = '';
1117e41f4b71Sopenharmony_ci}
1118e41f4b71Sopenharmony_ci
1119e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1120e41f4b71Sopenharmony_ci  name: 'screen01',
1121e41f4b71Sopenharmony_ci  width: 1080,
1122e41f4b71Sopenharmony_ci  height: 2340,
1123e41f4b71Sopenharmony_ci  density: 2,
1124e41f4b71Sopenharmony_ci  surfaceId: ''
1125e41f4b71Sopenharmony_ci};
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1128e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1129e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1130e41f4b71Sopenharmony_ci  let promise: Promise<void> = screenClass.setOrientation(screen.Orientation.VERTICAL);
1131e41f4b71Sopenharmony_ci  promise.then(() => {
1132e41f4b71Sopenharmony_ci    console.info('Succeeded in setting the vertical orientation.');
1133e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
1134e41f4b71Sopenharmony_ci    console.error(`Failed to set the vertical orientation. Code:${err.code},message is ${err.message}`);
1135e41f4b71Sopenharmony_ci  });
1136e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1137e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1138e41f4b71Sopenharmony_ci});
1139e41f4b71Sopenharmony_ci```
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci### setScreenActiveMode
1142e41f4b71Sopenharmony_ci
1143e41f4b71Sopenharmony_cisetScreenActiveMode(modeIndex: number, callback: AsyncCallback&lt;void&gt;): void
1144e41f4b71Sopenharmony_ci
1145e41f4b71Sopenharmony_ci设置屏幕当前显示模式,使用callback异步回调。
1146e41f4b71Sopenharmony_ci
1147e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1148e41f4b71Sopenharmony_ci
1149e41f4b71Sopenharmony_ci| 参数名    | 类型                      | 必填 | 说明                                                         |
1150e41f4b71Sopenharmony_ci| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
1151e41f4b71Sopenharmony_ci| modeIndex | number                    | 是   | 模式索引。模式索引的当前值和值的范围,会根据屏幕当前分辨率、刷新率和设备硬件差异产生变化,该参数仅支持整数输入。 |
1152e41f4b71Sopenharmony_ci| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置屏幕当前显示模式成功,err为undefined,否则为错误对象。 |
1153e41f4b71Sopenharmony_ci
1154e41f4b71Sopenharmony_ci**错误码:**
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1159e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1160e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1161e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1162e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**示例:**
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci```ts
1167e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1168e41f4b71Sopenharmony_ci
1169e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1170e41f4b71Sopenharmony_ci  name : string = '';
1171e41f4b71Sopenharmony_ci  width : number =  0;
1172e41f4b71Sopenharmony_ci  height : number = 0;
1173e41f4b71Sopenharmony_ci  density : number = 0;
1174e41f4b71Sopenharmony_ci  surfaceId : string = '';
1175e41f4b71Sopenharmony_ci}
1176e41f4b71Sopenharmony_ci
1177e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1178e41f4b71Sopenharmony_ci  name: 'screen01',
1179e41f4b71Sopenharmony_ci  width: 1080,
1180e41f4b71Sopenharmony_ci  height: 2340,
1181e41f4b71Sopenharmony_ci  density: 2,
1182e41f4b71Sopenharmony_ci  surfaceId: ''
1183e41f4b71Sopenharmony_ci};
1184e41f4b71Sopenharmony_ci
1185e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1186e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1187e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1188e41f4b71Sopenharmony_ci  let modeIndex: number = 0;
1189e41f4b71Sopenharmony_ci  screenClass.setScreenActiveMode(modeIndex, (err: BusinessError) => {
1190e41f4b71Sopenharmony_ci    const errCode: number = err.code;
1191e41f4b71Sopenharmony_ci    if (errCode) {
1192e41f4b71Sopenharmony_ci      console.error(`Failed to set screen active mode 0. Code:${err.code},message is ${err.message}`);
1193e41f4b71Sopenharmony_ci      return;
1194e41f4b71Sopenharmony_ci    }
1195e41f4b71Sopenharmony_ci    console.info('Succeeded in setting the vertical orientation.');
1196e41f4b71Sopenharmony_ci  });
1197e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1198e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1199e41f4b71Sopenharmony_ci});
1200e41f4b71Sopenharmony_ci```
1201e41f4b71Sopenharmony_ci
1202e41f4b71Sopenharmony_ci### setScreenActiveMode
1203e41f4b71Sopenharmony_ci
1204e41f4b71Sopenharmony_cisetScreenActiveMode(modeIndex: number): Promise&lt;void&gt;
1205e41f4b71Sopenharmony_ci
1206e41f4b71Sopenharmony_ci设置屏幕当前显示模式,使用Promise异步回调。
1207e41f4b71Sopenharmony_ci
1208e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1209e41f4b71Sopenharmony_ci
1210e41f4b71Sopenharmony_ci| 参数名    | 类型   | 必填 | 说明       |
1211e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---------- |
1212e41f4b71Sopenharmony_ci| modeIndex | number | 是   | 模式索引。模式索引的当前值和值的范围,会根据屏幕当前分辨率、刷新率和设备硬件差异产生变化,该参数仅支持整数输入。 |
1213e41f4b71Sopenharmony_ci
1214e41f4b71Sopenharmony_ci**返回值:**
1215e41f4b71Sopenharmony_ci
1216e41f4b71Sopenharmony_ci| 类型                | 说明                      |
1217e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
1218e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1219e41f4b71Sopenharmony_ci
1220e41f4b71Sopenharmony_ci**错误码:**
1221e41f4b71Sopenharmony_ci
1222e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1223e41f4b71Sopenharmony_ci
1224e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1225e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1226e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1227e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1228e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1229e41f4b71Sopenharmony_ci
1230e41f4b71Sopenharmony_ci**示例:**
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ci```ts
1233e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1234e41f4b71Sopenharmony_ci
1235e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1236e41f4b71Sopenharmony_ci  name : string = '';
1237e41f4b71Sopenharmony_ci  width : number =  0;
1238e41f4b71Sopenharmony_ci  height : number = 0;
1239e41f4b71Sopenharmony_ci  density : number = 0;
1240e41f4b71Sopenharmony_ci  surfaceId : string = '';
1241e41f4b71Sopenharmony_ci}
1242e41f4b71Sopenharmony_ci
1243e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1244e41f4b71Sopenharmony_ci  name: 'screen01',
1245e41f4b71Sopenharmony_ci  width: 1080,
1246e41f4b71Sopenharmony_ci  height: 2340,
1247e41f4b71Sopenharmony_ci  density: 2,
1248e41f4b71Sopenharmony_ci  surfaceId: ''
1249e41f4b71Sopenharmony_ci};
1250e41f4b71Sopenharmony_ci
1251e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1252e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1253e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1254e41f4b71Sopenharmony_ci  let modeIndex: number = 0;
1255e41f4b71Sopenharmony_ci  let promise: Promise<void> = screenClass.setScreenActiveMode(modeIndex);
1256e41f4b71Sopenharmony_ci  promise.then(() => {
1257e41f4b71Sopenharmony_ci    console.info('Succeeded in setting screen active mode 0.');
1258e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
1259e41f4b71Sopenharmony_ci    console.error(`Failed to set screen active mode 0.Code:${err.code},message is ${err.message}`);
1260e41f4b71Sopenharmony_ci  });
1261e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1262e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1263e41f4b71Sopenharmony_ci});
1264e41f4b71Sopenharmony_ci```
1265e41f4b71Sopenharmony_ci
1266e41f4b71Sopenharmony_ci### setDensityDpi
1267e41f4b71Sopenharmony_ci
1268e41f4b71Sopenharmony_cisetDensityDpi(densityDpi: number, callback: AsyncCallback&lt;void&gt;): void;
1269e41f4b71Sopenharmony_ci
1270e41f4b71Sopenharmony_ci设置屏幕的像素密度,使用callback异步回调。
1271e41f4b71Sopenharmony_ci
1272e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1273e41f4b71Sopenharmony_ci
1274e41f4b71Sopenharmony_ci| 参数名     | 类型                      | 必填 | 说明                                       |
1275e41f4b71Sopenharmony_ci| ---------- | ------------------------- | ---- |------------------------------------------|
1276e41f4b71Sopenharmony_ci| densityDpi | number                    | 是   | 像素密度。支持的输入范围为[80, 640],该参数仅支持整数输入。       |
1277e41f4b71Sopenharmony_ci| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置屏幕的像素密度成功,err为undefined,否则为错误对象。 |
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ci**错误码:**
1280e41f4b71Sopenharmony_ci
1281e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1282e41f4b71Sopenharmony_ci
1283e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1284e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1285e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1286e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1287e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1288e41f4b71Sopenharmony_ci
1289e41f4b71Sopenharmony_ci**示例:**
1290e41f4b71Sopenharmony_ci
1291e41f4b71Sopenharmony_ci```ts
1292e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1293e41f4b71Sopenharmony_ci
1294e41f4b71Sopenharmony_cilet densityDpi: number = 320;
1295e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1296e41f4b71Sopenharmony_ci  name : string = '';
1297e41f4b71Sopenharmony_ci  width : number =  0;
1298e41f4b71Sopenharmony_ci  height : number = 0;
1299e41f4b71Sopenharmony_ci  density : number = 0;
1300e41f4b71Sopenharmony_ci  surfaceId : string = '';
1301e41f4b71Sopenharmony_ci}
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1304e41f4b71Sopenharmony_ci  name: 'screen01',
1305e41f4b71Sopenharmony_ci  width: 1080,
1306e41f4b71Sopenharmony_ci  height: 2340,
1307e41f4b71Sopenharmony_ci  density: 2,
1308e41f4b71Sopenharmony_ci  surfaceId: ''
1309e41f4b71Sopenharmony_ci};
1310e41f4b71Sopenharmony_ci
1311e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1312e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1313e41f4b71Sopenharmony_ci  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1314e41f4b71Sopenharmony_ci  screenClass.setDensityDpi(densityDpi, (err: BusinessError) => {
1315e41f4b71Sopenharmony_ci    const errCode: number = err.code;
1316e41f4b71Sopenharmony_ci    if (errCode) {
1317e41f4b71Sopenharmony_ci      console.error(`Failed to set the pixel density of the screen to 320. Code:${err.code},message is ${err.message}`);
1318e41f4b71Sopenharmony_ci      return;
1319e41f4b71Sopenharmony_ci    }
1320e41f4b71Sopenharmony_ci    console.info('Succeeded in setting the vertical orientation.');
1321e41f4b71Sopenharmony_ci  });
1322e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1323e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1324e41f4b71Sopenharmony_ci});
1325e41f4b71Sopenharmony_ci```
1326e41f4b71Sopenharmony_ci
1327e41f4b71Sopenharmony_ci### setDensityDpi
1328e41f4b71Sopenharmony_ci
1329e41f4b71Sopenharmony_cisetDensityDpi(densityDpi: number): Promise&lt;void&gt;
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci设置屏幕的像素密度,使用Promise异步回调。
1332e41f4b71Sopenharmony_ci
1333e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1334e41f4b71Sopenharmony_ci
1335e41f4b71Sopenharmony_ci| 参数名     | 类型   | 必填 | 说明                                 |
1336e41f4b71Sopenharmony_ci| ---------- | ------ | ---- |------------------------------------|
1337e41f4b71Sopenharmony_ci| densityDpi | number | 是   | 像素密度。支持的输入范围为[80, 640],该参数仅支持整数输入。 |
1338e41f4b71Sopenharmony_ci
1339e41f4b71Sopenharmony_ci**返回值:**
1340e41f4b71Sopenharmony_ci
1341e41f4b71Sopenharmony_ci| 类型                | 说明                      |
1342e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
1343e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1344e41f4b71Sopenharmony_ci
1345e41f4b71Sopenharmony_ci**错误码:**
1346e41f4b71Sopenharmony_ci
1347e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[屏幕错误码](errorcode-display.md)。
1348e41f4b71Sopenharmony_ci
1349e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1350e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1351e41f4b71Sopenharmony_ci| 202     | Permission verification failed. A non-system application calls a system API.|
1352e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1353e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. |
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ci**示例:**
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_ci```ts
1358e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1359e41f4b71Sopenharmony_ci
1360e41f4b71Sopenharmony_cilet densityDpi: number = 320;
1361e41f4b71Sopenharmony_ciclass VirtualScreenOption {
1362e41f4b71Sopenharmony_ci  name : string = '';
1363e41f4b71Sopenharmony_ci  width : number =  0;
1364e41f4b71Sopenharmony_ci  height : number = 0;
1365e41f4b71Sopenharmony_ci  density : number = 0;
1366e41f4b71Sopenharmony_ci  surfaceId : string = '';
1367e41f4b71Sopenharmony_ci}
1368e41f4b71Sopenharmony_ci
1369e41f4b71Sopenharmony_cilet option : VirtualScreenOption = {
1370e41f4b71Sopenharmony_ci  name: 'screen01',
1371e41f4b71Sopenharmony_ci  width: 1080,
1372e41f4b71Sopenharmony_ci  height: 2340,
1373e41f4b71Sopenharmony_ci  density: 2,
1374e41f4b71Sopenharmony_ci  surfaceId: ''
1375e41f4b71Sopenharmony_ci};
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ciscreen.createVirtualScreen(option).then((data: screen.Screen) => {
1378e41f4b71Sopenharmony_ci  let screenClass: screen.Screen = data;
1379e41f4b71Sopenharmony_ci  let promise: Promise<void> = screenClass.setDensityDpi(densityDpi);
1380e41f4b71Sopenharmony_ci  promise.then(() => {
1381e41f4b71Sopenharmony_ci    console.info('Succeeded in setting the pixel density of the screen to 320.');
1382e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
1383e41f4b71Sopenharmony_ci    console.error(`Failed to set the pixel density of the screen to 320. Code:${err.code},message is ${err.message}`);
1384e41f4b71Sopenharmony_ci  });
1385e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1386e41f4b71Sopenharmony_ci  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1387e41f4b71Sopenharmony_ci});
1388e41f4b71Sopenharmony_ci```
1389e41f4b71Sopenharmony_ci
1390e41f4b71Sopenharmony_ci## Orientation
1391e41f4b71Sopenharmony_ci
1392e41f4b71Sopenharmony_ci屏幕方向枚举。
1393e41f4b71Sopenharmony_ci
1394e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1395e41f4b71Sopenharmony_ci
1396e41f4b71Sopenharmony_ci| 名称               | 值   | 说明                             |
1397e41f4b71Sopenharmony_ci| ------------------ | ---- | -------------------------------- |
1398e41f4b71Sopenharmony_ci| UNSPECIFIED        | 0    | 表示未指定屏幕方向,由系统指定。 |
1399e41f4b71Sopenharmony_ci| VERTICAL           | 1    | 表示指定屏幕为垂直方向。         |
1400e41f4b71Sopenharmony_ci| HORIZONTAL         | 2    | 表示指定屏幕为水平方向。         |
1401e41f4b71Sopenharmony_ci| REVERSE_VERTICAL   | 3    | 表示指定屏幕为反向垂直方向。     |
1402e41f4b71Sopenharmony_ci| REVERSE_HORIZONTAL | 4    | 表示指定屏幕为反向水平方向。     |
1403e41f4b71Sopenharmony_ci
1404e41f4b71Sopenharmony_ci## ScreenSourceMode<sup>10+</sup>
1405e41f4b71Sopenharmony_ci
1406e41f4b71Sopenharmony_ci屏幕显示内容来源模式枚举。
1407e41f4b71Sopenharmony_ci
1408e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1409e41f4b71Sopenharmony_ci
1410e41f4b71Sopenharmony_ci| 名称               | 值   | 说明                             |
1411e41f4b71Sopenharmony_ci| ------------------ | ---- | -------------------------------- |
1412e41f4b71Sopenharmony_ci| SCREEN_MAIN         | 0    | 表示屏幕为默认主屏。 |
1413e41f4b71Sopenharmony_ci| SCREEN_MIRROR       | 1    | 表示屏幕内容来自镜像。         |
1414e41f4b71Sopenharmony_ci| SCREEN_EXTEND       | 2    | 表示屏幕内容来自扩展。         |
1415e41f4b71Sopenharmony_ci| SCREEN_ALONE        | 3    | 表示屏幕为未指定来源。     |
1416e41f4b71Sopenharmony_ci
1417e41f4b71Sopenharmony_ci## ScreenModeInfo
1418e41f4b71Sopenharmony_ci
1419e41f4b71Sopenharmony_ci屏幕显示模式信息。
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1422e41f4b71Sopenharmony_ci
1423e41f4b71Sopenharmony_ci| 名称        | 类型 | 可读 | 可写 | 说明                                               |
1424e41f4b71Sopenharmony_ci| ----------- | -------- | ---- | ---- | -------------------------------------------------- |
1425e41f4b71Sopenharmony_ci| id          | number   | 是   | 是   | 模式id,所支持的模式由具体设备分辨率和刷新率决定,该参数应为整数。 | 
1426e41f4b71Sopenharmony_ci| width       | number   | 是   | 是   | 屏幕的宽度,单位为px,该参数应为整数。                                |
1427e41f4b71Sopenharmony_ci| height      | number   | 是   | 是   | 屏幕的高度,单位为px,该参数应为整数。                                |
1428e41f4b71Sopenharmony_ci| refreshRate | number   | 是   | 是   | 屏幕的刷新率,单位为hz,该参数应为整数。                                     |