提交 a9dfb614 编写于 作者: E ester.zhou
上级 74aefb7c
无相关合并请求
......@@ -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<boolean> | 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<boolean> | 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<boolean> | 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<boolean> | 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<SystemEvent>): 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.systemTime
# @ohos.systemTime (System Time and Time Zone)
The **systemTime** 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.
......@@ -29,6 +29,14 @@ Sets the system time. This API uses an asynchronous callback to return the resul
| time | number | Yes | Timestamp to set, in milliseconds. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
......@@ -37,17 +45,17 @@ let time = 1611081385000;
try {
systemTime.setTime(time, (error) => {
if (error) {
console.info(`Failed to setting time. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in setting time`);
}console.info(`Succeeded in setting time`);
});
} catch(e) {
console.info(`Failed to set time. message:${e.message}, code:${e.code}`);
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTime<sup>(deprecated)</sup>
## systemTime.setTime
setTime(time : number) : Promise&lt;void&gt;
......@@ -69,6 +77,14 @@ Sets the system time. 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 [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
......@@ -78,58 +94,58 @@ try {
systemTime.setTime(time).then(() => {
console.info(`Succeeded in setting time.`);
}).catch((error) => {
console.info(`Failed to setting time. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to set time. message:${e.message}, code:${e.code}`);
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>(deprecated)</sup>
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since the Unix epoch. 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 [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ------------------ |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getCurrentTime(true, (error, time) => {
if (error) {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting currentTime : ${time}`);
console.info(`Succeeded in getting currentTime: ${time}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`);
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>(deprecated)</sup>
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since the Unix epoch. 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 [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-1).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -138,39 +154,43 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
| -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getCurrentTime((error, time) => {
if (error) {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting currentTime : ${time}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`);
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>(deprecated)</sup>
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
Obtains the time elapsed since the Unix epoch. 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 [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-2).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value**
......@@ -178,6 +198,14 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| --------------------- | --------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since the Unix epoch.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
......@@ -185,58 +213,58 @@ try {
systemTime.getCurrentTime().then((time) => {
console.info(`Succeeded in getting currentTime : ${time}`);
}).catch((error) => {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`);
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealActiveTime<sup>(deprecated)</sup>
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system startup, excluding the deep sleep time. 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 [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | -------------------------- |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getRealActiveTime(true, (error, time) => {
if (error) {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting real active time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealActiveTime<sup>(deprecated)</sup>
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system startup, excluding the deep sleep time. 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 [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-1).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -245,39 +273,43 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getRealActiveTime((error, time) => {
if (error) {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting real active time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealActiveTime<sup>(deprecated)</sup>
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
Obtains the time elapsed since system startup, excluding the deep sleep time. 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 [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-2).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ----------------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value**
......@@ -285,6 +317,14 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------------- | -------------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, excluding the deep sleep time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
......@@ -292,58 +332,58 @@ try {
systemTime.getRealActiveTime().then((time) => {
console.info(`Succeeded in getting real active time : ${time}`);
}).catch((error) => {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>(deprecated)</sup>
## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system startup, including the deep sleep time. 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 [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ------------------------------- |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getRealTime(true, (error, time) => {
if (error) {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting real time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>(deprecated)</sup>
## systemTime.getRealTime<sup>8+</sup>
getRealTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system startup, including the deep sleep time. 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 [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-1).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -352,39 +392,43 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getRealTime((error, time) => {
if (error) {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in getting real time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>(deprecated)</sup>
## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano?: boolean): Promise&lt;number&gt;
Obtains the time elapsed since system startup, including the deep sleep time. 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 [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-2).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).|
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value**
......@@ -392,6 +436,14 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, including the deep sleep time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
......@@ -399,14 +451,14 @@ try {
systemTime.getRealTime().then((time) => {
console.info(`Succeeded in getting real time : ${time}`);
}).catch((error) => {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`);
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setDate<sup>(deprecated)</sup>
## systemTime.setDate
setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
......@@ -423,6 +475,14 @@ Sets the system date. This API uses an asynchronous callback to return the resul
| date | Date | Yes | Target date to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
......@@ -430,17 +490,17 @@ let date = new Date();
try {
systemTime.setDate(date, (error) => {
if (error) {
console.info(`Failed to setting date. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in setting date.`);
});
} catch(e) {
console.info(`Failed to set date. message:${e.message}, code:${e.code}`);
console.info(`Failed to set date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setDate<sup>(deprecated)</sup>
## systemTime.setDate
setDate(date: Date): Promise&lt;void&gt;
......@@ -462,6 +522,14 @@ Sets the system date. 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 [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
......@@ -470,23 +538,19 @@ try {
systemTime.setDate(date).then(() => {
console.info(`Succeeded in setting date.`);
}).catch((error) => {
console.info(`Failed to setting date. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to set date. message:${e.message}, code:${e.code}`);
console.info(`Failed to set date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getDate<sup>(deprecated)</sup>
## systemTime.getDate<sup>8+</sup>
getDate(callback: AsyncCallback&lt;Date&gt;): void
Obtains the current system date. 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 [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -495,32 +559,36 @@ Obtains the current system date. This API uses an asynchronous callback to retur
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Date&gt; | Yes | Callback used to return the current system date.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getDate((error, date) => {
if (error) {
console.info(`Failed to get date. message:${error.message}, code:${error.code}`);
console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in get date : ${date}`);;
});
} catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`);
console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getDate<sup>(deprecated)</sup>
## systemTime.getDate<sup>8+</sup>
getDate(): Promise&lt;Date&gt;
Obtains the current system date. 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 [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate-1).
**System capability**: SystemCapability.MiscServices.Time
**Return value**
......@@ -529,6 +597,14 @@ Obtains the current system date. This API uses a promise to return the result.
| ------------------- | ----------------------------------------- |
| Promise&lt;Date&gt; | Promise used to return the current system date.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
......@@ -536,14 +612,14 @@ try {
systemTime.getDate().then((date) => {
console.info(`Succeeded in getting date : ${date}`);
}).catch((error) => {
console.info(`Failed to getting date. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting date. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`);
console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTimezone<sup>(deprecated)</sup>
## systemTime.setTimezone
setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -560,23 +636,31 @@ Sets the system time zone. This API uses an asynchronous callback to return the
| timezone | string | Yes | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones). |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
try {
systemTime.setTimezone('Asia/Shanghai', (error) => {
if (error) {
console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in setting timezone.`);
});
} catch(e) {
console.info(`Failed to set timezone. message:${e.message}, code:${e.code}`);
console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTimezone<sup>(deprecated)</sup>
## systemTime.setTimezone
setTimezone(timezone: string): Promise&lt;void&gt;
......@@ -598,6 +682,14 @@ Sets the system time zone. 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 [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example**
```js
......@@ -605,23 +697,19 @@ try {
systemTime.setTimezone('Asia/Shanghai').then(() => {
console.info(`Succeeded in setting timezone.`);
}).catch((error) => {
console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`);
console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to set timezone. message:${e.message}, code:${e.code}`);
console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getTimezone<sup>(deprecated)</sup>
## systemTime.getTimezone<sup>8+</sup>
getTimezone(callback: AsyncCallback&lt;string&gt;): void
Obtains the system time zone. 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 [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone).
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
......@@ -630,32 +718,36 @@ Obtains the system time zone. This API uses an asynchronous callback to return t
| -------- | --------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
try {
systemTime.getTimezone((error, data) => {
if (error) {
console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`);
console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in get timezone : ${data}`);;
});
} catch(e) {
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`);
console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getTimezone<sup>(deprecated)</sup>
## systemTime.getTimezone<sup>8+</sup>
getTimezone(): Promise&lt;string&gt;
Obtains the system time zone. 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 [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone-1).
**System capability**: SystemCapability.MiscServices.Time
**Return value**
......@@ -664,6 +756,14 @@ Obtains the system time zone. This API uses a promise to return the result.
| --------------------- | ------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example**
```js
......@@ -671,10 +771,10 @@ try {
systemTime.getTimezone().then((data) => {
console.info(`Succeeded in getting timezone: ${data}`);
}).catch((error) => {
console.info(`Failed to getting timezone. message:${error.message}, code:${error.code}`);
console.info(`Failed to getting timezone. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`);
console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
}
```
......
# @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**
......@@ -69,15 +67,15 @@ export default {
repeat: false
};
try {
systemTimer.createTimer(options, (error) => {
systemTimer.createTimer(options, (error, timerId) => {
if (error) {
console.info(`Failed to create timer. message:${error.message}, code:${error.code}`);
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in creating timer.`);
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
});
} catch(e) {
console.info(`Failed to create timer. message:${e.message}, code:${e.code}`);
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**
......@@ -115,13 +111,13 @@ export default {
repeat:false
};
try {
systemTimer.createTimer(options).then(() => {
console.info(`Succeeded in creating timer.`);
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}`);
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}`);
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**
......@@ -154,19 +148,19 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
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}`);
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(`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**
......@@ -204,17 +196,17 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
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}`);
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}`);
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**
......@@ -246,20 +236,20 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
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}`);
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}`);
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**
......@@ -296,18 +284,18 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
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}`);
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}`);
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**
......@@ -339,21 +325,21 @@ export default {
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)
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}`);
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}`);
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**
......@@ -390,19 +374,19 @@ export default {
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)
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}`);
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}`);
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 {
......@@ -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
......@@ -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.|
......@@ -4493,9 +4713,9 @@ 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. |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| 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
......
......@@ -1219,7 +1219,7 @@ The universal events are not supported.
onAlert(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
Triggered when **alert()** is invoked to display an alert dialog box on the web page.
Called when **alert()** is invoked to display an alert dialog box on the web page.
**Parameters**
......@@ -1233,7 +1233,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
**Example**
......@@ -1277,7 +1277,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web
onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
Triggered when this page is about to exit after the user refreshes or closes the page. This callback is triggered only when the page has obtained focus.
Called when this page is about to exit after the user refreshes or closes the page. This API takes effect only when the page has obtained focus.
**Parameters**
......@@ -1291,7 +1291,7 @@ Triggered when this page is about to exit after the user refreshes or closes the
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
**Example**
......@@ -1338,7 +1338,7 @@ Triggered when this page is about to exit after the user refreshes or closes the
onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
Triggered when **confirm()** is invoked by the web page.
Called when **confirm()** is invoked by the web page.
**Parameters**
......@@ -1352,7 +1352,7 @@ Triggered when **confirm()** is invoked by the web page.
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
**Example**
......@@ -1412,7 +1412,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|
| boolean | If the callback returns **true**, the application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **\<Web>** component to exit the current page based on the user operation. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
**Example**
......@@ -1460,7 +1460,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
onConsole(callback: (event?: { message: ConsoleMessage }) => boolean)
Triggered to notify the host application of a JavaScript console message.
Called to notify the host application of a JavaScript console message.
**Parameters**
......@@ -1539,7 +1539,7 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp
onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResourceError }) => void)
Triggered when an error occurs during web page loading. For better results, simplify the implementation logic in the callback.
Called when an error occurs during web page loading. For better results, simplify the implementation logic in the callback.
**Parameters**
......@@ -1583,7 +1583,7 @@ Triggered when an error occurs during web page loading. For better results, simp
onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: WebResourceResponse }) => void)
Triggered when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.
Called when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.
**Parameters**
......@@ -1635,7 +1635,7 @@ Triggered when an HTTP error (the response code is greater than or equal to 400)
onPageBegin(callback: (event?: { url: string }) => void)
Triggered when the web page starts to be loaded. This API is triggered only for the main frame content, and not for the iframe or frameset content.
Called when the web page starts to be loaded. This API is called only for the main frame content, and not for the iframe or frameset content.
**Parameters**
......@@ -1668,7 +1668,7 @@ Triggered when the web page starts to be loaded. This API is triggered only for
onPageEnd(callback: (event?: { url: string }) => void)
Triggered when the web page loading is complete. This API is triggered only for the main frame content.
Called when the web page loading is complete. This API takes effect only for the main frame content.
**Parameters**
......@@ -1700,7 +1700,7 @@ Triggered when the web page loading is complete. This API is triggered only for
onProgressChange(callback: (event?: { newProgress: number }) => void)
Triggered when the web page loading progress changes.
Called when the web page loading progress changes.
**Parameters**
......@@ -1732,7 +1732,7 @@ Triggered when the web page loading progress changes.
onTitleReceive(callback: (event?: { title: string }) => void)
Triggered when the document title of the web page is changed.
Called when the document title of the web page is changed.
**Parameters**
......@@ -1764,7 +1764,7 @@ Triggered when the document title of the web page is changed.
onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void)
Triggered when loading of the web page is complete. This API is used by an application to update the historical link it accessed.
Called when loading of the web page is complete. This API is used by an application to update the historical link it accessed..
**Parameters**
......@@ -1797,7 +1797,7 @@ Triggered when loading of the web page is complete. This API is used by an appli
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
Triggered when the rendering process exits abnormally.
Called when the rendering process exits abnormally.
**Parameters**
......@@ -1829,7 +1829,7 @@ Triggered when the rendering process exits abnormally.
onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector: FileSelectorParam }) => boolean)
Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.
Called to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.
**Parameters**
......@@ -1842,7 +1842,7 @@ Triggered to process an HTML form whose input type is **file**, in response to t
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | The value **true** means that the pop-up window provided by the system is displayed. The value **false** means that the default web pop-up window is displayed.|
| boolean | The value **true** means that the pop-up window provided by the system is displayed. If the callback returns **false**, the **\<Web>** component cannot trigger the system dialog box.|
**Example**
......@@ -1885,7 +1885,7 @@ Triggered to process an HTML form whose input type is **file**, in response to t
onResourceLoad(callback: (event: {url: string}) => void)
Invoked to notify the **\<Web>** component of the URL of the loaded resource file.
Called to notify the **\<Web>** component of the URL of the loaded resource file.
**Parameters**
......@@ -1917,7 +1917,7 @@ Invoked to notify the **\<Web>** component of the URL of the loaded resource fil
onScaleChange(callback: (event: {oldScale: number, newScale: number}) => void)
Invoked when the display ratio of this page changes.
Called when the display ratio of this page changes.
**Parameters**
......@@ -1950,7 +1950,7 @@ Invoked when the display ratio of this page changes.
onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean)
Triggered when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access.
Called when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access.
**Parameters**
......@@ -1989,7 +1989,7 @@ Triggered when the **\<Web>** component is about to access a URL. This API is us
onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebResourceResponse)
Invoked when the **\<Web>** component is about to access a URL. This API is used to block the URL and return the response data.
Called when the **\<Web>** component is about to access a URL. This API is used to block the URL and return the response data.
**Parameters**
......@@ -2054,7 +2054,7 @@ Invoked when the **\<Web>** component is about to access a URL. This API is used
onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, realm: string}) => boolean)
Invoked when an HTTP authentication request is received.
Called when an HTTP authentication request is received.
**Parameters**
......@@ -2123,7 +2123,7 @@ Invoked when an HTTP authentication request is received.
onSslErrorEventReceive(callback: (event: { handler: SslErrorHandler, error: SslError }) => void)
Invoked when an SSL error occurs during resource loading.
Called when an SSL error occurs during resource loading.
**Parameters**
......@@ -2176,7 +2176,7 @@ Invoked when an SSL error occurs during resource loading.
onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)
Invoked when an SSL client certificate request is received.
Called when an SSL client certificate request is received.
**Parameters**
......@@ -2231,7 +2231,7 @@ Invoked when an SSL client certificate request is received.
onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)
Invoked when a permission request is received.
Called when a permission request is received.
**Parameters**
......@@ -2320,7 +2320,7 @@ Shows a context menu after the user clicks the right mouse button or long presse
onScroll(callback: (event: {xOffset: number, yOffset: number}) => void)
Invoked when the scrollbar of the page scrolls.
Called when the scrollbar of the page scrolls.
**Parameters**
......@@ -2398,7 +2398,7 @@ Registers a callback for receiving a request to obtain the geolocation informati
onGeolocationHide(callback: () => void)
Triggered to notify the user that the request for obtaining the geolocation information received when **[onGeolocationShow](#ongeolocationshow)** is called has been canceled.
Called to notify the user that the request for obtaining the geolocation information received when **[onGeolocationShow](#ongeolocationshow)** is called has been canceled.
**Parameters**
......@@ -2430,7 +2430,7 @@ Triggered to notify the user that the request for obtaining the geolocation info
onFullScreenEnter(callback: (event: { handler: FullScreenExitHandler }) => void)
Registers a callback for the component's entering into full screen mode.
Called when the component enters full screen mode.
**Parameters**
......@@ -2463,7 +2463,7 @@ Registers a callback for the component's entering into full screen mode.
onFullScreenExit(callback: () => void)
Registers a callback for the component's exiting full screen mode.
Called when the component exits full screen mode.
**Parameters**
......@@ -2568,7 +2568,7 @@ Registers a callback for window closure.
onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMatches: number, isDoneCounting: boolean}) => void): WebAttribute
Invoked to notify the caller of the search result on the web page.
Called to notify the caller of the search result on the web page.
**Parameters**
......@@ -2603,7 +2603,7 @@ Invoked to notify the caller of the search result on the web page.
onDataResubmitted(callback: (event: {handler: DataResubmissionHandler}) => void)
Invoked when the web form data is resubmitted.
Called when the web form data is resubmitted.
**Parameters**
......@@ -2636,7 +2636,7 @@ Invoked when the web form data is resubmitted.
onPageVisible(callback: (event: {url: string}) => void)
Invoked when the old page is not displayed and the new page is about to be visible.
Called when the old page is not displayed and the new page is about to be visible.
**Parameters**
......@@ -2668,7 +2668,7 @@ Invoked when the old page is not displayed and the new page is about to be visib
onInterceptKeyEvent(callback: (event: KeyEvent) => boolean)
Invoked when the key event is intercepted, before being consumed by the Webview.
Called when the key event is intercepted, before being consumed by the Webview.
**Parameters**
......@@ -2710,7 +2710,7 @@ Invoked when the key event is intercepted, before being consumed by the Webview.
onTouchIconUrlReceived(callback: (event: {url: string, precomposed: boolean}) => void)
Invoked when an apple-touch-icon URL is received.
Called when an apple-touch-icon URL is received.
**Parameters**
......@@ -2743,7 +2743,7 @@ Invoked when an apple-touch-icon URL is received.
onFaviconReceived(callback: (event: {favicon: image.PixelMap}) => void)
Invoked when this web page receives a new favicon.
Called when this web page receives a new favicon.
**Parameters**
......@@ -3243,7 +3243,7 @@ Performs HTTP authentication with the user name and password provided by the use
isHttpAuthInfoSaved(): boolean
Uses the password cached on the server for authentication.
Uses the account name and password cached on the server for authentication.
**Return value**
......@@ -4160,7 +4160,7 @@ This API is deprecated since API version 9. You are advised to use [loadUrl<sup>
onActive(): void
Invoked when the **\<Web>** component enters the active state.
Called when the **\<Web>** component enters the active state.
This API is deprecated since API version 9. You are advised to use [onActive<sup>9+</sup>](../apis/js-apis-webview.md#onactive).
......@@ -4189,7 +4189,7 @@ This API is deprecated since API version 9. You are advised to use [onActive<sup
onInactive(): void
Invoked when the **\<Web>** component enters the inactive state.
Called when the **\<Web>** component enters the inactive state.
This API is deprecated since API version 9. You are advised to use [onInactive<sup>9+</sup>](../apis/js-apis-webview.md#oninactive).
......@@ -4319,7 +4319,7 @@ Zooms out of this web page by 20%.
refresh()
Invoked when the **\<Web>** component refreshes the web page.
Called when the **\<Web>** component refreshes the web page.
This API is deprecated since API version 9. You are advised to use [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh).
......@@ -4973,39 +4973,6 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if
}
```
### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
Saves the cookies in the memory to the drive. This API returns the result synchronously.
**Return value**
| Type | Description |
| ------- | -------------------- |
| boolean | Operation result.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('saveCookieSync')
.onClick(() => {
let result = this.controller.getCookieManager().saveCookieSync()
console.log("result: " + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getCookie<sup>9+</sup>
getCookie(url: string): string
......@@ -5087,6 +5054,39 @@ Sets a cookie value for the specified URL.
}
```
### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
Saves the cookies in the memory to the drive. This API returns the result synchronously.
**Return value**
| Type | Description |
| ------- | -------------------- |
| boolean | Operation result.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('saveCookieSync')
.onClick(() => {
let result = web_webview.WebCookieManager.saveCookieSync()
console.log("result: " + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### saveCookieAsync<sup>9+</sup>
saveCookieAsync(): Promise\<boolean>
......@@ -5466,6 +5466,103 @@ Enumerates the error codes returned by **onSslErrorEventReceive** API.
| On | The web dark mode is enabled. |
| Auto | The web dark mode setting follows the system settings. |
## WebAsyncController
Implements a **WebAsyncController** object, which can be used to control the behavior of a **\<Web>** component with asynchronous callbacks. A **WebAsyncController **object controls one **\<Web>** component.
### Creating an Object
```
webController: WebController = new WebController();
webAsyncController: WebAsyncController = new WebAsyncController(webController);
```
### storeWebArchive<sup>9+</sup>
storeWebArchive(baseName: string, autoName: boolean, callback: AsyncCallback\<string>): void
Stores this web page. This API uses an asynchronous callback to return the result.
**Parameters**
| 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. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('saveWebArchive')
.onClick(() => {
let webAsyncController = new web_webview.WebAsyncController(this.controller)
webAsyncController.storeWebArchive("/data/storage/el2/base/", true, (filename) => {
if (filename != null) {
console.info(`save web archive success: ${filename}`)
}
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### storeWebArchive<sup>9+</sup>
storeWebArchive(baseName: string, autoName: boolean): Promise\<string>
Stores this web page. This API uses a promise to return the result.
**Parameters**
| 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. |
**Return value**
| Type | Description |
| --------------- | -------------------------------- |
| Promise\<string> | Promise used to return the save path if the operation is successful and null otherwise. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController();
build() {
Column() {
Button('saveWebArchive')
.onClick(() => {
let webAsyncController = new web_webview.WebAsyncController(this.controller);
webAsyncController.storeWebArchive("/data/storage/el2/base/", true)
.then(filename => {
if (filename != null) {
console.info(`save web archive success: ${filename}`)
}
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## WebMessagePort<sup>9+</sup>
Implements a **WebMessagePort** instance, which can be used to send and receive messages.
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部