提交 7f47ffb6 编写于 作者: G Gloria

Update docs against 10212+10709+10772+9885+10665

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 ac819e96
......@@ -11,7 +11,6 @@ The **Display** module provides APIs for managing displays, such as obtaining in
import display from '@ohos.display';
```
## DisplayState
Enumerates the display states.
......@@ -65,61 +64,6 @@ Describes the cutout, which is an area that is not intended for displaying conte
| boundingRects | Array\<[Rect](#rect9)> | Yes | No | Bounding rectangle for punch holes and notches.|
| waterfallDisplayAreaRects | [WaterfallDisplayAreaRects](#waterfalldisplayarearects9) | Yes| No| Curved area on the waterfall display.|
## display.getDefaultDisplay
getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
Obtains the default display object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.|
**Example**
```js
var displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data;
});
```
## display.getDefaultDisplay
getDefaultDisplay(): Promise&lt;Display&gt;
Obtains the default display object. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value**
| Type | Description |
| ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.|
**Example**
```js
var displayClass = null;
let promise = display.getDefaultDisplay();
promise.then((data) => {
displayClass = data;
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
});
```
## display.getDefaultDisplaySync<sup>9+</sup>
getDefaultDisplaySync(): Display
......@@ -134,15 +78,28 @@ Obtains the default display object. This API returns the result synchronously.
| ------------------------------| ----------------------------------------------|
| [Display](#display) | Default display 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
var displayClass = display.getDefaultDisplaySync();
let displayClass = null;
try {
displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
```
## display.getAllDisplay
## display.getAllDisplays<sup>9+</sup>
getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
getAllDisplays(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
Obtains all display objects. This API uses an asynchronous callback to return the result.
......@@ -150,14 +107,24 @@ Obtains all display objects. This API uses an asynchronous callback to return th
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.|
| Name| Type| Mandatory| Description|
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes| Callback 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
display.getAllDisplay((err, data) => {
let displayClass = null;
display.getAllDisplays((err, data) => {
displayClass = data;
if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
......@@ -166,9 +133,9 @@ display.getAllDisplay((err, data) => {
});
```
## display.getAllDisplay
## display.getAllDisplays<sup>9+</sup>
getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
getAllDisplays(): Promise&lt;Array&lt;Display&gt;&gt;
Obtains all display objects. This API uses a promise to return the result.
......@@ -176,15 +143,25 @@ Obtains all display objects. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.|
| Type| Description|
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | 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
let promise = display.getAllDisplay();
let displayClass = null;
let promise = 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
| Type | Description |
| -------------------------------- |-----------------------------------------------------------------------|
|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).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
var displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
let displayClass = 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;
});
var ret = display.hasPrivateWindow(displayClass.id);
};
let ret = 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.");
} else if (!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&lt;number&gt; | Yes| Callback used to return the ID of the display.|
**Example**
```js
var callback = (data) => {
let callback = (data) => {
console.info('Listening enabled. Data: ' + JSON.stringify(data));
}
display.on("add", callback);
};
try {
display.on("add", callback);
} catch (exception) {
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&lt;number&gt; | 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&lt;number&gt; | 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));
};
```
## display.getDefaultDisplay<sup>(deprecated)</sup>
getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.|
**Example**
```js
let displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data;
});
```
## display.getDefaultDisplay<sup>(deprecated)</sup>
getDefaultDisplay(): Promise&lt;Display&gt;
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value**
| Type | Description |
| ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.|
**Example**
```js
let displayClass = null;
let promise = display.getDefaultDisplay();
promise.then((data) => {
displayClass = data;
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
});
```
## display.getAllDisplay<sup>(deprecated)</sup>
getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.|
**Example**
```js
display.off("remove");
display.getAllDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
});
```
## display.getAllDisplay<sup>(deprecated)</sup>
getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value**
| Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.|
**Example**
```js
let promise = 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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......@@ -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
### getCutoutInfo<sup>9+</sup>
getCutoutInfo(callback: AsyncCallback&lt;CutoutInfo&gt;): void
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[CutoutInfo](#cutoutinfo9)&gt; | 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&lt;[CutoutInfo](#cutoutinfo9)&gt; | 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
let displayClass = 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&lt;CutoutInfo&gt;
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.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......@@ -338,11 +473,26 @@ Obtains the cutout information of the display. This API uses a promise to return
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;[CutoutInfo](#cutoutinfo9)&gt; | Promise used to return the `CutoutInfo` object.|
| Promise&lt;[CutoutInfo](#cutoutinfo9)&gt; | Promise used to return the **CutoutInfo** 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
let displayClass = null;
try {
displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
let promise = displayClass.getCutoutInfo();
promise.then((data) => {
console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
......
# Screen
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
| -------- | --------------------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Screen](#screen)&gt;&gt; | Yes | Callback used to return all the **Screen** objects obtained.|
**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
var screenClass = null;
let screenClass = null;
screen.getAllScreens((err, data) => {
if (err.code) {
console.error('Failed to get all screens . Cause: ' + JSON.stringify(err));
console.error('Failed to get all screens. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in getting all screens . Data:' + JSON.stringify(data));
console.info('Succeeded in getting all screens. Data:' + JSON.stringify(data));
screenClass = data[0];
});
```
## screen.getAllScreens
getAllScreens(): Promise&lt;Array&lt;Screen&gt;&gt;
......@@ -48,22 +59,34 @@ Obtains all screens. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value**
| Type | Description |
| --------------------------------------------- | ----------------------------------------- |
| Promise&lt;Array&lt;[Screen](#screen)&gt;&gt; | Promise used to return all the **Screen** objects obtained.|
**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
var screenClass = null;
let screenClass = null;
let promise = screen.getAllScreens();
promise.then((data) => {
screenClass = data[0];
console.log('Succeeded in getting all screens . Data:'+ JSON.stringify(data));
console.log('Succeeded in getting all screens. Data:'+ JSON.stringify(data));
}).catch((err) => {
console.log('Failed to get all screens . Cause: ' + JSON.stringify(err));
console.log('Failed to get all screens. Cause: ' + JSON.stringify(err));
});
```
## screen.on('connect' | 'disconnect' | 'change')
on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback&lt;number&gt;): void
Subscribes to events related to the screen state.
......@@ -71,19 +94,27 @@ Subscribes to events related to the screen state.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ---------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;number&gt; | Yes | Callback used to return the screen ID. |
**Example**
```js
var callback = (data) => {
console.info('Register the callback for screen changes. Data: ' + JSON.stringify(data))
try {
let callback = (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));
};
screen.on("connect", callback);
```
## screen.off('connect' | 'disconnect' | 'change')
off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback&lt;number&gt;): void
Unsubscribes from events related to the screen state.
......@@ -91,20 +122,27 @@ Unsubscribes from events related to the screen state.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ---------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;number&gt; | No | Callback used to return the screen ID. |
**Example**
```js
var callback = (data) => {
console.info('Unregister the callback for screen changes. Data: ' + JSON.stringify(data))
try {
let callback = (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));
};
screen.off("connect", callback);
```
## screen.makeExpand
makeExpand(options:Array&lt;ExpandOption&gt;, callback: AsyncCallback&lt;number&gt;): void
Sets the screen to the expanded mode. This API uses an asynchronous callback to return the result.
......@@ -112,26 +150,40 @@ Sets the screen to the expanded mode. This API uses an asynchronous callback to
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------ | ---- | -------------------------------- |
| options | Array&lt;[ExpandOption](#expandoption)&gt; | Yes | Parameters for expanding the screen. |
| callback | Callback&lt;number&gt; | Yes | Callback used to return the group ID of the expanded screens.|
**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
var groupId = null;
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}], (err, data) => {
if (err.code) {
console.error('Failed to make screens as expand-screen. Cause:' + JSON.stringify(err));
return;
}
groupId = data;
console.info('Succeeded in making screens as expand-screen.Data:' + JSON.stringify(data));
});
try {
let groupId = null;
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}], (err, data) => {
if (err.code) {
console.error('Failed to expand the screen. Code:' + JSON.stringify(err));
return;
}
groupId = data;
console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to expand the screen. Code: ' + JSON.stringify(exception));
};
```
## screen.makeExpand
makeExpand(options:Array&lt;ExpandOption&gt;): Promise&lt;number&gt;
Sets the screen to the expanded mode. This API uses a promise to return the result.
......@@ -145,20 +197,35 @@ Sets the screen to the expanded mode. This API uses a promise to return the resu
| options | Array&lt;[ExpandOption](#expandoption)&gt; | Yes | Parameters for expanding the screen.|
**Return value**
| Type | Description |
| --------------------- | ----------------------------------- |
| Promise&lt;number&gt; | Promise used to return the group ID of the expanded screens.|
**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
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}]).then((data) => {
console.info('Succeeded in making screens as expand-screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as expand-screen. Cause:' + JSON.stringify(err));
});
try {
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}]).then((data) => {
console.info('Succeeded in expanding the screen. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to expand the screen. Code:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to expand the screen. Code: ' + JSON.stringify(exception));
};
```
## screen.makeMirror
makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
Sets screen mirroring. This API uses an asynchronous callback to return the result.
......@@ -173,20 +240,34 @@ Sets screen mirroring. This API uses an asynchronous callback to return the resu
| mirrorScreen | Array&lt;number&gt; | Yes | IDs of secondary screens. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the group ID of the secondary screens.|
**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
var mainScreenId = 0;
var mirrorScreenIds = [1, 2, 3];
screen.makeMirror(mainScreenId, mirrorScreenIds, (err, data) => {
if (err.code) {
console.error('Failed to make screens as mirror-screen.Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in making screens as mirror-screen.Data:' + JSON.stringify(data));
});
let mainScreenId = 0;
let mirrorScreenIds = [1, 2, 3];
try {
screen.makeMirror(mainScreenId, mirrorScreenIds, (err, data) => {
if (err.code) {
console.error('Failed to set screen mirroring. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to set screen mirroring. Code: ' + JSON.stringify(exception));
};
```
## screen.makeMirror
makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;): Promise&lt;number&gt;
Sets screen mirroring. This API uses a promise to return the result.
......@@ -201,22 +282,37 @@ Sets screen mirroring. This API uses a promise to return the result.
| mirrorScreen | Array&lt;number&gt; | Yes | IDs of secondary screens.|
**Return value**
| Type | Description |
| --------------------- | ----------------------------------- |
| Promise&lt;number&gt; | Promise used to return the group ID of the secondary screens.|
**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
var mainScreenId = 0;
var mirrorScreenIds = [1, 2, 3];
screen.makeMirror(mainScreenId, mirrorScreenIds).then((data) => {
console.info('Succeeded in making screens as mirror-screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as mirror-screen.Cause:' + JSON.stringify(err));
});
let mainScreenId = 0;
let mirrorScreenIds = [1, 2, 3];
try {
screen.makeMirror(mainScreenId, mirrorScreenIds).then((data) => {
console.info('Succeeded in setting screen mirroring. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set screen mirroring. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set screen mirroring. Code: ' + JSON.stringify(exception));
};
```
## screen.createVirtualScreen
createVirtualScreen(options:VirtualScreenOption, callback: AsyncCallback&lt;Screen&gt;): void
Creates a virtual screen. This API uses an asynchronous callback to return the result.
......@@ -232,35 +328,50 @@ Creates a virtual screen. This API uses an asynchronous callback to return the r
| options | [VirtualScreenOption](#virtualscreenoption) | Yes | Virtual screen parameters. |
| callback | AsyncCallback&lt;[Screen](#screen)&gt; | Yes | Callback used to return the created virtual screen.|
**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
var screenClass = null;
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}, (err, data) => {
if (err.code) {
console.error('Failed to create virtual screen.Cause:' + JSON.stringify(err));
return;
}
screenClass = data;
console.info('Succeeded in creating virtual screen.Data:' + JSON.stringify(data));
});
let screenClass = null;
try {
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}, (err, data) => {
if (err.code) {
console.error('Failed to create the virtual screen. Code: ' + JSON.stringify(err));
return;
}
screenClass = data;
console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to create the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.createVirtualScreen
createVirtualScreen(options:VirtualScreenOption): Promise&lt;Screen&gt;
Creates a virtual screen. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**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)
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | ------------------------ |
| options | [VirtualScreenOption](#virtualscreenoption) | Yes | Virtual screen parameters.|
......@@ -271,24 +382,38 @@ Creates a virtual screen. This API uses a promise to return the result.
| -------------------------------- | ------------------------------------- |
| Promise&lt;[Screen](#screen)&gt; | Promise used to return the created virtual screen.|
**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
var screenClass = null;
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}).then((data) => {
screenClass = data;
console.info('Succeeded in creating virtual screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to create virtual screen.Cause:' + JSON.stringify(err));
});
let screenClass = null;
try {
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}).then((data) => {
screenClass = data;
console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to create the virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to create the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.destroyVirtualScreen
destroyVirtualScreen(screenId:number, callback: AsyncCallback&lt;void&gt;): void
Destroys a virtual screen. This API uses an asynchronous callback to return the result.
......@@ -296,24 +421,39 @@ Destroys a virtual screen. This API uses an asynchronous callback to return the
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| screenId | number | Yes | Screen ID. |
| 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.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | ----------------------------- |
| 1400002 | Unauthorized operation. |
**Example**
```js
var screenId = 1;
screen.destroyVirtualScreen(screenId, (err,data) => {
if (err.code) {
console.error('Failed to destroy virtual screen.Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in destroying virtual screen.');
});
let screenId = 1;
try {
screen.destroyVirtualScreen(screenId, (err,data) => {
if (err.code) {
console.error('Failed to destroy the virtual screen. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in destroying the virtual screen.');
});
} catch (exception) {
console.error('Failed to destroy the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.destroyVirtualScreen
destroyVirtualScreen(screenId:number): Promise&lt;void&gt;
Destroys a virtual screen. This API uses a promise to return the result.
......@@ -321,26 +461,42 @@ Destroys a virtual screen. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------- |
| screenId | number | Yes | Screen ID.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | ----------------------------- |
| 1400002 | Unauthorized operation. |
**Example**
```js
var screenId = 1;
screen.destroyVirtualScreen(screenId).then((data) => {
console.info('Succeeded in destroying virtual screen.');
}).catch((err) => {
console.error('Failed to destroy virtual screen.Cause:' + JSON.stringify(err));
});
let screenId = 1;
try {
screen.destroyVirtualScreen(screenId).then((data) => {
console.info('Succeeded in destroying the virtual screen.');
}).catch((err) => {
console.error('Failed to destroy the virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to destroy the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.setVirtualScreenSurface
setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback&lt;void&gt;): void
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&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.|
**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
var screenId = 1;
var surfaceId = '2048';
screen.setVirtualScreenSurface(screenId, surfaceId, (err,data) => {
if (err.code) {
console.error('Failed to set surface for the virtual screen. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting surface for the virtual screen.');
});
let screenId = 1;
let surfaceId = '2048';
try {
screen.setVirtualScreenSurface(screenId, surfaceId, (err,data) => {
if (err.code) {
console.error('Failed to set the surface for the virtual screen. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the surface for the virtual screen.');
});
} catch (exception) {
console.error('Failed to set the surface for the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.setVirtualScreenSurface
setVirtualScreenSurface(screenId:number, surfaceId: string): Promise&lt;void&gt;
Sets the surface for a virtual screen. This API uses a promise to return the result.
......@@ -381,28 +550,44 @@ Sets the surface for a virtual screen. This API uses a promise to return the res
**Required permissions**: ohos.permission.CAPTURE_SCREEN (available only to system applications)
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------- |
| screenId | number | Yes | Screen ID. |
| surfaceId | string | Yes | Surface ID.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**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
var screenId = 1;
var surfaceId = '2048';
screen.setVirtualScreenSurface(screenId, surfaceId).then((data) => {
console.info('Succeeded in setting surface for the virtual screen.');
}).catch((err) => {
console.error('Failed to set surface for the virtual screen. Cause:' + JSON.stringify(err));
});
let screenId = 1;
let surfaceId = '2048';
try {
screen.setVirtualScreenSurface(screenId, surfaceId).then((data) => {
console.info('Succeeded in setting the surface for the virtual screen.');
}).catch((err) => {
console.error('Failed to set the surface for the virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the surface for the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.isScreenRotationLocked
isScreenRotationLocked(): Promise&lt;boolean&gt;
Checks whether auto rotate is locked. This API uses a promise to return the result.
......@@ -410,20 +595,23 @@ Checks whether auto rotate is locked. This API uses a promise to return the resu
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value**
| Type | Description |
| ---------------------- | ------------------------------------- |
| 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.|
**Example**
```js
screen.isScreenRotationLocked().then((isLocked) => {
console.info('Succeeded in getting screen rotation lock status. isLocked:'+ JSON.stringify(isLocked));
console.info('Succeeded in getting the screen rotation lock status. isLocked:'+ JSON.stringify(isLocked));
}).catch((err) => {
console.error('Failed to get screen rotation lock status. Cause:' + JSON.stringify(err));
console.error('Failed to get the screen rotation lock status. Cause:' + JSON.stringify(err));
});
```
## screen.isScreenRotationLocked
isScreenRotationLocked(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether auto rotate is locked. This API uses an asynchronous callback to return the result.
......@@ -441,14 +629,15 @@ Checks whether auto rotate is locked. This API uses an asynchronous callback to
```js
screen.isScreenRotationLocked((err, isLocked) => {
if (err.code) {
console.error('Failed to get screen rotation lock status. Cause:' + JSON.stringify(err));
console.error('Failed to get the screen rotation lock status. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in getting screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
console.info('Succeeded in getting the screen rotation lock status. isLocked:' + JSON.stringify(isLocked));
});
```
## screen.setScreenRotationLocked
setScreenRotationLocked(isLocked: boolean): Promise&lt;void&gt;
Sets whether to lock auto rotate. This API uses a promise to return the result.
......@@ -456,26 +645,34 @@ Sets whether to lock auto rotate. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------- |
| isLocked | boolean | Yes | Whether to lock auto rotate. The value **true** means to lock auto rotate, and **false** means the opposite.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
var isLocked = false;
screen.setScreenRotationLocked(isLocked).then((data) => {
console.info('Succeeded in setting whether to lock screen rotation');
}).catch((err) => {
console.error('Failed to set whether to lock screen rotation. Cause:' + JSON.stringify(err));
});
let isLocked = false;
try {
screen.setScreenRotationLocked(isLocked).then((data) => {
console.info('Succeeded in unlocking auto rotate');
}).catch((err) => {
console.error('Failed to unlock auto rotate. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to unlock auto rotate. Code: ' + JSON.stringify(exception));
};
```
## screen.setScreenRotationLocked
setScreenRotationLocked(isLocked: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets whether to lock auto rotate. This API uses an asynchronous callback to return the result.
......@@ -492,17 +689,22 @@ Sets whether to lock auto rotate. This API uses an asynchronous callback to retu
**Example**
```js
var isLocked = false;
screen.setScreenRotationLocked(isLocked, (err, data) => {
if (err.code) {
console.error('Failed to set whether to lock screen rotation. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting whether to lock screen rotation.');
});
let isLocked = false;
try {
screen.setScreenRotationLocked(isLocked, (err, data) => {
if (err.code) {
console.error('Failed to unlock auto rotate. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in unlocking auto rotate.');
});
} catch (exception) {
console.error('Failed to unlock auto rotate. Code: ' + JSON.stringify(exception));
};
```
## ExpandOption
Defines the parameters for expanding a screen.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......@@ -514,6 +716,7 @@ Defines the parameters for expanding a screen.
| startY | number | Yes | Yes | Start Y coordinate of the screen.|
## VirtualScreenOption
Defines virtual screen parameters.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......@@ -527,6 +730,7 @@ Defines virtual screen parameters.
| 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
| orientation | [Orientation](#orientation) | Yes | No | Screen orientation. |
### setOrientation
setOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
Sets the screen orientation. This API uses an asynchronous callback to return the result.
......@@ -553,17 +758,32 @@ Sets the screen orientation. This API uses an asynchronous callback to return th
| orientation | [Orientation](#orientation) | Yes | Screen orientation. |
| 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.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
screenClass.setOrientation(screen.Orientation.VERTICAL, (err, data) => {
if (err.code) {
console.error('Failed to setOrientation VERTICAL. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting Orientation VERTICAL. data: ' + JSON.stringify(data));
})
try {
screenClass.setOrientation(screen.Orientation.VERTICAL, (err, data) => {
if (err.code) {
console.error('Failed to set the vertical orientation. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the vertical orientation. data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to set the vertical orientation. Code: ' + JSON.stringify(exception));
};
```
### setOrientation
setOrientation(orientation: Orientation): Promise&lt;void&gt;
Sets the screen orientation. This API uses a promise to return the result.
......@@ -575,20 +795,36 @@ Sets the screen orientation. This API uses a promise to return the result.
| orientation | [Orientation](#orientation) | Yes | Screen orientation.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
let promise = screenClass.setOrientation(screen.Orientation.VERTICAL);
promise.then((data) => {
console.info('Succeeded in setting Orientation VERTICAL. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set Orientation VERTICAL. Cause: ' + JSON.stringify(err));
})
try {
let promise = screenClass.setOrientation(screen.Orientation.VERTICAL);
promise.then((data) => {
console.info('Succeeded in setting the vertical orientation. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set the vertical orientation. Cause: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the vertical orientation. Code: ' + JSON.stringify(exception));
};
```
### setScreenActiveMode
setScreenActiveMode(modeIndex: number, callback: AsyncCallback&lt;void&gt;): void
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&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.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
var modeIndex = 0;
screenClass.setScreenActiveMode(modeIndex, (err, data) => {
if (err.code) {
console.error('Failed to set ScreenActiveMode 0. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting ScreenActiveMode 0. data: ' + JSON.stringify(data));
})
let modeIndex = 0;
try {
screenClass.setScreenActiveMode(modeIndex, (err, data) => {
if (err.code) {
console.error('Failed to set screen active mode 0. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting screen active mode 0. data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to set screen active mode 0. Code: ' + JSON.stringify(exception));
};
```
### setScreenActiveMode
setScreenActiveMode(modeIndex: number): Promise&lt;void&gt;
Sets the active mode of the screen. This API uses a promise to return the result.
......@@ -629,18 +879,32 @@ Sets the active mode of the screen. This API uses a promise to return the result
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
var modeIndex = 0;
let promise = screenClass.setScreenActiveMode(modeIndex);
promise.then((data) => {
console.info('Succeeded in setting ScreenActiveMode 0. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set ScreenActiveMode 0. Cause: ' + JSON.stringify(err));
})
let modeIndex = 0;
try {
let promise = screenClass.setScreenActiveMode(modeIndex);
promise.then((data) => {
console.info('Succeeded in setting screen active mode 0. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set screen active mode 0. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set screen active mode 0. Code: ' + JSON.stringify(exception));
};
```
### setDensityDpi
setDensityDpi(densityDpi: number, callback: AsyncCallback&lt;void&gt;): void;
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&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.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
var densityDpi = 320;
screenClass.setDensityDpi(densityDpi, (err, data) => {
if (err.code) {
console.error('Failed to set DensityDpi 320. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeed in setting DensityDpi 320. data: ' + JSON.stringify(data));
})
let densityDpi = 320;
try {
screenClass.setDensityDpi(densityDpi, (err, data) => {
if (err.code) {
console.error('Failed to set the pixel density of the screen to 320. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeed in setting the pixel density of the screen to 320. data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to set the pixel density of the screen to 320. Code: ' + JSON.stringify(exception));
};
```
### setDensityDpi
setDensityDpi(densityDpi: number): Promise&lt;void&gt;
Sets the pixel density of the screen. This API uses a promise to return the result.
......@@ -681,18 +959,32 @@ Sets the pixel density of the screen. This API uses a promise to return the resu
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Display Error Codes](../errorcodes/errorcode-display.md).
| ID| Error Message|
| ------- | -------------------------------------------- |
| 1400003 | This display manager service works abnormally. |
**Example**
```js
var densityDpi = 320;
var promise = screenClass.setDensityDpi(densityDpi);
promise.then((data) => {
console.info('Succeeded in setting DensityDpi 320. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set DensityDpi 320. Cause: ' + JSON.stringify(err));
})
let densityDpi = 320;
try {
let promise = screenClass.setDensityDpi(densityDpi);
promise.then((data) => {
console.info('Succeeded in setting the pixel density of the screen to 320. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set the pixel density of the screen to 320. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the pixel density of the screen to 320. Code: ' + JSON.stringify(exception));
};
```
## Orientation
Enumerates the screen orientations.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......@@ -706,6 +998,7 @@ Enumerates the screen orientations.
| REVERSE_HORIZONTAL | 4 | Reverse horizontal. |
## ScreenModeInfo
Defines the screen mode information.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
......
......@@ -73,7 +73,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
**Example**
```js
var screenshotOptions = {
let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
......@@ -85,14 +85,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
"rotation": 0,
"displayId": 0
};
screenshot.save(screenshotOptions, (err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
});
try {
screenshot.save(screenshotOptions, (err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
## screenshot.save
......@@ -114,14 +118,18 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses an async
**Example**
```js
screenshot.save((err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
});
try {
screenshot.save((err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
## screenshot.save
......@@ -149,7 +157,7 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis
**Example**
```js
var screenshotOptions = {
let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
......@@ -161,11 +169,15 @@ Takes a screenshot and saves it as a **PixelMap** object. This API uses a promis
"rotation": 0,
"displayId": 0
};
let promise = screenshot.save(screenshotOptions);
promise.then((pixelMap) => {
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
}).catch((err) => {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
});
try {
let promise = screenshot.save(screenshotOptions);
promise.then((pixelMap) => {
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
}).catch((err) => {
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
因为 它太大了无法显示 source diff 。你可以改为 查看blob
# Display Error Codes
## 1400001 Invalid Display or Screen
**Error Message**
Invalid display or screen.
**Description**
This error code is reported when an invalid display, including a virtual screen, is operated.
**Possible Causes**
1. The virtual screen has not been created.
2. The virtual screen has been destroyed.
**Procedure**
1. Before operating the virtual screen, check whether the virtual screen has been created.
2. Check whether the virtual screen has been destroyed.
## 1400002 Unauthorized Operation
**Error Message**
Unauthorized operation.
**Description**
This error code is reported when the API does not have the required permissions to operate an object.
**Possible Causes**
The virtual screen object of another process is operated.
**Procedure**
Check whether unauthorized operations are performed on the object of another process. If yes, delete the operations.
## 1400003 Abnormal Display Manager Service
**Error Message**
This display manager service works abnormally.
**Description**
This error code is reported when the display manager service is abnormal.
**Possible Causes**
1. The display manager service is not started normally.
2. The bottom-layer graphics synthesis and rendering are abnormal.
**Procedure**
Try again later or restart the device.
# Window Error Codes
## 1300001 Repeated Operation
**Error Message**
Repeated operation.
**Description**
This error code is reported when a repeated operation is performed.
**Possible Causes**
The window to create already exists.
**Procedure**
Before creating a window, check whether the window already exists. If it already exists, use it directly.
## 1300002 Abnormal Window State
**Error Message**
This window state is abnormal.
**Description**
This error code is reported when you operate a window in an abnormal state, for example, a window that has been destroyed.
**Possible Causes**
The window has been destroyed when being operated.
**Procedure**
Before operating the window, check whether it exists.
## 1300003 Abnormal Window Manager Service
**Error Message**
This window manager service works abnormally.
**Description**
This error code is reported when the window manager service is abnormal.
**Possible Causes**
The internal services of the window are not started normally.
**Procedure**
Try again later or restart the device.
## 1300004 Unauthorized Operation
**Error Message**
Unauthorized operation.
**Description**
This error code is reported when the API does not have the required permissions to operate an object.
**Possible Causes**
The window object of another process is operated.
**Procedure**
Check whether unauthorized operations are performed on the object of another process. If yes, delete the operations.
## 1300005 Abnormal Window Stage
**Error Message**
This window stage is abnormal.
**Description**
This error code is reported when you operate a window stage in the abnormal state, for example, a window stage that has been destroyed.
**Possible Causes**
The window stage has been destroyed when being operated.
**Procedure**
Before operating a window stage, check whether it exists.
## 1300006 Abnormal Window Context
**Error Message**
This window context is abnormal.
**Description**
This error code is reported when you operate a window context in the abnormal state, for example, a window context that has been destroyed.
**Possible Causes**
The window context has been destroyed when being operated.
**Procedure**
Before operating the window context, check whether it exists.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册