• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.screen (Screen) (System API)
2
3The **Screen** module implements basic screen management. You can use the APIs of this module to obtain a **Screen** object, listen for screen changes, and create and destroy virtual screens.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import { screen } from '@kit.ArkUI';
15```
16
17## screen.getAllScreens
18
19getAllScreens(callback: AsyncCallback<Array<Screen>>): void
20
21Obtains all screens. This API uses an asynchronous callback to return the result.
22
23**System capability**: SystemCapability.WindowManager.WindowManager.Core
24
25**Parameters**
26
27| Name  | Type                                               | Mandatory| Description                                  |
28| -------- | --------------------------------------------------- | ---- | -------------------------------------- |
29| callback | AsyncCallback<Array<[Screen](#screen)>> | Yes  | Callback used to return all the **Screen** objects obtained.|
30
31**Error codes**
32
33For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
34
35| ID| Error Message|
36| ------- | ----------------------- |
37| 202     | Permission verification failed. A non-system application calls a system API.|
38| 1400001 | Invalid display or screen. |
39
40**Example**
41
42```ts
43import { BusinessError } from '@kit.BasicServicesKit';
44
45let screenClass: screen.Screen | null = null;
46screen.getAllScreens((err: BusinessError, data: Array<screen.Screen>) => {
47  const errCode: number = err.code;
48  if (errCode) {
49    console.error(`Failed to get all screens. Code:${err.code},message is ${err.message}`);
50    return;
51  }
52  console.info('Succeeded in getting all screens. Data:' + JSON.stringify(data));
53  screenClass = data[0];
54});
55```
56
57## screen.getAllScreens
58
59getAllScreens(): Promise&lt;Array&lt;Screen&gt;&gt;
60
61Obtains all screens. This API uses a promise to return the result.
62
63**System capability**: SystemCapability.WindowManager.WindowManager.Core
64
65**Return value**
66
67| Type                                         | Description                                     |
68| --------------------------------------------- | ----------------------------------------- |
69| Promise&lt;Array&lt;[Screen](#screen)&gt;&gt; | Promise used to return all the **Screen** objects obtained.|
70
71**Error codes**
72
73For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
74
75| ID| Error Message|
76| ------- | ----------------------- |
77| 202     | Permission verification failed. A non-system application calls a system API.|
78| 1400001 | Invalid display or screen. |
79
80**Example**
81
82```ts
83import { BusinessError } from '@kit.BasicServicesKit';
84
85let screenClass: screen.Screen | null = null;
86let promise: Promise<Array<screen.Screen>> = screen.getAllScreens();
87promise.then((data: Array<screen.Screen>) => {
88  screenClass = data[0];
89  console.log('Succeeded in getting all screens. Data:' + JSON.stringify(data));
90}).catch((err: BusinessError) => {
91  console.log('Failed to get all screens. Cause: ' + JSON.stringify(err));
92});
93```
94
95## screen.on('connect' | 'disconnect' | 'change')
96
97on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback&lt;number&gt;): void
98
99Subscribes to events related to the screen state.
100
101**System capability**: SystemCapability.WindowManager.WindowManager.Core
102
103**Parameters**
104
105| Name   | Type                  | Mandatory| Description                                                       |
106| --------- | ---------------------- | ---- | ----------------------------------------------------------- |
107| eventType | string                 | Yes  | Event type.<br>- **connect**: an event indicating that the screen is connected.<br>- **disconnect**: an event indicating that the screen is disconnected.<br>- **change**: an event indicating that the screen state changes.|
108| callback  | Callback&lt;number&gt; | Yes  | Callback used to return the screen ID, which is an integer.                                   |
109
110**Error codes**
111
112For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
113
114| ID| Error Message|
115| ------- | ----------------------- |
116| 202     | Permission verification failed. A non-system application calls a system API.|
117| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
118
119**Example**
120
121```ts
122let callback: Callback<number> = (data: number) => {
123  console.info('Succeeded in registering the callback for screen changes. Data: ' + JSON.stringify(data))
124};
125screen.on('connect', callback);
126```
127
128## screen.off('connect' | 'disconnect' | 'change')
129
130off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback&lt;number&gt;): void
131
132Unsubscribes from events related to the screen state.
133
134**System capability**: SystemCapability.WindowManager.WindowManager.Core
135
136**Parameters**
137
138| Name   | Type                  | Mandatory| Description                                                        |
139| --------- | ---------------------- | ---- | ------------------------------------------------------------ |
140| eventType | string                 | Yes  | Event type.<br>- **connect**: an event indicating that the screen is connected.<br>- **disconnect**: an event indicating that the screen is disconnected.<br>- **change**: an event indicating that the screen state changes.|
141| callback  | Callback&lt;number&gt; | No  | Callback used to return the screen ID, which is an integer.                                    |
142
143**Error codes**
144
145For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
146
147| ID| Error Message|
148| ------- | ----------------------- |
149| 202     | Permission verification failed. A non-system application calls a system API.|
150| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
151
152**Example**
153
154```ts
155let callback: Callback<number> = (data: number) => {
156  console.info('Succeeded in unregistering the callback for screen changes. Data: ' + JSON.stringify(data))
157};
158screen.off('connect', callback);
159screen.off('connect');
160```
161
162## screen.makeExpand
163
164makeExpand(options:Array&lt;ExpandOption&gt;, callback: AsyncCallback&lt;number&gt;): void
165
166Sets the screen to the expanded mode. This API uses an asynchronous callback to return the result.
167
168**System capability**: SystemCapability.WindowManager.WindowManager.Core
169
170**Parameters**
171
172| Name  | Type                                      | Mandatory| Description                        |
173| -------- | ------------------------------------------ | ---- |----------------------------|
174| options  | Array&lt;[ExpandOption](#expandoption)&gt; | Yes  | Parameters for expanding the screen.              |
175| callback | AsyncCallback&lt;number&gt;                     | Yes  | Callback used to return the group ID of the expanded screens, which is an integer.|
176
177**Error codes**
178
179For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
180
181| ID| Error Message|
182| ------- | ----------------------- |
183| 202     | Permission verification failed. A non-system application calls a system API.|
184| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
185| 1400001 | Invalid display or screen. |
186
187**Example**
188
189```ts
190import { BusinessError } from '@kit.BasicServicesKit';
191
192let groupId: number | null = null;
193class ExpandOption {
194  screenId: number = 0;
195  startX: number = 0;
196  startY: number = 0;
197}
198let mainScreenOption: ExpandOption = { screenId: 0, startX: 0, startY: 0 };
199let otherScreenOption: ExpandOption = { screenId: 1, startX: 1080, startY: 0 };
200let expandOptionArray : ExpandOption[] = [ mainScreenOption, otherScreenOption ];
201screen.makeExpand(expandOptionArray, (err: BusinessError, data: number) => {
202  const errCode: number = err.code;
203  if (errCode) {
204    console.error(`Failed to expand the screen. Code:${err.code},message is ${err.message}`);
205    return;
206  }
207  groupId = data;
208  console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
209});
210```
211
212## screen.makeExpand
213
214makeExpand(options:Array&lt;ExpandOption&gt;): Promise&lt;number&gt;
215
216Sets the screen to the expanded mode. This API uses a promise to return the result.
217
218**System capability**: SystemCapability.WindowManager.WindowManager.Core
219
220**Parameters**
221
222| Name | Type                                      | Mandatory| Description                    |
223| ------- | ------------------------------------------ | ---- | ------------------------ |
224| options | Array&lt;[ExpandOption](#expandoption)&gt; | Yes  | Parameters for expanding the screen.|
225
226**Return value**
227
228| Type                 | Description                             |
229| --------------------- |---------------------------------|
230| Promise&lt;number&gt; | Promise used to return the group ID of the expanded screens, which is an integer.|
231
232**Error codes**
233
234For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
235
236| ID| Error Message|
237| ------- | ----------------------- |
238| 202     | Permission verification failed. A non-system application calls a system API.|
239| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
240| 1400001 | Invalid display or screen. |
241
242**Example**
243
244```ts
245import { BusinessError } from '@kit.BasicServicesKit';
246
247class ExpandOption {
248  screenId: number = 0;
249  startX: number = 0;
250  startY: number = 0;
251}
252let mainScreenOption: ExpandOption = { screenId: 0, startX: 0, startY: 0 };
253let otherScreenOption: ExpandOption = { screenId: 1, startX: 1080, startY: 0 };
254let expandOptionArray : ExpandOption[] = [ mainScreenOption, otherScreenOption ];
255screen.makeExpand(expandOptionArray).then((
256  data: number) => {
257  console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
258}).catch((err: BusinessError) => {
259  console.error(`Failed to expand the screen. Code:${err.code},message is ${err.message}`);
260});
261```
262
263## screen.stopExpand<sup>10+</sup>
264
265stopExpand(expandScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;void&gt;): void
266
267Stops the expanded mode. This API uses an asynchronous callback to return the result.
268
269**System capability**: SystemCapability.WindowManager.WindowManager.Core
270
271**Parameters**
272
273| Name| Type| Mandatory| Description                                     |
274| ------------ | --------------------------- | --- |-----------------------------------------|
275| expandScreen | Array&lt;number&gt;         | Yes  |  IDs of the expanded screens. Each ID must be an integer. The size of the expandScreen array cannot exceed 1000. |
276| callback     | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the expanded mode is stopped, **err** is **undefined**; otherwise, **err** is an error object.|
277
278**Error codes**
279
280For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
281
282| ID| Error Message|
283| ------- | ----------------------- |
284| 202     | Permission verification failed. A non-system application calls a system API.|
285| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
286| 1400001 | Invalid display or screen. |
287
288**Example**
289
290```ts
291import { BusinessError } from '@kit.BasicServicesKit';
292
293let expandScreenIds: Array<number> = [1, 2, 3];
294screen.stopExpand(expandScreenIds, (err: BusinessError) => {
295  const errCode: number = err.code;
296  if (errCode) {
297    console.error(`Failed to stop expand screens. Code:${err.code},message is ${err.message}`);
298    return;
299  }
300  console.info('Succeeded in stopping expand screens.');
301});
302```
303
304## screen.stopExpand<sup>10+</sup>
305
306stopExpand(expandScreen:Array&lt;number&gt;): Promise&lt;void&gt;
307
308Stops the expanded mode. This API uses a promise to return the result.
309
310**System capability**: SystemCapability.WindowManager.WindowManager.Core
311
312**Parameters**
313
314| Name| Type| Mandatory| Description                |
315| ------------ | ------------------- | --- |--------------------|
316| expandScreen | Array&lt;number&gt; | Yes  |  IDs of the expanded screens. Each ID must be an integer. The size of the expandScreen array cannot exceed 1000.|
317
318**Return value**
319
320| Type| Description|
321| --------------------- | ----------------------- |
322| Promise&lt;void&gt; | Promise that returns no value.|
323
324**Error codes**
325
326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
327
328| ID| Error Message|
329| ------- | ----------------------- |
330| 202     | Permission verification failed. A non-system application calls a system API.|
331| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
332| 1400001 | Invalid display or screen. |
333
334**Example**
335
336```ts
337import { BusinessError } from '@kit.BasicServicesKit';
338
339let expandScreenIds: Array<number> = [1, 2, 3];
340screen.stopExpand(expandScreenIds).then(() => {
341  console.info('Succeeded in stopping expand screens.');
342}).catch((err: BusinessError) => {
343  console.error(`Failed to stop expand screens. Code:${err.code},message is ${err.message}`);
344});
345```
346
347## screen.makeMirror
348
349makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
350
351Sets screen mirroring. This API uses an asynchronous callback to return the result.
352
353**System capability**: SystemCapability.WindowManager.WindowManager.Core
354
355**Parameters**
356
357| Name      | Type                       | Mandatory| Description                |
358| ------------ | --------------------------- | ---- |--------------------|
359| mainScreen   | number                      | Yes  | ID of the primary screen. The value must be an integer. |
360| mirrorScreen | Array&lt;number&gt;         | Yes  |  IDs of secondary screens. Each ID must be an integer.|
361| callback     | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the group ID of the secondary screens, which is an integer. |
362
363**Error codes**
364
365For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
366
367| ID| Error Message|
368| ------- | ----------------------- |
369| 202     | Permission verification failed. A non-system application calls a system API.|
370| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
371| 1400001 | Invalid display or screen. |
372
373**Example**
374
375```ts
376import { BusinessError } from '@kit.BasicServicesKit';
377
378let mainScreenId: number = 0;
379let mirrorScreenIds: Array<number> = [1, 2, 3];
380screen.makeMirror(mainScreenId, mirrorScreenIds, (err: BusinessError, data: number) => {
381  const errCode: number = err.code;
382  if (errCode) {
383    console.error(`Failed to set screen mirroring. Code:${err.code},message is ${err.message}`);
384    return;
385  }
386  console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
387});
388```
389
390## screen.makeMirror
391
392makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;): Promise&lt;number&gt;
393
394Sets screen mirroring. This API uses a promise to return the result.
395
396**System capability**: SystemCapability.WindowManager.WindowManager.Core
397
398**Parameters**
399
400| Name      | Type               | Mandatory| Description                |
401| ------------ | ------------------- | ---- |--------------------|
402| mainScreen   | number              | Yes  | ID of the primary screen. The value must be an integer. |
403| mirrorScreen | Array&lt;number&gt; | Yes  | IDs of secondary screens. Each ID must be an integer.|
404
405**Return value**
406
407| Type                 | Description                             |
408| --------------------- |---------------------------------|
409| Promise&lt;number&gt; | Promise used to return the group ID of the secondary screens, which is an integer.|
410
411**Error codes**
412
413For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
414
415| ID| Error Message|
416| ------- | ----------------------- |
417| 202     | Permission verification failed. A non-system application calls a system API.|
418| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
419| 1400001 | Invalid display or screen. |
420
421**Example**
422
423```ts
424import { BusinessError } from '@kit.BasicServicesKit';
425
426let mainScreenId: number = 0;
427let mirrorScreenIds: Array<number> = [1, 2, 3];
428screen.makeMirror(mainScreenId, mirrorScreenIds).then((data: number) => {
429  console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
430}).catch((err: BusinessError) => {
431  console.error(`Failed to set screen mirroring. Code:${err.code},message is ${err.message}`);
432});
433```
434
435## screen.stopMirror<sup>10+</sup>
436
437stopMirror(mirrorScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;void&gt;): void
438
439Stops screen mirroring. This API uses an asynchronous callback to return the result.
440
441**System capability**: SystemCapability.WindowManager.WindowManager.Core
442
443**Parameters**
444
445| Name| Type| Mandatory| Description                                     |
446| ------------ | --------------------------- | --- |-----------------------------------------|
447| mirrorScreen | Array&lt;number&gt;         | Yes  |  IDs of secondary screens. Each ID must be an integer. The size of the mirrorScreen array cannot exceed 1000.|
448| callback     | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If screen mirroring is stopped, **err** is **undefined**; otherwise, **err** is an error object.|
449
450**Error codes**
451
452For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
453
454| ID| Error Message|
455| ------- | ----------------------- |
456| 202     | Permission verification failed. A non-system application calls a system API.|
457| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
458| 1400001 | Invalid display or screen. |
459
460**Example**
461
462```ts
463import { BusinessError } from '@kit.BasicServicesKit';
464
465let mirrorScreenIds: Array<number> = [1, 2, 3];
466screen.stopMirror(mirrorScreenIds, (err: BusinessError) => {
467  const errCode: number = err.code;
468  if (errCode) {
469    console.error(`Failed to stop mirror screens. Code:${err.code},message is ${err.message}`);
470    return;
471  }
472  console.info('Succeeded in stopping mirror screens.');
473});
474```
475
476## screen.stopMirror<sup>10+</sup>
477
478stopMirror(mirrorScreen:Array&lt;number&gt;): Promise&lt;void&gt;
479
480Stops screen mirroring. This API uses a promise to return the result.
481
482**System capability**: SystemCapability.WindowManager.WindowManager.Core
483
484**Parameters**
485
486| Name| Type| Mandatory| Description                |
487| ------------ | ------------------- | --- |--------------------|
488| mirrorScreen | Array&lt;number&gt; | Yes  |  IDs of secondary screens. Each ID must be an integer. The size of the mirrorScreen array cannot exceed 1000.|
489
490**Return value**
491
492| Type| Description|
493| --------------------- | ----------------------- |
494| Promise&lt;void&gt; | Promise that returns no value.|
495
496**Error codes**
497
498For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
499
500| ID| Error Message|
501| ------- | ----------------------- |
502| 202     | Permission verification failed. A non-system application calls a system API.|
503| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
504| 1400001 | Invalid display or screen. |
505
506**Example**
507
508```ts
509import { BusinessError } from '@kit.BasicServicesKit';
510
511let mirrorScreenIds: Array<number> = [1, 2, 3];
512screen.stopMirror(mirrorScreenIds).then(() => {
513  console.info('Succeeded in stopping mirror screens.');
514}).catch((err: BusinessError) => {
515  console.error(`Failed to stop mirror screens.Code:${err.code},message is ${err.message}`);
516});
517```
518
519## screen.createVirtualScreen
520
521createVirtualScreen(options:VirtualScreenOption, callback: AsyncCallback&lt;Screen&gt;): void
522
523Creates a virtual screen. This API uses an asynchronous callback to return the result.
524
525**System capability**: SystemCapability.WindowManager.WindowManager.Core
526
527**Required permissions**: ohos.permission.CAPTURE_SCREEN
528
529**Parameters**
530
531| Name  | Type                                       | Mandatory| Description                              |
532| -------- | ------------------------------------------- | ---- | ---------------------------------- |
533| options  | [VirtualScreenOption](#virtualscreenoption) | Yes  | Virtual screen parameters.          |
534| callback | AsyncCallback&lt;[Screen](#screen)&gt;      | Yes  | Callback used to return the created virtual screen.|
535
536**Error codes**
537
538For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
539
540| ID| Error Message|
541| ------- | ----------------------- |
542| 201 | Permission verification failed. |
543| 202     | Permission verification failed. A non-system application calls a system API.|
544| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
545| 1400001 | Invalid display or screen. |
546
547**Example**
548
549```ts
550import { BusinessError } from '@kit.BasicServicesKit';
551
552let screenClass: screen.Screen | null = null;
553class VirtualScreenOption {
554  name : string = '';
555  width : number =  0;
556  height : number = 0;
557  density : number = 0;
558  surfaceId : string = '';
559}
560
561let option : VirtualScreenOption = {
562  name: 'screen01',
563  width: 1080,
564  height: 2340,
565  density: 2,
566  surfaceId: ''
567};
568screen.createVirtualScreen(option, (err: BusinessError, data: screen.Screen) => {
569  const errCode: number = err.code;
570  if (errCode) {
571    console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
572    return;
573  }
574  screenClass = data;
575  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
576});
577```
578
579## screen.createVirtualScreen
580
581createVirtualScreen(options:VirtualScreenOption): Promise&lt;Screen&gt;
582
583Creates a virtual screen. This API uses a promise to return the result.
584
585**System capability**: SystemCapability.WindowManager.WindowManager.Core
586
587**Required permissions**: ohos.permission.CAPTURE_SCREEN
588
589**Parameters**
590
591| Name | Type                                       | Mandatory| Description                    |
592| ------- | ------------------------------------------- | ---- | ------------------------ |
593| options | [VirtualScreenOption](#virtualscreenoption) | Yes  | Virtual screen parameters.|
594
595**Return value**
596
597| Type                            | Description                                 |
598| -------------------------------- | ------------------------------------- |
599| Promise&lt;[Screen](#screen)&gt; | Promise used to return the created virtual screen.|
600
601**Error codes**
602
603For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
604
605| ID| Error Message|
606| ------- | ----------------------- |
607| 201 | Permission verification failed. |
608| 202     | Permission verification failed. A non-system application calls a system API.|
609| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
610| 1400001 | Invalid display or screen. |
611
612**Example**
613
614```ts
615import { BusinessError } from '@kit.BasicServicesKit';
616
617let screenClass: screen.Screen | null = null;
618class VirtualScreenOption {
619  name : string = '';
620  width : number =  0;
621  height : number = 0;
622  density : number = 0;
623  surfaceId : string = '';
624}
625
626let option : VirtualScreenOption = {
627  name: 'screen01',
628  width: 1080,
629  height: 2340,
630  density: 2,
631  surfaceId: ''
632};
633
634screen.createVirtualScreen(option).then((data: screen.Screen) => {
635  screenClass = data;
636  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
637}).catch((err: BusinessError) => {
638  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
639});
640```
641
642## screen.destroyVirtualScreen
643
644destroyVirtualScreen(screenId:number, callback: AsyncCallback&lt;void&gt;): void
645
646Destroys a virtual screen. This API uses an asynchronous callback to return the result.
647
648**System capability**: SystemCapability.WindowManager.WindowManager.Core
649
650**Parameters**
651
652| Name  | Type                     | Mandatory| Description                                                        |
653| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
654| screenId | number                    | Yes  | Screen ID. The value must be an integer.                                                  |
655| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the virtual screen is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
656
657**Error codes**
658
659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
660
661| ID| Error Message|
662| ------- | ----------------------------- |
663| 202     | Permission verification failed. A non-system application calls a system API.|
664| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
665| 1400002 | Unauthorized operation. |
666
667**Example**
668
669```ts
670import { BusinessError } from '@kit.BasicServicesKit';
671
672let screenId: number = 1;
673screen.destroyVirtualScreen(screenId, (err: BusinessError) => {
674  const errCode: number = err.code;
675  if (errCode) {
676    console.error(`Failed to destroy the virtual screen. Code:${err.code},message is ${err.message}`);
677    return;
678  }
679  console.info('Succeeded in destroying the virtual screen.');
680});
681```
682
683## screen.destroyVirtualScreen
684
685destroyVirtualScreen(screenId:number): Promise&lt;void&gt;
686
687Destroys a virtual screen. This API uses a promise to return the result.
688
689**System capability**: SystemCapability.WindowManager.WindowManager.Core
690
691**Parameters**
692
693| Name  | Type  | Mandatory| Description      |
694| -------- | ------ | ---- | ---------- |
695| screenId | number | Yes  | Screen ID. The value must be an integer.|
696
697**Return value**
698
699| Type               | Description                     |
700| ------------------- | ------------------------- |
701| Promise&lt;void&gt; | Promise that returns no value.|
702
703**Error codes**
704
705For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
706
707| ID| Error Message|
708| ------- | ----------------------------- |
709| 202     | Permission verification failed. A non-system application calls a system API.|
710| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
711| 1400002 | Unauthorized operation. |
712
713**Example**
714
715```ts
716import { BusinessError } from '@kit.BasicServicesKit';
717
718let screenId: number = 1;
719screen.destroyVirtualScreen(screenId).then(() => {
720  console.info('Succeeded in destroying the virtual screen.');
721}).catch((err: BusinessError) => {
722  console.error(`Failed to destroy the virtual screen.Code:${err.code},message is ${err.message}`);
723});
724```
725
726## screen.setVirtualScreenSurface
727
728setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback&lt;void&gt;): void
729
730Sets the surface for a virtual screen. This API uses an asynchronous callback to return the result.
731
732**System capability**: SystemCapability.WindowManager.WindowManager.Core
733
734**Required permissions**: ohos.permission.CAPTURE_SCREEN (available only to system applications)
735
736**Parameters**
737
738| Name   | Type                     | Mandatory| Description                                                        |
739| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
740| screenId  | number                    | Yes  | Screen ID. The value must be an integer.                                                  |
741| surfaceId | string                    | Yes  | Surface ID of the virtual screen. The value can be customized.                                               |
742| callback  | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the virtual screen surface is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
743
744**Error codes**
745
746For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
747
748| ID| Error Message|
749| ------- | ----------------------- |
750| 201 | Permission verification failed. |
751| 202     | Permission verification failed. A non-system application calls a system API.|
752| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
753| 1400001 | Invalid display or screen. |
754
755**Example**
756
757```ts
758import { BusinessError } from '@kit.BasicServicesKit';
759
760let screenId: number = 1;
761let surfaceId: string = '2048';
762screen.setVirtualScreenSurface(screenId, surfaceId, (err: BusinessError) => {
763  const errCode: number = err.code;
764  if (errCode) {
765    console.error(`Failed to set the surface for the virtual screen. Code:${err.code},message is ${err.message}`);
766    return;
767  }
768  console.info('Succeeded in setting the surface for the virtual screen.');
769});
770```
771
772## screen.setVirtualScreenSurface
773
774setVirtualScreenSurface(screenId:number, surfaceId: string): Promise&lt;void&gt;
775
776Sets the surface for a virtual screen. This API uses a promise to return the result.
777
778**System capability**: SystemCapability.WindowManager.WindowManager.Core
779
780**Required permissions**: ohos.permission.CAPTURE_SCREEN (available only to system applications)
781
782**Parameters**
783
784| Name   | Type  | Mandatory| Description         |
785| --------- | ------ | ---- | ------------- |
786| screenId  | number | Yes  | Screen ID. The value must be an integer.   |
787| surfaceId | string | Yes  | Surface ID of the virtual screen. The value can be customized.|
788
789**Return value**
790
791| Type               | Description                     |
792| ------------------- | ------------------------- |
793| Promise&lt;void&gt; | Promise that returns no value.|
794
795**Error codes**
796
797For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
798
799| ID| Error Message|
800| ------- | ----------------------- |
801| 201 | Permission verification failed. |
802| 202     | Permission verification failed. A non-system application calls a system API.|
803| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
804| 1400001 | Invalid display or screen. |
805
806**Example**
807
808```ts
809import { BusinessError } from '@kit.BasicServicesKit';
810
811let screenId: number = 1;
812let surfaceId: string = '2048';
813screen.setVirtualScreenSurface(screenId, surfaceId).then(() => {
814  console.info('Succeeded in setting the surface for the virtual screen.');
815}).catch((err: BusinessError) => {
816  console.error(`Failed to set the surface for the virtual screen. Code:${err.code},message is ${err.message}`);
817});
818```
819
820## screen.isScreenRotationLocked
821
822isScreenRotationLocked(): Promise&lt;boolean&gt;
823
824Checks whether auto rotate is locked. This API uses a promise to return the result.
825
826**System capability**: SystemCapability.WindowManager.WindowManager.Core
827
828**Return value**
829
830| Type                  | Description                                 |
831| ---------------------- | ------------------------------------- |
832| Promise&lt;boolean&gt; | Promise used to return the result. If **true** is returned, auto rotate is locked. If **false** is returned, auto rotate is unlocked.|
833
834**Error codes**
835
836For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
837
838| ID| Error Message|
839| ------- | ----------------------- |
840| 202     | Permission verification failed. A non-system application calls a system API.|
841
842**Example**
843
844```ts
845import { BusinessError } from '@kit.BasicServicesKit';
846
847screen.isScreenRotationLocked().then((isLocked: boolean) => {
848  console.info('Succeeded in getting the screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
849}).catch((err: BusinessError) => {
850  console.error(`Failed to get the screen rotation lock status. Code:${err.code},message is ${err.message}`);
851});
852```
853
854## screen.isScreenRotationLocked
855
856isScreenRotationLocked(callback: AsyncCallback&lt;boolean&gt;): void
857
858Checks whether auto rotate is locked. This API uses an asynchronous callback to return the result.
859
860**System capability**: SystemCapability.WindowManager.WindowManager.Core
861
862**Parameters**
863
864| Name   | Type                         | Mandatory| Description                                                        |
865| --------- | ---------------------------- | ---- | ------------------------------------------------------------ |
866| callback  | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If **true** is returned, auto rotate is locked. If **false** is returned, auto rotate is unlocked.|
867
868**Error codes**
869
870For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
871
872| ID| Error Message|
873| ------- | ----------------------- |
874| 202     | Permission verification failed. A non-system application calls a system API.|
875
876**Example**
877
878```ts
879import { BusinessError } from '@kit.BasicServicesKit';
880
881screen.isScreenRotationLocked((err: BusinessError, isLocked: boolean) => {
882const errCode: number = err.code;
883if (errCode) {
884  console.error(`Failed to get the screen rotation lock status. Code:${err.code},message is ${err.message}`);
885  return;
886}
887console.info('Succeeded in getting the screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
888});
889```
890
891## screen.setScreenRotationLocked
892
893setScreenRotationLocked(isLocked: boolean): Promise&lt;void&gt;
894
895Sets whether to lock auto rotate. This API uses a promise to return the result.
896
897**System capability**: SystemCapability.WindowManager.WindowManager.Core
898
899**Parameters**
900
901| Name   | Type  | Mandatory| Description         |
902| --------- | ------ | ---- | ------------- |
903| isLocked  | boolean | Yes  | Whether to lock auto rotate. The value **true** means to lock auto rotate, and **false** means the opposite.|
904
905**Return value**
906
907| Type               | Description                     |
908| ------------------- | ------------------------- |
909| Promise&lt;void&gt; | Promise that returns no value.|
910
911**Error codes**
912
913For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
914
915| ID| Error Message|
916| ------- | ----------------------- |
917| 202     | Permission verification failed. A non-system application calls a system API.|
918| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
919
920**Example**
921
922```ts
923import { BusinessError } from '@kit.BasicServicesKit';
924
925let isLocked: boolean = false;
926screen.setScreenRotationLocked(isLocked).then(() => {
927  console.info('Succeeded in unlocking auto rotate');
928}).catch((err: BusinessError) => {
929  console.error(`Failed to unlock auto rotate. Code:${err.code},message is ${err.message}`);
930});
931```
932
933## screen.setScreenRotationLocked
934
935setScreenRotationLocked(isLocked: boolean, callback: AsyncCallback&lt;void&gt;): void
936
937Sets whether to lock auto rotate. This API uses an asynchronous callback to return the result.
938
939**System capability**: SystemCapability.WindowManager.WindowManager.Core
940
941**Parameters**
942
943| Name   | Type                     | Mandatory| Description                                                        |
944| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
945| isLocked  | boolean                   | Yes  | Whether to lock auto rotate. The value **true** means to lock auto rotate, and **false** means the opposite.                |
946| callback  | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
947
948**Error codes**
949
950For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
951
952| ID| Error Message|
953| ------- | ----------------------- |
954| 202     | Permission verification failed. A non-system application calls a system API.|
955| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
956
957**Example**
958
959```ts
960import { BusinessError } from '@kit.BasicServicesKit';
961
962let isLocked: boolean = false;
963screen.setScreenRotationLocked(isLocked, (err: BusinessError) => {
964  const errCode: number = err.code;
965  if (errCode) {
966    console.error(`Failed to unlock auto rotate. Code:${err.code},message is ${err.message}`);
967    return;
968  }
969  console.info('Succeeded in unlocking auto rotate.');
970});
971```
972
973## ExpandOption
974
975Defines the parameters for expanding a screen.
976
977**System capability**: SystemCapability.WindowManager.WindowManager.Core
978
979| Name    | Type| Readable| Writable| Description               |
980| -------- | -------- | ---- | ---- | ------------------- |
981| screenId | number   | Yes  | Yes  | Screen ID. The value must be an integer.         |
982| startX   | number   | Yes  | Yes  | Start X coordinate of the screen. The value must be an integer.|
983| startY   | number   | Yes  | Yes  | Start Y coordinate of the screen. The value must be an integer.|
984
985## VirtualScreenOption
986
987Defines virtual screen parameters.
988
989**System capability**: SystemCapability.WindowManager.WindowManager.Core
990
991| Name     | Type| Readable| Writable| Description                      |
992| --------- | -------- | ---- | ---- |--------------------------|
993| name      | string   | Yes  | Yes  | Name of a virtual screen.              |
994| width     | number   | Yes  | Yes  | Width of the virtual screen, in px. The value must be an integer.|
995| height    | number   | Yes  | Yes  | Height of the virtual screen, in px. The value must be an integer.|
996| density   | number   | Yes  | Yes  | Density of the virtual screen, in px. The value must be a floating point number.|
997| surfaceId | string   | Yes  | Yes  | Surface ID of the virtual screen.       |
998
999## Screen
1000
1001Implements a **Screen** instance.
1002
1003Before calling any API in **Screen**, you must use **[getAllScreens()](#screengetallscreens)** or **[createVirtualScreen()](#screencreatevirtualscreen)** to obtain a **Screen** instance.
1004
1005### Attributes
1006
1007**System capability**: SystemCapability.WindowManager.WindowManager.Core
1008
1009| Name             | Type                                      | Readable| Writable| Description                                                         |
1010| ----------------- | ---------------------------------------------- | ---- | ---- |-------------------------------------------------------------|
1011| id                | number                                         | Yes  | No  | Screen ID. The value must be an integer.                                             |
1012| parent            | number                                         | Yes  | No  | ID of the group to which a screen belongs. The value must be an integer.                                         |
1013| supportedModeInfo | Array&lt;[ScreenModeInfo](#screenmodeinfo)&gt; | Yes  | No  | Mode set supported by the screen.                                                 |
1014| activeModeIndex   | number                                         | Yes  | No  | Index of the active screen mode. The current value and value range of this parameter vary according to the screen resolution, refresh rate, and device hardware. The value must be an integer.|
1015| orientation       | [Orientation](#orientation)                     | Yes  | No  | Screen orientation.                                                      |
1016| sourceMode<sup>10+</sup> | [ScreenSourceMode](#screensourcemode10)            | Yes  | No  | Source mode of the screen.                                                    |
1017
1018### setOrientation
1019
1020setOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
1021
1022Sets the screen orientation. This API uses an asynchronous callback to return the result.
1023
1024**System capability**: SystemCapability.WindowManager.WindowManager.Core
1025
1026| Name     | Type                       | Mandatory| Description                                                        |
1027| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
1028| orientation | [Orientation](#orientation) | Yes  | Screen orientation. The value must be an enumerated value of **Orientation**.               |
1029| callback    | AsyncCallback&lt;void&gt;   | Yes  | Callback used to return the result. If the screen orientation is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
1030
1031**Error codes**
1032
1033For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1034
1035| ID| Error Message|
1036| ------- | -------------------------------------------- |
1037| 202     | Permission verification failed. A non-system application calls a system API.|
1038| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
1039| 1400003 | This display manager service works abnormally. |
1040
1041**Example**
1042
1043```ts
1044import { BusinessError } from '@kit.BasicServicesKit';
1045
1046class VirtualScreenOption {
1047  name : string = '';
1048  width : number =  0;
1049  height : number = 0;
1050  density : number = 0;
1051  surfaceId : string = '';
1052}
1053
1054let option : VirtualScreenOption = {
1055  name: 'screen01',
1056  width: 1080,
1057  height: 2340,
1058  density: 2,
1059  surfaceId: ''
1060};
1061
1062screen.createVirtualScreen(option).then((data: screen.Screen) => {
1063  let screenClass: screen.Screen = data;
1064  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1065  screenClass.setOrientation(screen.Orientation.VERTICAL, (err: BusinessError) => {
1066    const errCode: number = err.code;
1067    if (errCode) {
1068      console.error(`Failed to set the vertical orientation. Code:${err.code},message is ${err.message}`);
1069      return;
1070    }
1071    console.info('Succeeded in setting the vertical orientation.');
1072  });
1073}).catch((err: BusinessError) => {
1074  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1075});
1076```
1077
1078### setOrientation
1079
1080setOrientation(orientation: Orientation): Promise&lt;void&gt;
1081
1082Sets the screen orientation. This API uses a promise to return the result.
1083
1084**System capability**: SystemCapability.WindowManager.WindowManager.Core
1085
1086| Name     | Type                       | Mandatory| Description      |
1087| ----------- | --------------------------- | ---- | ---------- |
1088| orientation | [Orientation](#orientation) | Yes  | Screen orientation. The value must be an enumerated value of **Orientation**.|
1089
1090**Return value**
1091
1092| Type               | Description                     |
1093| ------------------- | ------------------------- |
1094| Promise&lt;void&gt; | Promise that returns no value.|
1095
1096**Error codes**
1097
1098For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1099
1100| ID| Error Message|
1101| ------- | -------------------------------------------- |
1102| 202     | Permission verification failed. A non-system application calls a system API.|
1103| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
1104| 1400003 | This display manager service works abnormally. |
1105
1106**Example**
1107
1108```ts
1109import { BusinessError } from '@kit.BasicServicesKit';
1110
1111class VirtualScreenOption {
1112  name : string = '';
1113  width : number =  0;
1114  height : number = 0;
1115  density : number = 0;
1116  surfaceId : string = '';
1117}
1118
1119let option : VirtualScreenOption = {
1120  name: 'screen01',
1121  width: 1080,
1122  height: 2340,
1123  density: 2,
1124  surfaceId: ''
1125};
1126
1127screen.createVirtualScreen(option).then((data: screen.Screen) => {
1128  let screenClass: screen.Screen = data;
1129  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1130  let promise: Promise<void> = screenClass.setOrientation(screen.Orientation.VERTICAL);
1131  promise.then(() => {
1132    console.info('Succeeded in setting the vertical orientation.');
1133  }).catch((err: BusinessError) => {
1134    console.error(`Failed to set the vertical orientation. Code:${err.code},message is ${err.message}`);
1135  });
1136}).catch((err: BusinessError) => {
1137  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1138});
1139```
1140
1141### setScreenActiveMode
1142
1143setScreenActiveMode(modeIndex: number, callback: AsyncCallback&lt;void&gt;): void
1144
1145Sets the active mode of the screen. This API uses an asynchronous callback to return the result.
1146
1147**System capability**: SystemCapability.WindowManager.WindowManager.Core
1148
1149| Name   | Type                     | Mandatory| Description                                                        |
1150| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
1151| modeIndex | number                    | Yes  | Index of the mode to set. The current value and value range of this parameter vary according to the screen resolution, refresh rate, and device hardware. The value must be an integer.|
1152| callback  | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the active mode is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
1153
1154**Error codes**
1155
1156For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1157
1158| ID| Error Message|
1159| ------- | -------------------------------------------- |
1160| 202     | Permission verification failed. A non-system application calls a system API.|
1161| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1162| 1400003 | This display manager service works abnormally. |
1163
1164**Example**
1165
1166```ts
1167import { BusinessError } from '@kit.BasicServicesKit';
1168
1169class VirtualScreenOption {
1170  name : string = '';
1171  width : number =  0;
1172  height : number = 0;
1173  density : number = 0;
1174  surfaceId : string = '';
1175}
1176
1177let option : VirtualScreenOption = {
1178  name: 'screen01',
1179  width: 1080,
1180  height: 2340,
1181  density: 2,
1182  surfaceId: ''
1183};
1184
1185screen.createVirtualScreen(option).then((data: screen.Screen) => {
1186  let screenClass: screen.Screen = data;
1187  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1188  let modeIndex: number = 0;
1189  screenClass.setScreenActiveMode(modeIndex, (err: BusinessError) => {
1190    const errCode: number = err.code;
1191    if (errCode) {
1192      console.error(`Failed to set screen active mode 0. Code:${err.code},message is ${err.message}`);
1193      return;
1194    }
1195    console.info('Succeeded in setting the vertical orientation.');
1196  });
1197}).catch((err: BusinessError) => {
1198  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1199});
1200```
1201
1202### setScreenActiveMode
1203
1204setScreenActiveMode(modeIndex: number): Promise&lt;void&gt;
1205
1206Sets the active mode of the screen. This API uses a promise to return the result.
1207
1208**System capability**: SystemCapability.WindowManager.WindowManager.Core
1209
1210| Name   | Type  | Mandatory| Description      |
1211| --------- | ------ | ---- | ---------- |
1212| modeIndex | number | Yes  | Index of the mode to set. The current value and value range of this parameter vary according to the screen resolution, refresh rate, and device hardware. The value must be an integer.|
1213
1214**Return value**
1215
1216| Type               | Description                     |
1217| ------------------- | ------------------------- |
1218| Promise&lt;void&gt; | Promise that returns no value.|
1219
1220**Error codes**
1221
1222For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1223
1224| ID| Error Message|
1225| ------- | -------------------------------------------- |
1226| 202     | Permission verification failed. A non-system application calls a system API.|
1227| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1228| 1400003 | This display manager service works abnormally. |
1229
1230**Example**
1231
1232```ts
1233import { BusinessError } from '@kit.BasicServicesKit';
1234
1235class VirtualScreenOption {
1236  name : string = '';
1237  width : number =  0;
1238  height : number = 0;
1239  density : number = 0;
1240  surfaceId : string = '';
1241}
1242
1243let option : VirtualScreenOption = {
1244  name: 'screen01',
1245  width: 1080,
1246  height: 2340,
1247  density: 2,
1248  surfaceId: ''
1249};
1250
1251screen.createVirtualScreen(option).then((data: screen.Screen) => {
1252  let screenClass: screen.Screen = data;
1253  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1254  let modeIndex: number = 0;
1255  let promise: Promise<void> = screenClass.setScreenActiveMode(modeIndex);
1256  promise.then(() => {
1257    console.info('Succeeded in setting screen active mode 0.');
1258  }).catch((err: BusinessError) => {
1259    console.error(`Failed to set screen active mode 0.Code:${err.code},message is ${err.message}`);
1260  });
1261}).catch((err: BusinessError) => {
1262  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1263});
1264```
1265
1266### setDensityDpi
1267
1268setDensityDpi(densityDpi: number, callback: AsyncCallback&lt;void&gt;): void;
1269
1270Sets the pixel density of the screen. This API uses an asynchronous callback to return the result.
1271
1272**System capability**: SystemCapability.WindowManager.WindowManager.Core
1273
1274| Name    | Type                     | Mandatory| Description                                      |
1275| ---------- | ------------------------- | ---- |------------------------------------------|
1276| densityDpi | number                    | Yes  | Pixel density. The value must be an integer in the range [80, 640].      |
1277| callback   | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the pixel density is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
1278
1279**Error codes**
1280
1281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1282
1283| ID| Error Message|
1284| ------- | -------------------------------------------- |
1285| 202     | Permission verification failed. A non-system application calls a system API.|
1286| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1287| 1400003 | This display manager service works abnormally. |
1288
1289**Example**
1290
1291```ts
1292import { BusinessError } from '@kit.BasicServicesKit';
1293
1294let densityDpi: number = 320;
1295class VirtualScreenOption {
1296  name : string = '';
1297  width : number =  0;
1298  height : number = 0;
1299  density : number = 0;
1300  surfaceId : string = '';
1301}
1302
1303let option : VirtualScreenOption = {
1304  name: 'screen01',
1305  width: 1080,
1306  height: 2340,
1307  density: 2,
1308  surfaceId: ''
1309};
1310
1311screen.createVirtualScreen(option).then((data: screen.Screen) => {
1312  let screenClass: screen.Screen = data;
1313  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
1314  screenClass.setDensityDpi(densityDpi, (err: BusinessError) => {
1315    const errCode: number = err.code;
1316    if (errCode) {
1317      console.error(`Failed to set the pixel density of the screen to 320. Code:${err.code},message is ${err.message}`);
1318      return;
1319    }
1320    console.info('Succeeded in setting the vertical orientation.');
1321  });
1322}).catch((err: BusinessError) => {
1323  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1324});
1325```
1326
1327### setDensityDpi
1328
1329setDensityDpi(densityDpi: number): Promise&lt;void&gt;
1330
1331Sets the pixel density of the screen. This API uses a promise to return the result.
1332
1333**System capability**: SystemCapability.WindowManager.WindowManager.Core
1334
1335| Name    | Type  | Mandatory| Description                                |
1336| ---------- | ------ | ---- |------------------------------------|
1337| densityDpi | number | Yes  | Pixel density. The value must be an integer in the range [80, 640].|
1338
1339**Return value**
1340
1341| Type               | Description                     |
1342| ------------------- | ------------------------- |
1343| Promise&lt;void&gt; | Promise that returns no value.|
1344
1345**Error codes**
1346
1347For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md).
1348
1349| ID| Error Message|
1350| ------- | -------------------------------------------- |
1351| 202     | Permission verification failed. A non-system application calls a system API.|
1352| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.|
1353| 1400003 | This display manager service works abnormally. |
1354
1355**Example**
1356
1357```ts
1358import { BusinessError } from '@kit.BasicServicesKit';
1359
1360let densityDpi: number = 320;
1361class VirtualScreenOption {
1362  name : string = '';
1363  width : number =  0;
1364  height : number = 0;
1365  density : number = 0;
1366  surfaceId : string = '';
1367}
1368
1369let option : VirtualScreenOption = {
1370  name: 'screen01',
1371  width: 1080,
1372  height: 2340,
1373  density: 2,
1374  surfaceId: ''
1375};
1376
1377screen.createVirtualScreen(option).then((data: screen.Screen) => {
1378  let screenClass: screen.Screen = data;
1379  let promise: Promise<void> = screenClass.setDensityDpi(densityDpi);
1380  promise.then(() => {
1381    console.info('Succeeded in setting the pixel density of the screen to 320.');
1382  }).catch((err: BusinessError) => {
1383    console.error(`Failed to set the pixel density of the screen to 320. Code:${err.code},message is ${err.message}`);
1384  });
1385}).catch((err: BusinessError) => {
1386  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
1387});
1388```
1389
1390## Orientation
1391
1392Enumerates the screen orientations.
1393
1394**System capability**: SystemCapability.WindowManager.WindowManager.Core
1395
1396| Name              | Value  | Description                            |
1397| ------------------ | ---- | -------------------------------- |
1398| UNSPECIFIED        | 0    | Unspecified. The screen orientation is determined by the system.|
1399| VERTICAL           | 1    | Vertical.        |
1400| HORIZONTAL         | 2    | Horizontal.        |
1401| REVERSE_VERTICAL   | 3    | Reverse vertical.    |
1402| REVERSE_HORIZONTAL | 4    | Reverse horizontal.    |
1403
1404## ScreenSourceMode<sup>10+</sup>
1405
1406Enumerates the display content source modes of the screen.
1407
1408**System capability**: SystemCapability.WindowManager.WindowManager.Core
1409
1410| Name              | Value  | Description                            |
1411| ------------------ | ---- | -------------------------------- |
1412| SCREEN_MAIN         | 0    | The primary screen is displayed (default).|
1413| SCREEN_MIRROR       | 1    | The mirror is displayed.        |
1414| SCREEN_EXTEND       | 2    | The extended screen is displayed.        |
1415| SCREEN_ALONE        | 3    | The source is unspecified.    |
1416
1417## ScreenModeInfo
1418
1419Defines the screen mode information.
1420
1421**System capability**: SystemCapability.WindowManager.WindowManager.Core
1422
1423| Name       | Type| Readable| Writable| Description                                              |
1424| ----------- | -------- | ---- | ---- | -------------------------------------------------- |
1425| id          | number   | Yes  | Yes  | Mode ID. The supported mode is determined by the device resolution and refresh rate. The value must be an integer.|
1426| width       | number   | Yes  | Yes  | Width of the screen, in px. The value must be an integer.                               |
1427| height      | number   | Yes  | Yes  | Height of the screen, in px. The value must be an integer.                               |
1428| refreshRate | number   | Yes  | Yes  | Refresh rate of the screen, in hz. The value must be an integer.                                    |
1429