diff --git a/en/application-dev/quick-start/start-with-ets-fa.md b/en/application-dev/quick-start/start-with-ets-fa.md index 66f2ead3d35e72950a81c5495db14254210c8c2b..197765c3119690c7529469daa85a045d7c2853fd 100644 --- a/en/application-dev/quick-start/start-with-ets-fa.md +++ b/en/application-dev/quick-start/start-with-ets-fa.md @@ -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%') diff --git a/en/application-dev/reference/apis/js-apis-screen-lock.md b/en/application-dev/reference/apis/js-apis-screen-lock.md index c726ec7c8fdd4cd6f16d71f5a6892bc565b66cf6..aebd21314c8d71e68409b4b5d89af29161614950 100644 --- a/en/application-dev/reference/apis/js-apis-screen-lock.md +++ b/en/application-dev/reference/apis/js-apis-screen-lock.md @@ -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.
- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.
- **1**, the operation fails. For example, screen locking or unlocking fails.
- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.| | callback | AsyncCallback\ | 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** diff --git a/en/application-dev/reference/apis/js-apis-system-date-time.md b/en/application-dev/reference/apis/js-apis-system-date-time.md index 90c915b32ee35f9d09f6fe0453c962b985f914f1..38d90b668894a52dde1a4ae05578d290182bc6ef 100644 --- a/en/application-dev/reference/apis/js-apis-system-date-time.md +++ b/en/application-dev/reference/apis/js-apis-system-date-time.md @@ -1,4 +1,4 @@ -# @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. diff --git a/en/application-dev/reference/apis/js-apis-system-time.md b/en/application-dev/reference/apis/js-apis-system-time.md index a1876af97b532bf208eb405ee9c7c22edda6919f..6454fd82ed851af06a70941cdf6ef68bf6af232a 100644 --- a/en/application-dev/reference/apis/js-apis-system-time.md +++ b/en/application-dev/reference/apis/js-apis-system-time.md @@ -1,4 +1,4 @@ -# @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,25 +29,33 @@ Sets the system time. This API uses an asynchronous callback to return the resul | time | number | Yes | Timestamp to set, in milliseconds. | | callback | AsyncCallback<void> | 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 // Set the system time to 2021-01-20 02:36:25. let time = 1611081385000; try { - systemTime.setTime(time, (error) => { - if (error) { - console.info(`Failed to setting time. message:${error.message}, code:${error.code}`); - return; - } - console.info(`Succeeded in setting time`); - }); + systemTime.setTime(time, (error) => { + if (error) { + console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`); + return; + } + }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(deprecated) +## systemTime.setTime setTime(time : number) : Promise<void> @@ -69,67 +77,75 @@ Sets the system time. This API uses a promise to return the result. | ------------------- | ------------------------- | | Promise<void> | 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 // Set the system time to 2021-01-20 02:36:25. let time = 1611081385000; 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}`); - }); + systemTime.setTime(time).then(() => { + console.info(`Succeeded in setting time.`); + }).catch((error) => { + 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(deprecated) +## systemTime.getCurrentTime8+ getCurrentTime(isNano: boolean, callback: AsyncCallback<number>): 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | Yes | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| | callback | AsyncCallback<number> | 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}`); - return; - } - console.info(`Succeeded in getting currentTime : ${time}`); - }); + systemTime.getCurrentTime(true, (error, time) => { + if (error) { + 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(deprecated) +## systemTime.getCurrentTime8+ getCurrentTime(callback: AsyncCallback<number>): 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<number> | 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}`); - return; - } - console.info(`Succeeded in getting currentTime : ${time}`); - }); + systemTime.getCurrentTime((error, time) => { + if (error) { + 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(deprecated) +## systemTime.getCurrentTime8+ getCurrentTime(isNano?: boolean): Promise<number> 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | No | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| **Return value** @@ -178,65 +198,73 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return | --------------------- | --------------------------- | | Promise<number> | 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 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}`); - }); + 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}`); + }); } 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(deprecated) +## systemTime.getRealActiveTime8+ getRealActiveTime(isNano: boolean, callback: AsyncCallback<number>): 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | Yes | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| | callback | AsyncCallback<number> | 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}`); - return; - } - console.info(`Succeeded in getting real active time : ${time}`); - }); + systemTime.getRealActiveTime(true, (error, time) => { + if (error) { + 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(deprecated) +## systemTime.getRealActiveTime8+ getRealActiveTime(callback: AsyncCallback<number>): 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<number> | 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}`); - return; - } - console.info(`Succeeded in getting real active time : ${time}`); - }); + systemTime.getRealActiveTime((error, time) => { + if (error) { + 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(deprecated) +## systemTime.getRealActiveTime8+ getRealActiveTime(isNano?: boolean): Promise<number> 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | No | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| **Return value** @@ -285,65 +317,73 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th | -------------- | -------------------------------- | | Promise<number> | 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 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}`); - }); + 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}`); + }); } 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(deprecated) +## systemTime.getRealTime8+ getRealTime(isNano: boolean, callback: AsyncCallback<number>): 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | Yes | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| | callback | AsyncCallback<number> | 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}`); - return; - } - console.info(`Succeeded in getting real time : ${time}`); - }); + systemTime.getRealTime(true, (error, time) => { + if (error) { + 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(deprecated) +## systemTime.getRealTime8+ getRealTime(callback: AsyncCallback<number>): 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<number> | 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}`); - return; - } - console.info(`Succeeded in getting real time : ${time}`); - }); + systemTime.getRealTime((error, time) => { + if (error) { + 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(deprecated) +## systemTime.getRealTime8+ getRealTime(isNano?: boolean): Promise<number> 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.
- **true**: in nanoseconds (ns).
- **false**: in milliseconds (ms).| +| isNano | boolean | No | Whether the time to return is in nanoseconds.
- **true**: in nanoseconds.
- **false**: in milliseconds.| **Return value** @@ -392,21 +436,29 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th | --------------------- | ------------------------------- | | Promise<number> | 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 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}`); - }); + 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}`); + }); } 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(deprecated) +## systemTime.setDate setDate(date: Date, callback: AsyncCallback<void>): void @@ -423,24 +475,32 @@ Sets the system date. This API uses an asynchronous callback to return the resul | date | Date | Yes | Target date to set. | | callback | AsyncCallback<void> | 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 let date = new Date(); try { - systemTime.setDate(date, (error) => { - if (error) { - console.info(`Failed to setting date. message:${error.message}, code:${error.code}`); - return; - } - console.info(`Succeeded in setting date.`); - }); + systemTime.setDate(date, (error) => { + if (error) { + 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(deprecated) +## systemTime.setDate setDate(date: Date): Promise<void> @@ -462,31 +522,35 @@ Sets the system date. This API uses a promise to return the result. | ------------------- | -------------------- | | Promise<void> | 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 let date = new Date(); 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}`); - }); + systemTime.setDate(date).then(() => { + console.info(`Succeeded in setting date.`); + }).catch((error) => { + 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(deprecated) +## systemTime.getDate8+ getDate(callback: AsyncCallback<Date>): 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<Date> | 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}`); - return; - } - console.info(`Succeeded in get date : ${date}`);; - }); + systemTime.getDate((error, date) => { + if (error) { + 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(deprecated) +## systemTime.getDate8+ getDate(): Promise<Date> 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,21 +597,29 @@ Obtains the current system date. This API uses a promise to return the result. | ------------------- | ----------------------------------------- | | Promise<Date> | 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 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}`); - }); + 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}`); + }); } 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(deprecated) +## systemTime.setTimezone setTimezone(timezone: string, callback: AsyncCallback<void>): 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<void> | 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}`); - return; - } - console.info(`Succeeded in setting timezone.`); - }); + systemTime.setTimezone('Asia/Shanghai', (error) => { + if (error) { + 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(deprecated) +## systemTime.setTimezone setTimezone(timezone: string): Promise<void> @@ -598,30 +682,34 @@ Sets the system time zone. This API uses a promise to return the result. | ------------------- | -------------------- | | Promise<void> | 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 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}`); - }); + 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}`); + }); } 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(deprecated) +## systemTime.getTimezone8+ getTimezone(callback: AsyncCallback<string>): 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<string> | 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}`); - return; - } - console.info(`Succeeded in get timezone : ${data}`);; - }); + systemTime.getTimezone((error, data) => { + if (error) { + 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(deprecated) +## systemTime.getTimezone8+ getTimezone(): Promise<string> 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,17 +756,25 @@ Obtains the system time zone. This API uses a promise to return the result. | --------------------- | ------------------------------------- | | Promise<string> | 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 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}`); - }); + 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}`); + }); } 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}`); } ``` diff --git a/en/application-dev/reference/apis/js-apis-system-timer.md b/en/application-dev/reference/apis/js-apis-system-timer.md index fb1f95ce2d8c5003377120d9d28f29f4415d3117..cb3a97212ef21d604ae41784f142ac60fcf3f353 100644 --- a/en/application-dev/reference/apis/js-apis-system-timer.md +++ b/en/application-dev/reference/apis/js-apis-system-timer.md @@ -1,4 +1,4 @@ -# @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<number>): 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<number> 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<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<void> 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<void>): 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<void> 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<void>): 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<void> 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}`); } + } } ``` diff --git a/en/application-dev/reference/apis/js-apis-webview.md b/en/application-dev/reference/apis/js-apis-webview.md index 83d89392cd8ade90901018fbe5721ce53ba54f2e..8c3ca939bdb5758f987780d94c7bb88837613b4d 100644 --- a/en/application-dev/reference/apis/js-apis-webview.md +++ b/en/application-dev/reference/apis/js-apis-webview.md @@ -1,6 +1,6 @@ -# @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 {

