| Promise<Array<[Display](#display)>> | Promise used to return all the display objects.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | ----------------------- |
| 1400001 | Invalid display or screen. |
**Example**
```js
letpromise=display.getAllDisplay();
letdisplayClass=null;
letpromise=display.getAllDisplays();
promise.then((data)=>{
displayClass=data;
console.info('Succeeded in obtaining all the display objects. Data: '+JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain all the display objects. Code: '+JSON.stringify(err));
...
...
@@ -195,7 +172,7 @@ promise.then((data) => {
hasPrivateWindow(displayId: number): boolean
Checks whether there is a visible privacy window on a display. The privacy window can be set by calling `[setPrivacyMode](js-apis-window.md#setprivacymode7)`. The content in the privacy window cannot be captured or recorded.
Checks whether there is a visible privacy window on a display. The privacy window can be set by calling [setWindowPrivacyMode()](js-apis-window.md#setwindowprivacymode9). The content in the privacy window cannot be captured or recorded.
**System API**: This is a system API.
...
...
@@ -211,30 +188,41 @@ Checks whether there is a visible privacy window on a display. The privacy windo
|boolean | Whether there is a visible privacy window on the display.<br>The value `true` means that there is a visible privacy window on the display, and `false` means the opposite.<br>|
|boolean | Whether there is a visible privacy window on the display.<br>The value **true** means that there is a visible privacy window on the display, and **false** means the opposite.<br>|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| 1400003 | This display manager service works abnormally. |
**Example**
```js
vardisplayClass=null;
display.getDefaultDisplay((err,data)=>{
if(err.code){
console.error('Failed to obtain the default display object. Code: '+JSON.stringify(err));
letdisplayClass=null;
try{
displayClass=display.getDefaultDisplaySync();
}catch(exception){
console.error('Failed to obtain the default display object. Code: '+JSON.stringify(exception));
return;
}
console.info('Succeeded in obtaining the default display object. Data:'+JSON.stringify(data));
displayClass=data;
});
varret=display.hasPrivateWindow(displayClass.id);
};
letret=undefined;
try{
ret=display.hasPrivateWindow(displayClass.id);
}catch(exception){
console.error('Failed to check has privateWindow or not. Code: '+JSON.stringify(exception));
};
if(ret==undefined){
console.log("Failed to check has privateWindow or not.");
console.log("Failed to check has privateWindow or not.");
}
if(ret){
console.log("There has privateWindow.");
}elseif(!ret){
console.log("There has no privateWindow.");
}
};
```
## display.on('add'|'remove'|'change')
...
...
@@ -249,16 +237,20 @@ Subscribes to display changes.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type.<br>- **add**, indicating the display addition event.<br>- **remove**, indicating the display removal event.<br>- **change**, indicating the display change event.|
| type | string | Yes| Event type.<br>- **add**, indicating the display addition event. Example: event indicating that a display is connected to a PC.<br>- **remove**, indicating the display removal event. Example: event that a display is disconnected from a PC.<br>- **change**, indicating the display change event. Example: event that the display orientation is changed.|
| callback | Callback<number> | Yes| Callback used to return the ID of the display.|
console.error('Failed to register callback. Code: '+JSON.stringify(exception));
};
```
## display.off('add'|'remove'|'change')
...
...
@@ -271,21 +263,147 @@ Unsubscribes from display changes.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type.<br>- **add**, indicating the display addition event.<br>- **remove**, indicating the display removal event.<br>- **change**, indicating the display change event.|
| callback | Callback<number> | No| Callback used to return the ID of the display.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type.<br>- **add**, indicating the display addition event. Example: event indicating that a display is connected to a PC.<br>- **remove**, indicating the display removal event. Example: event that a display is disconnected from a PC.<br>- **change**, indicating the display change event. Example: event that the display orientation is changed.|
| callback | Callback<number> | No| Callback used to return the ID of the display.|
**Example**
```js
try{
display.off("remove");
}catch(exception){
console.error('Failed to unregister callback. Code: '+JSON.stringify(exception));
Obtains the default display object. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDefaultDisplaySync()](#displaygetdefaultdisplaysync9) instead.
Obtains the default display object. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDefaultDisplaySync()](#displaygetdefaultdisplaysync9) instead.
Obtains all display objects. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllDisplays()](#displaygetalldisplays9) instead.
Obtains all display objects. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllDisplays()](#displaygetalldisplays9-1) instead.
| Promise<Array<[Display](#display)>> | Promise used to return all the display objects.|
**Example**
```js
letpromise=display.getAllDisplay();
promise.then((data)=>{
console.info('Succeeded in obtaining all the display objects. Data: '+JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain all the display objects. Code: '+JSON.stringify(err));
});
```
## Display
Implements a `Display` instance, with properties and APIs defined.
Implements a **Display** instance, with properties and APIs defined.
To call an API in the following API examples, you must first use `[getAllDisplay()](#displaygetalldisplay)`, `[getDefaultDisplay()](#displaygetdefaultdisplay)`, or `[getDefaultDisplaySync()](#displaygetdefaultdisplaysync)` to obtain a `Display` instance.
Before calling any API in **Display**, you must use [getAllDisplays()](#displaygetalldisplays9) or [getDefaultDisplaySync()](#displaygetdefaultdisplaysync9) to obtain a **Display** instance.
@@ -296,7 +414,7 @@ To call an API in the following API examples, you must first use `[getAllDisplay
| alive | boolean | Yes| No| Whether the display is alive.|
| state | [DisplayState](#displaystate) | Yes| No| State of the display.|
| refreshRate | number | Yes| No| Refresh rate of the display.|
| rotation | number | Yes| No| Screen rotation angle of the display.|
| rotation | number | Yes| No| Screen rotation angle of the display.<br>The value **0** indicates that the screen of the display rotates by 0°.<br>The value **1** indicates that the screen of the display rotates by 90°.<br>The value **2** indicates that the screen of the display rotates by 180°.<br>The value **3** indicates that the screen of the display rotates by 270°.|
| width | number | Yes| No| Width of the display, in pixels.|
| height | number | Yes| No| Height of the display, in pixels.|
| densityDPI | number | Yes| No| Screen density of the display, in DPI.|
...
...
@@ -308,29 +426,46 @@ To call an API in the following API examples, you must first use `[getAllDisplay
Obtains the cutout information of the display. This API uses an asynchronous callback to return the result.
Obtains the cutout information of the display. This API uses an asynchronous callback to return the result. You are advised not to use the cutout area during application layout.
| callback | AsyncCallback<[CutoutInfo](#cutoutinfo9)> | Yes | Callback used to If the operation is successful, `err` is `undefined` and `data` is the `CutoutInfo` object obtained. Otherwise, `err` is an error object.|
| callback | AsyncCallback<[CutoutInfo](#cutoutinfo9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **CutoutInfo** object obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | ----------------------- |
| 1400001 | Invalid display or screen. |
**Example**
```js
letdisplayClass=null;
try{
displayClass=display.getDefaultDisplaySync();
}catch(exception){
console.error('Failed to obtain the default display object. Code: '+JSON.stringify(exception));
};
displayClass.getCutoutInfo((err,data)=>{
if(err.code){
console.error('Failed to get cutoutInfo. Cause: '+JSON.stringify(err));
console.error('Failed to get cutoutInfo. Code: '+JSON.stringify(err));
return;
}
console.info('Succeeded in getting cutoutInfo. data: '+JSON.stringify(data));
})
});
```
### getCutoutInfo<sup>9+</sup>
getCutoutInfo(): Promise<CutoutInfo>
Obtains the cutout information of the display. This API uses a promise to return the result.
Obtains the cutout information of the display. This API uses a promise to return the result. You are advised not to use the cutout area during application layout.
The **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.
> **NOTE**
...
...
@@ -6,6 +7,7 @@ The **Screen** module implements basic screen management. You can use the APIs o
> 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.
>
> The APIs provided by this module are system APIs.
## Modules to Import
```js
...
...
@@ -26,19 +28,28 @@ Obtains all screens. This API uses an asynchronous callback to return the result
| 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.|
| callback | Callback<number> | Yes | Callback used to return the screen ID. |
**Example**
```js
varcallback=(data)=>{
console.info('Register the callback for screen changes. Data: '+JSON.stringify(data))
try{
letcallback=(data)=>{
console.info('Succeeded in registering the callback for screen changes. Data: '+JSON.stringify(data))
};
screen.on('connect',callback);
}catch(exception){
console.error('Failed to register the callback for screen changes. Code: '+JSON.stringify(exception));
| 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.|
| callback | Callback<number> | No | Callback used to return the screen ID. |
**Example**
```js
varcallback=(data)=>{
console.info('Unregister the callback for screen changes. Data: '+JSON.stringify(data))
try{
letcallback=(data)=>{
console.info('Succeeded in unregistering the callback for screen changes. Data: '+JSON.stringify(data))
};
screen.off('connect',callback);
}catch(exception){
console.error('Failed to register the callback for screen changes. Code: '+JSON.stringify(exception));
**Required permissions**: ohos.permission.CAPTURE_SCREEN (mandatory when **VirtualScreenOption.surfaceId** is valid available only to system applications)
**Required permissions**: ohos.permission.CAPTURE_SCREEN (mandatory when **VirtualScreenOption.surfaceId** is valid; available only to system applications)
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the virtual screen is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
Sets the surface for a virtual screen. This API uses an asynchronous callback to return the result.
...
...
@@ -357,21 +513,34 @@ Sets the surface for a virtual screen. This API uses an asynchronous callback to
| surfaceId | string | Yes | Surface ID. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the virtual screen surface is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| Promise<boolean> | Promise used to return the result. If **true** is returned, auto rotate is locked. If **false** is returned, auto rotate is unlocked.|
| surfaceId | string | Yes | Yes | Surface ID of the virtual screen.|
## Screen
Implements a **Screen** instance.
Before calling any API in **Screen**, you must use **[getAllScreens()](#screengetallscreens)** or **[createVirtualScreen()](#screencreatevirtualscreen)** to obtain a **Screen** instance.
...
...
@@ -542,6 +746,7 @@ Before calling any API in **Screen**, you must use **[getAllScreens()](#screenge
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the screen orientation is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
Sets the active mode of the screen. This API uses an asynchronous callback to return the result.
...
...
@@ -600,19 +836,33 @@ Sets the active mode of the screen. This API uses an asynchronous callback to re
| modeIndex | number | Yes | Index of the mode to set. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the active mode is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
Sets the pixel density of the screen. This API uses an asynchronous callback to return the result.
...
...
@@ -652,19 +916,33 @@ Sets the pixel density of the screen. This API uses an asynchronous callback to
| densityDpi | number | Yes | Pixel density. The value ranges from 80 to 640. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the pixel density is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).