diff --git a/zh-cn/application-dev/reference/apis/js-apis-display.md b/zh-cn/application-dev/reference/apis/js-apis-display.md
index 233e4da08e39a0d93482ba0b73a315499b2fd341..4f87ddaf5507b56f86e1b073135828fdd17f111e 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-display.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-display.md
@@ -11,7 +11,6 @@
import display from '@ohos.display';
```
-
## DisplayState
显示设备的状态枚举。
@@ -65,61 +64,6 @@ import display from '@ohos.display';
| boundingRects | Array\<[Rect](#rect9)> | 是 | 否 | 挖孔、刘海等区域的边界矩形。 |
| waterfallDisplayAreaRects | [WaterfallDisplayAreaRects](#waterfalldisplayarearects9) | 是 | 否 | 瀑布屏曲面部分显示区域。 |
-## display.getDefaultDisplay
-
-getDefaultDisplay(callback: AsyncCallback<Display>): void
-
-获取当前默认的display对象,使用callback异步回调。
-
-**系统能力:** SystemCapability.WindowManager.WindowManager.Core
-
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback<[Display](#display)> | 是 | 回调函数。返回当前默认的display对象。 |
-
-**示例:**
-
-```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<Display>
-
-获取当前默认的display对象,使用Promise异步回调。
-
-**系统能力:** SystemCapability.WindowManager.WindowManager.Core
-
-**返回值:**
-
-| 类型 | 说明 |
-| ---------------------------------- | ---------------------------------------------- |
-| Promise<[Display](#display)> | Promise对象。返回当前默认的display对象。 |
-
-**示例:**
-
-```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.getDefaultDisplaySync9+
getDefaultDisplaySync(): Display
@@ -137,12 +81,16 @@ getDefaultDisplaySync(): Display
**示例:**
```js
-var displayClass = display.getDefaultDisplaySync();
+try {
+ let displayClass = display.getDefaultDisplaySync();
+} catch (exception) {
+ console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
+};
```
-## display.getAllDisplay
+## display.getAllDisplays9+
-getAllDisplay(callback: AsyncCallback<Array<Display>>): void
+getAllDisplays(callback: AsyncCallback<Array<Display>>): void
获取当前所有的display对象,使用callback异步回调。
@@ -150,14 +98,14 @@ getAllDisplay(callback: AsyncCallback<Array<Display>>): void
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
+| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
-| callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调函数。返回当前所有的display对象。 |
+| callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调函数。返回当前所有的display对象。 |
**示例:**
```js
-display.getAllDisplay((err, data) => {
+display.getAllDisplays((err, data) => {
if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
@@ -166,9 +114,9 @@ display.getAllDisplay((err, data) => {
});
```
-## display.getAllDisplay
+## display.getAllDisplays9+
-getAllDisplay(): Promise<Array<Display>>
+getAllDisplays(): Promise<Array<Display>>
获取当前所有的display对象,使用Promise异步回调。
@@ -176,14 +124,14 @@ getAllDisplay(): Promise<Array<Display>>
**返回值:**
-| 类型 | 说明 |
+| 类型 | 说明 |
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise<Array<[Display](#display)>> | Promise对象。返回当前所有的display对象。 |
**示例:**
```js
-let promise = display.getAllDisplay();
+let promise = display.getAllDisplays();
promise.then((data) => {
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err) => {
@@ -216,25 +164,27 @@ hasPrivateWindow(displayId: number): boolean
**示例:**
```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);
+try {
+ let 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')
@@ -255,10 +205,14 @@ on(type: 'add'|'remove'|'change', callback: Callback<number>): void
**示例:**
```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')
@@ -279,7 +233,129 @@ off(type: 'add'|'remove'|'change', callback?: Callback<number>): void
**示例:**
```js
-display.off("remove");
+try {
+ display.off("remove");
+} catch (exception) {
+ console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception));
+};
+```
+
+## display.getDefaultDisplay(deprecated)
+
+getDefaultDisplay(callback: AsyncCallback<Display>): void
+
+获取当前默认的display对象,使用callback异步回调。
+
+> **说明:**
+> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。
+
+**系统能力:** SystemCapability.WindowManager.WindowManager.Core
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------- | -------- | -------- |
+| callback | AsyncCallback<[Display](#display)> | 是 | 回调函数。返回当前默认的display对象。 |
+
+**示例:**
+
+```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(deprecated)
+
+getDefaultDisplay(): Promise<Display>
+
+获取当前默认的display对象,使用Promise异步回调。
+
+> **说明:**
+> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。
+
+**系统能力:** SystemCapability.WindowManager.WindowManager.Core
+
+**返回值:**
+
+| 类型 | 说明 |
+| ---------------------------------- | ---------------------------------------------- |
+| Promise<[Display](#display)> | Promise对象。返回当前默认的display对象。 |
+
+**示例:**
+
+```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.getAllDisplay(deprecated)
+
+getAllDisplay(callback: AsyncCallback<Array<Display>>): void
+
+获取当前所有的display对象,使用callback异步回调。
+
+> **说明:**
+> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9)。
+
+**系统能力:** SystemCapability.WindowManager.WindowManager.Core
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
+| callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调函数。返回当前所有的display对象。 |
+
+**示例:**
+
+```js
+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(deprecated)
+
+getAllDisplay(): Promise<Array<Display>>
+
+获取当前所有的display对象,使用Promise异步回调。
+
+> **说明:**
+> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9-1)。
+
+**系统能力:** SystemCapability.WindowManager.WindowManager.Core
+
+**返回值:**
+
+| 类型 | 说明 |
+| ----------------------------------------------- | ------------------------------------------------------- |
+| Promise<Array<[Display](#display)>> | Promise对象。返回当前所有的display对象。 |
+
+**示例:**
+
+```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
@@ -312,6 +388,8 @@ getCutoutInfo(callback: AsyncCallback<CutoutInfo>): void
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
+**参数:**
+
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback<[CutoutInfo](#cutoutinfo9)> | 是 | 回调函数。当获取信息成功,err为undefined,data为获取到的CutoutInfo对象;否则err为错误对象。 |
@@ -321,11 +399,11 @@ getCutoutInfo(callback: AsyncCallback<CutoutInfo>): void
```js
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));
-})
+});
```
### getCutoutInfo9+
getCutoutInfo(): Promise<CutoutInfo>
@@ -347,4 +425,4 @@ let promise = displayClass.getCutoutInfo();
promise.then((data) => {
console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
});
-```
\ No newline at end of file
+```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-screen.md b/zh-cn/application-dev/reference/apis/js-apis-screen.md
index 83ddfec6366a0e755b97eff377b99b62ebdd3276..4dd8fafc283b062840c37f0725871e421898da7a 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-screen.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-screen.md
@@ -87,10 +87,14 @@ on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback<number&
**示例:**
```js
-var callback = (data) => {
- console.info('Register the callback for screen changes. Data: ' + JSON.stringify(data))
+try {
+ let callback = (data) => {
+ console.info('Register 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')
@@ -111,10 +115,14 @@ off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback<numbe
**示例:**
```js
-var callback = (data) => {
- console.info('Unregister the callback for screen changes. Data: ' + JSON.stringify(data))
+try {
+ let callback = (data) => {
+ console.info('Unregister 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
@@ -135,15 +143,19 @@ makeExpand(options:Array<ExpandOption>, callback: AsyncCallback<number&
**示例:**
```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 make screens as expand-screen. Code:' + JSON.stringify(err));
+ return;
+ }
+ groupId = data;
+ console.info('Succeeded in making screens as expand-screen. Data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to make screens as expand-screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.makeExpand
@@ -169,11 +181,15 @@ makeExpand(options:Array<ExpandOption>): Promise<number>
**示例:**
```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 making screens as expand-screen. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to make screens as expand-screen. Code:' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to make screens as expand-screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.makeMirror
@@ -195,15 +211,19 @@ makeMirror(mainScreen:number, mirrorScreen:Array<number>, callback: AsyncC
**示例:**
```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 make screens as mirror-screen. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in making screens as mirror-screen. Data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.makeMirror
@@ -230,13 +250,17 @@ makeMirror(mainScreen:number, mirrorScreen:Array<number>): Promise<numb
**示例:**
```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 making screens as mirror-screen. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.createVirtualScreen
@@ -259,21 +283,25 @@ createVirtualScreen(options:VirtualScreenOption, callback: AsyncCallback<Scre
**示例:**
```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 virtual screen. Code: ' + JSON.stringify(err));
+ return;
+ }
+ screenClass = data;
+ console.info('Succeeded in creating virtual screen. Data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to create virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.createVirtualScreen
@@ -301,19 +329,23 @@ createVirtualScreen(options:VirtualScreenOption): Promise<Screen>
**示例:**
```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 virtual screen. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to create virtual screen. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to create virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.destroyVirtualScreen
@@ -334,14 +366,18 @@ destroyVirtualScreen(screenId:number, callback: AsyncCallback<void>): void
**示例:**
```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 virtual screen. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in destroying virtual screen.');
+ });
+} catch (exception) {
+ console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.destroyVirtualScreen
@@ -367,12 +403,16 @@ destroyVirtualScreen(screenId:number): Promise<void>
**示例:**
```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 virtual screen.');
+ }).catch((err) => {
+ console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.setVirtualScreenSurface
@@ -396,15 +436,19 @@ setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallb
**示例:**
```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 surface for the virtual screen. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in setting surface for the virtual screen.');
+ });
+} catch (exception) {
+ console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.setVirtualScreenSurface
@@ -433,13 +477,17 @@ setVirtualScreenSurface(screenId:number, surfaceId: string): Promise<void>
**示例:**
```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 surface for the virtual screen.');
+ }).catch((err) => {
+ console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(exception));
+};
```
## screen.isScreenRotationLocked
@@ -515,12 +563,16 @@ setScreenRotationLocked(isLocked: boolean): Promise<void>
**示例:**
```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 setting whether to lock screen rotation');
+ }).catch((err) => {
+ console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(exception));
+};
```
## screen.setScreenRotationLocked
@@ -541,14 +593,18 @@ setScreenRotationLocked(isLocked: boolean, callback: AsyncCallback<void>):
**示例:**
```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 set whether to lock screen rotation. Cause:' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in setting whether to lock screen rotation.');
+ });
+} catch (exception) {
+ console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(exception));
+};
```
## ExpandOption
@@ -609,13 +665,17 @@ setOrientation(orientation: Orientation, callback: AsyncCallback<void>): v
**示例:**
```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 Orientation VERTICAL. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in setting Orientation VERTICAL. data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to set Orientation VERTICAL. Code: ' + JSON.stringify(exception));
+};
```
### setOrientation
@@ -639,12 +699,16 @@ setOrientation(orientation: Orientation): Promise<void>
**示例:**
```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 Orientation VERTICAL. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to set Orientation VERTICAL. Cause: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to set Orientation VERTICAL. Code: ' + JSON.stringify(exception));
+};
```
### setScreenActiveMode
@@ -663,14 +727,18 @@ setScreenActiveMode(modeIndex: number, callback: AsyncCallback<void>): voi
**示例:**
```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 ScreenActiveMode 0. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in setting ScreenActiveMode 0. data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(exception));
+};
```
### setScreenActiveMode
@@ -694,13 +762,17 @@ setScreenActiveMode(modeIndex: number): Promise<void>
**示例:**
```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 ScreenActiveMode 0. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(exception));
+};
```
### setDensityDpi
@@ -719,14 +791,18 @@ setDensityDpi(densityDpi: number, callback: AsyncCallback<void>): void;
**示例:**
```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 DensityDpi 320. Code: ' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeed in setting DensityDpi 320. data: ' + JSON.stringify(data));
+ });
+} catch (exception) {
+ console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(exception));
+};
```
### setDensityDpi
@@ -750,13 +826,17 @@ setDensityDpi(densityDpi: number): Promise<void>
**示例:**
```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 DensityDpi 320. Data: ' + JSON.stringify(data));
+ }).catch((err) => {
+ console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(err));
+ });
+} catch (exception) {
+ console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(exception));
+};
```
## Orientation
diff --git a/zh-cn/application-dev/reference/apis/js-apis-screenshot.md b/zh-cn/application-dev/reference/apis/js-apis-screenshot.md
index 903b57b281a2f7e1d8ab54da0a29fd680162feea..86d42135ec5e3a9d9926cb753d4f80f57d12e24b 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-screenshot.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-screenshot.md
@@ -73,7 +73,7 @@ save(options: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>):
**示例:**
```js
- var screenshotOptions = {
+ let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
@@ -85,14 +85,18 @@ save(options: ScreenshotOptions, callback: AsyncCallback<image.PixelMap>):
"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(); // PixelMap使用完后及时释放内存
- });
+ 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(); // PixelMap使用完后及时释放内存
+ });
+ } catch (exception) {
+ console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
+ };
```
## screenshot.save
@@ -114,14 +118,18 @@ save(callback: AsyncCallback<image.PixelMap>): void
**示例:**
```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(); // PixelMap使用完后及时释放内存
- });
+ 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(); // PixelMap使用完后及时释放内存
+ });
+ } catch (exception) {
+ console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
+ };
```
## screenshot.save
@@ -149,7 +157,7 @@ save(options?: ScreenshotOptions): Promise<image.PixelMap>
**示例:**
```js
- var screenshotOptions = {
+ let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
@@ -161,11 +169,15 @@ save(options?: ScreenshotOptions): Promise<image.PixelMap>
"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(); // PixelMap使用完后及时释放内存
- }).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(); // PixelMap使用完后及时释放内存
+ }).catch((err) => {
+ console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
+ });
+ } catch (exception) {
+ console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
+ };
```