WebView Message Port Demo


-
+

display received message send from ets

@@ -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\): 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.
The value **false** means not to automatically generate a file name.
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.
The value **false** means not to automatically generate a file name.
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\ | 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}`); } diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-web.md b/en/application-dev/reference/arkui-ts/ts-basic-components-web.md index e2afb3e5eaa55dfb4d4509db3c87ba55821cd748..52414cedbeda0334a2df1e126931fc4d2f4d20a2 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-web.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-web.md @@ -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 **\** 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 **\** component to exit the current page based on the user operation. If the callback returns **false**, the **\** 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 **\** 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 **\** component to exit the current page based on the user operation. If the callback returns **false**, the **\** 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 **\** 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 **\** component to exit the current page based on the user operation. If the callback returns **false**, the **\** 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 **\** 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 **\** component to exit the current page based on the user operation. If the callback returns **false**, the **\** 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 **\** 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 **\** component of the URL of the loaded resource file. +Called to notify the **\** component of the URL of the loaded resource file. **Parameters** @@ -1917,7 +1917,7 @@ Invoked to notify the **\** 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 **\** component is about to access a URL. This API is used to determine whether to block the access. +Called when the **\** 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 **\** component is about to access a URL. This API is us onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebResourceResponse) -Invoked when the **\** component is about to access a URL. This API is used to block the URL and return the response data. +Called when the **\** 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 **\** 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, issuers : Array}) => 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** @@ -2695,7 +2695,7 @@ Invoked when the key event is intercepted, before being consumed by the Webview. Column() { Web({ src:'www.example.com', controller: this.controller }) .onInterceptKeyEvent((event) => { - if (event.keyCode == 2017 || event.keyCode == 2018) { + if (event.keyCode == 2017 || event.keyCode == 2018) { console.info(`onInterceptKeyEvent get event.keyCode ${event.keyCode}`) return true; } @@ -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 onActive(): void -Invoked when the **\** component enters the active state. +Called when the **\** component enters the active state. This API is deprecated since API version 9. You are advised to use [onActive9+](../apis/js-apis-webview.md#onactive). @@ -4189,7 +4189,7 @@ This API is deprecated since API version 9. You are advised to use [onActive** component enters the inactive state. +Called when the **\** component enters the inactive state. This API is deprecated since API version 9. You are advised to use [onInactive9+](../apis/js-apis-webview.md#oninactive). @@ -4319,7 +4319,7 @@ Zooms out of this web page by 20%. refresh() -Invoked when the **\** component refreshes the web page. +Called when the **\** component refreshes the web page. This API is deprecated since API version 9. You are advised to use [refresh9+](../apis/js-apis-webview.md#refresh). @@ -4973,39 +4973,6 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if } ``` -### saveCookieSync9+ -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 }) - } - } - } - ``` - ### getCookie9+ getCookie(url: string): string @@ -5087,6 +5054,39 @@ Sets a cookie value for the specified URL. } ``` +### saveCookieSync9+ +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 }) + } + } + } + ``` ### saveCookieAsync9+ saveCookieAsync(): Promise\ @@ -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 **\** component with asynchronous callbacks. A **WebAsyncController **object controls one **\** component. + +### Creating an Object + +``` +webController: WebController = new WebController(); +webAsyncController: WebAsyncController = new WebAsyncController(webController); +``` + +### storeWebArchive9+ + +storeWebArchive(baseName: string, autoName: boolean, callback: AsyncCallback\): 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.
The value **false** means not to automatically generate a file name.
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\ | 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 }) + } + } + } + ``` + +### storeWebArchive9+ + +storeWebArchive(baseName: string, autoName: boolean): Promise\ + +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.
The value **false** means not to automatically generate a file name.
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\ | 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 }) + } + } + } + ``` + ## WebMessagePort9+ Implements a **WebMessagePort** instance, which can be used to send and receive messages. diff --git a/en/application-dev/reference/errorcodes/Readme-EN.md b/en/application-dev/reference/errorcodes/Readme-EN.md index 20c69e4a113344944d47b775965bedcaa77569ad..c2ade1369554bcbc167d932b16340d48e005098f 100644 --- a/en/application-dev/reference/errorcodes/Readme-EN.md +++ b/en/application-dev/reference/errorcodes/Readme-EN.md @@ -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) diff --git a/en/application-dev/reference/errorcodes/errorcode-time.md b/en/application-dev/reference/errorcodes/errorcode-time.md new file mode 100644 index 0000000000000000000000000000000000000000..d63b3914ad6f480fdaa3808cf98ba25e390c7ebc --- /dev/null +++ b/en/application-dev/reference/errorcodes/errorcode-time.md @@ -0,0 +1,25 @@ +# 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. +