提交 4ff72de6 编写于 作者: E ester.zhou

update docs (13264)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 546daecb
......@@ -223,7 +223,10 @@ You can implement page redirection through the [page router](../reference/apis/j
.height('5%')
// Bind the onClick event to the Next button so that clicking the button redirects the user to the second page.
.onClick(() => {
router.pushUrl({ url: 'pages/second' })
router.push({ url: 'pages/second' })
// In a project of API version 9, you can use the API below instead:
// router.pushUrl({ url: 'pages/second' })
})
}
.width('100%')
......
......@@ -100,14 +100,6 @@ Unlocks the screen. This API uses an asynchronous callback to return the result.
| -------- | --------------------- | ---- | ------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
```js
......@@ -134,14 +126,6 @@ Unlocks the screen. This API uses a promise to return the result.
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
```js
......@@ -168,14 +152,6 @@ Locks the screen. This API uses an asynchronous callback to return the result.
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
```js
......@@ -204,13 +180,6 @@ Locks the screen. This API uses a promise to return the result.
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
......@@ -226,7 +195,7 @@ screenlock.lock().then((data) => {
onSystemEvent(callback: Callback&lt;SystemEvent&gt;): boolean
Registers a callback for system events related to screen locking.
Registers a callback for system events related to screen locking. This API can be called only by system screen lock applications.
**System capability**: SystemCapability.MiscServices.ScreenLock
......@@ -244,13 +213,6 @@ Registers a callback for system events related to screen locking.
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
......@@ -282,13 +244,6 @@ Sends an event to the screen lock service. This API uses an asynchronous callbac
| parameter | number | Yes | Result.<br>- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.<br>- **1**, the operation fails. For example, screen locking or unlocking fails.<br>- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite. |
**Error codes**
For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002 | The screenlock management service is abnormal. |
**Example**
......
# @ohos.systemDateTime
# @ohos.systemDateTime (System Time and Time Zone)
The **systemDateTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone.
......
# @ohos.systemTimer
# @ohos.systemTimer (System Timer)
The **systemTimer** module provides system timer features. You can use the APIs of this module to implement the alarm clock and other timer services.
......@@ -48,8 +48,6 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void
Creates a timer. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -63,23 +61,23 @@ Creates a timer. This API uses an asynchronous callback to return the result.
```js
export default {
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false
};
try {
systemTimer.createTimer(options, (error) => {
if (error) {
console.info(`Failed to create timer. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in creating timer.`);
});
} catch(e) {
console.info(`Failed to create timer. message:${e.message}, code:${e.code}`);
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false
};
try {
systemTimer.createTimer(options, (error, timerId) => {
if (error) {
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
});
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -89,8 +87,6 @@ createTimer(options: TimerOptions): Promise&lt;number&gt;
Creates a timer. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -109,21 +105,21 @@ Creates a timer. This API uses a promise to return the result.
```js
export default {
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
};
try {
systemTimer.createTimer(options).then(() => {
console.info(`Succeeded in creating timer.`);
}).catch((error) => {
console.info(`Failed to create timer. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to create timer. message:${e.message}, code:${e.code}`);
}
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
};
try {
systemTimer.createTimer(options).then((timerId) => {
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}).catch((error) => {
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -133,8 +129,6 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback&lt;void&g
Starts a timer. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -149,26 +143,26 @@ Starts a timer. This API uses an asynchronous callback to return the result.
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) {
console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
return;
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
try {
systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) {
console.info(`Failed to start timer. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in starting timer.`);
});
} catch(e) {
console.info(`Failed to start timer. message:${e.message}, code:${e.code}`);
}
console.info(`Succeeded in starting timer.`);
});
} catch(e) {
console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -178,8 +172,6 @@ startTimer(timer: number, triggerTime: number): Promise&lt;void&gt;
Starts a timer. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -199,24 +191,24 @@ Starts a timer. This API uses a promise to return the result.
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
try {
systemTimer.startTimer(timerId, triggerTime).then(() => {
console.info(`Succeeded in starting timer.`);
}).catch((error) => {
console.info(`Failed to start timer. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to start timer. message:${e.message}, code:${e.code}`);
}
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime).then(() => {
console.info(`Succeeded in starting timer.`);
}).catch((error) => {
console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -226,8 +218,6 @@ stopTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
Stops a timer. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -241,27 +231,27 @@ Stops a timer. This API uses an asynchronous callback to return the result.
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
try {
systemTimer.stopTimer(timerId, (error) => {
if (error) {
console.info(`Failed to stop timer. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in stopping timer.`);
});
} catch(e) {
console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`);
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
try {
systemTimer.stopTimer(timerId, (error) => {
if (error) {
console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
return;
}
}
console.info(`Succeeded in stopping timer.`);
});
} catch(e) {
console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -271,8 +261,6 @@ stopTimer(timer: number): Promise&lt;void&gt;
Stops a timer. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -291,25 +279,25 @@ Stops a timer. This API uses a promise to return the result.
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
try {
systemTimer.stopTimer(timerId).then(() => {
console.info(`Succeeded in stopping timer.`);
}).catch((error) => {
console.info(`Failed to stop timer. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`);
}
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
try {
systemTimer.stopTimer(timerId).then(() => {
console.info(`Succeeded in stopping timer.`);
}).catch((error) => {
console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -319,8 +307,6 @@ destroyTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
Destroys a timer. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -334,28 +320,28 @@ Destroys a timer. This API uses an asynchronous callback to return the result.
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId)
try {
systemTimer.destroyTimer(timerId, (error) => {
if (error) {
console.info(`Failed to destroy timer. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in destroying timer.`);
});
} catch(e) {
console.info(`Failed to destroying timer. message:${e.message}, code:${e.code}`);
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId);
try {
systemTimer.destroyTimer(timerId, (error) => {
if (error) {
console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in destroying timer.`);
});
} catch(e) {
console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -365,8 +351,6 @@ destroyTimer(timer: number): Promise&lt;void&gt;
Destroys a timer. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -385,25 +369,25 @@ Destroys a timer. This API uses a promise to return the result.
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId)
try {
systemTimer.destroyTimer(timerId).then(() => {
console.info(`Succeeded in destroying timer.`);
}).catch((error) => {
console.info(`Failed to destroy timer. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to destroying timer. message:${e.message}, code:${e.code}`);
}
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId);
try {
systemTimer.destroyTimer(timerId).then(() => {
console.info(`Succeeded in destroying timer.`);
}).catch((error) => {
console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
# @ohos.web.webview
# @ohos.web.webview (Webview)
The **Webview** module provides APIs for web control.
......@@ -228,19 +228,19 @@ Loads the dynamic link library (DLL) file of the web engine. This API can be cal
**Example**
The following code snippet exemplifies calling this API after the EntryAbility is created.
The following code snippet exemplifies calling this API after the MainAbility is created.
```ts
// xxx.ts
import UIAbility from '@ohos.app.ability.UIAbility';
import web_webview from '@ohos.web.webview';
import Ability from '@ohos.application.Ability'
import web_webview from '@ohos.web.webview'
export default class EntryAbility extends UIAbility {
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("EntryAbility onCreate")
console.log("MainAbility onCreate")
web_webview.WebviewController.initializeWebEngine()
globalThis.abilityWant = want
console.log("EntryAbility onCreate done")
console.log("MainAbility onCreate done")
}
}
```
......@@ -249,7 +249,7 @@ export default class EntryAbility extends UIAbility {
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import web_webview from '@ohos.web.webview'
@Entry
@Component
......@@ -1471,10 +1471,8 @@ struct WebComponent {
try {
// 1. Create two message ports.
this.ports = this.controller.createWebMessagePorts();
// 2. Send one of the message ports to the HTML side, which can then save and use the port.
this.controller.postMessage('__init_port__', [this.ports[0]], '*');
// 3. Register a callback for the other message port on the application side.
this.ports[1].onMessageEvent((result: WebMessage) => {
// 2. Register a callback on a message port (for example, port 1) on the application side.
this.ports[1].onMessageEvent((result: web_webview.WebMessage) => {
var msg = 'Got msg from HTML:';
if (typeof(result) == "string") {
console.log("received string message from html5, string is:" + result);
......@@ -1491,12 +1489,14 @@ struct WebComponent {
}
this.receivedFromHtml = msg;
})
// 3. Send another message port (for example, port 0) to the HTML side, which can then save the port for future use.
this.controller.postMessage('__init_port__', [this.ports[0]], '*');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
// 4. Use the port on the application side to send messages to the message port that has been sent to the HTML.
// 4. Use the port on the application side to send messages to the port that has been sent to the HTML side.
Button('SendDataToHTML')
.onClick(() => {
try {
......@@ -1506,7 +1506,7 @@ struct WebComponent {
console.error(`ports is null, Please initialize first`);
}
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: $rawfile('xxx.html'), controller: this.controller })
......@@ -1528,7 +1528,7 @@ struct WebComponent {
<h1>WebView Message Port Demo</h1>
<div>
<input type="button" value="SendToEts" onclick="PostMsgToEts(msgFromJS.value);"/><br/>
<input id="msgFromJs" type="text" value="send this message from HTML to ets"/><br/>
<input id="msgFromJS" type="text" value="send this message from HTML to ets"/><br/>
</div>
<p class="output">display received message send from ets</p>
</body>
......@@ -2750,6 +2750,104 @@ struct WebComponent {
}
```
### pageUp
pageUp(top:boolean): void
Scrolls the page up by half the view port or jumps to the top of the page.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| top | boolean | Yes | Whether to jump to the top of the page. The value **true** means to jump to the top of the page; and **false** means to scroll the page up by half the view port.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('pageUp')
.onClick(() => {
try {
this.controller.pageUp(false);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### pageDown
pageDown(bottom:boolean): void
Scrolls the page down by half the view port or jumps to the bottom of the page.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| bottom | boolean | Yes | Whether to jump to the bottom of the page. The value **true** means to jump to the bottom of the page; and **false** means to scroll the page down by half the view port.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('pageDown')
.onClick(() => {
try {
this.controller.pageDown(false);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getBackForwardEntries
getBackForwardEntries(): BackForwardList
......@@ -2799,6 +2897,122 @@ struct WebComponent {
}
```
### serializeWebState
serializeWebState(): Uint8Array
Serializes the page status history of the current Webview.
**System capability**: SystemCapability.Web.Webview.Core
**Return value**
| Type | Description |
| ---------- | --------------------------------------------- |
| Uint8Array | Serialized data of the page status history of the current WebView.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('serializeWebState')
.onClick(() => {
try {
let state = this.controller.serializeWebState();
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o2 | 0o100, 0o666);
fileio.writeSync(fd, state.buffer);
fileio.closeSync(fd);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### restoreWebState
restoreWebState(state: Uint8Array): void
Restores the page status history from the serialized data of the current WebView.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ---------------------------- |
| state | Uint8Array | Yes | Serialized data of the page status history.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('RestoreWebState')
.onClick(() => {
try {
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o002, 0o666);
let stat = fileio.fstatSync(fd);
let size = stat.size;
let buf = new ArrayBuffer(size);
fileio.read(fd, buf, (err, data) => {
if (data) {
this.controller.restoreWebState(new Uint8Array(data.buffer));
}
fileio.closeSync(fd);
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### customizeSchemes
static customizeSchemes(schemes: Array\<WebCustomScheme\>): void
......@@ -4001,7 +4215,7 @@ Stores this web page. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| baseName | string | Yes| Save path. The value cannot be null. |
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory. |
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise.|
**Example**
......@@ -4082,6 +4296,10 @@ Stores this web page. This API uses a promise to return the result.
Implements a **GeolocationPermissions** object.
### Required Permissions
**ohos.permission.LOCATION**, **ohos.permission.APPROXIMATELY_LOCATION**, and **ohos.permission.LOCATION_IN_BACKGROUND**, which are required for accessing the location information. For details about the permissions, see [@ohos.geolocation (Geolocation)](./js-apis-geolocation.md).
### allowGeolocation
static allowGeolocation(origin: string): void
......@@ -4469,6 +4687,8 @@ Provides the element information of the area being clicked. For details about th
Describes the data types supported for [WebMessagePort](#webmessageport).
**System capability**: SystemCapability.Web.Webview.Core
| Type | Description |
| -------- | -------------------------------------- |
| string | String type.|
......@@ -4492,10 +4712,10 @@ Provides the historical information list of the current webview.
**System capability**: SystemCapability.Web.Webview.Core
| Name | Type | Readable| Writable| Description |
| ------------ | ------ | ---- | ---- | ---------------------------- |
| currentIndex | number | Yes | No | Index of the current page in the page history stack.|
| size | number | Yes | No | Number of indexes in the history stack. |
| Name | Type | Readable| Writable| Description |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| currentIndex | number | Yes | No | Index of the current page in the page history stack. |
| size | number | Yes | No | Number of indexes in the history stack. The maximum value is 50. If this value is exceeded, the earliest index will be overwritten.|
### getItemAtIndex
......@@ -4537,8 +4757,8 @@ struct WebComponent {
try {
let list = this.controller.getBackForwardEntries();
let historyItem = list.getItemAtIndex(list.currentIndex);
console.log("HistoryItem: " + JSON.stringify(historyItem));
this.icon = historyItem.icon;
console.log("HistoryItem: " + JSON.stringify(historyItem));
this.icon = historyItem.icon;
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
......
......@@ -33,6 +33,8 @@
- Security
- [Ability Access Control Error Codes](errorcode-access-token.md)
- [HUKS Error Codes](errorcode-huks.md)
- [Crypto Framework Error Codes](errorcode-crypto-framework.md)
- [Certificate Error Codes](errorcode-cert.md)
- [User Authentication Error Codes](errorcode-useriam.md)
- Data Management
- [RDB Error Codes](errorcode-data-rdb.md)
......@@ -55,6 +57,7 @@
- [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md)
- [Input Method Framework Error Codes](errorcode-inputmethod-framework.md)
- [Pasteboard Error Codes](errorcode-pasteboard.md)
- [Time and Time Zone Service Error Codes](errorcode-time.md)
- [Webview Error Codes](errorcode-webview.md)
- Account Management
- [Account Error Codes](errorcode-account.md)
......
# Time and Time Zone Service Error Codes
## -1 Screen Unlock Error
**Error Message**
The parameter check failed or permission denied or system error.
**Description**
This error code is reported when a parameter check failure, permission verification failure, or system operation error occurs.
**Possible Cause**
1. The input parameter is invalid.
2. The required permission is not configured. For example, **ohos.permission.SET_TIME** is not configured for setting the time or **ohos.permission.SET_TIME_ZONE** is not configured for setting the time zone.
3. The system is not running properly due to a common kernel error, such as a memory allocation and multi-thread processing error.
**Solution**
1. Make sure input parameters are passed in as required.
2. Configure the **ohos.permission.SET_TIME** permission for setting the time and the **ohos.permission.SET_TIME_ZONE** permission for setting the time zone.
3. Make sure the memory is sufficient.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册