Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9).
Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9).
// Call the destroy() method to release resources after the HttpRequest is complete.
httpRequest.destroy();
}else{
}else{
console.info('error:'+JSON.stringify(err));
console.info('error:'+JSON.stringify(err));
// Unsubscribe from HTTP Response Header events.
// Unsubscribe from HTTP Response Header events.
httpRequest.off('headersReceive');
httpRequest.off('headersReceive');
// Call the destroy() method to release resources after HttpRequest is complete.
// Call the destroy() method to release resources after the HttpRequest is complete.
httpRequest.destroy();
httpRequest.destroy();
}
}
}
}
...
@@ -73,6 +75,9 @@ createHttp(): HttpRequest
...
@@ -73,6 +75,9 @@ createHttp(): HttpRequest
Creates an HTTP request. You can use this API to initiate or destroy an HTTP request, or enable or disable listening for HTTP Response Header events. An **HttpRequest** object corresponds to an HTTP request. To initiate multiple HTTP requests, you must create an **HttpRequest** object for each HTTP request.
Creates an HTTP request. You can use this API to initiate or destroy an HTTP request, or enable or disable listening for HTTP Response Header events. An **HttpRequest** object corresponds to an HTTP request. To initiate multiple HTTP requests, you must create an **HttpRequest** object for each HTTP request.
> **NOTE**
> Call the **destroy()** method to release resources after the HttpRequest is complete.
| method | [RequestMethod](#requestmethod) | No | Request method. The default value is **GET**. |
| method | [RequestMethod](#requestmethod) | No | Request method. The default value is **GET**. |
| extraData | string<sup>6+</sup>\| Object<sup>6+</sup>\| ArrayBuffer<sup>8+</sup> | No | Additional data for sending a request. This parameter is not used by default.<br>- If the HTTP request uses a POST or PUT method, this parameter serves as the content of the HTTP request and is encoded in UTF-8 format. If **'Content-Type'** is **'application/x-www-form-urlencoded'**, the data in the request body must be encoded in the format of **key1=value1&key2=value2&key3=value3** after URL transcoding.<sup>6+</sup><br>- If the HTTP request uses the GET, OPTIONS, DELETE, TRACE, or CONNECT method, this parameter serves as a supplement to HTTP request parameters. Parameters of the string type need to be encoded before being passed to the HTTP request. Parameters of the object type do not need to be precoded and will be directly concatenated to the URL. Parameters of the ArrayBuffer type will not be concatenated to the URL.<sup>6+</sup>|
| extraData | string<sup>6+</sup>\| Object<sup>6+</sup>\| ArrayBuffer<sup>8+</sup> | No | Additional data for sending a request. This parameter is not used by default.<br>- If the HTTP request uses a POST or PUT method, this parameter serves as the content of the HTTP request and is encoded in UTF-8 format. If **'Content-Type'** is **'application/x-www-form-urlencoded'**, the data in the request body must be encoded in the format of **key1=value1&key2=value2&key3=value3** after URL transcoding.<br>- If the HTTP request uses the GET, OPTIONS, DELETE, TRACE, or CONNECT method, this parameter serves as a supplement to HTTP request parameters. Parameters of the string type need to be encoded before being passed to the HTTP request. Parameters of the object type do not need to be precoded and will be directly concatenated to the URL. Parameters of the ArrayBuffer type will not be concatenated to the URL.|
| expectDataType<sup>9+</sup> | [HttpDataType](#httpdatatype9) | No | Type of the returned data. This parameter is not used by default. If this parameter is set, the system returns the specified type of data preferentially.|
| expectDataType<sup>9+</sup> | [HttpDataType](#httpdatatype9) | No | Type of the returned data. This parameter is not used by default. If this parameter is set, the system returns the specified type of data preferentially.|
| usingCache<sup>9+</sup> | boolean | No | Whether to use the cache. The default value is **true**. |
| usingCache<sup>9+</sup> | boolean | No | Whether to use the cache. The default value is **true**. |
| priority<sup>9+</sup> | number | No | Priority. The value range is [1,1000]. The default value is **1**. |
| priority<sup>9+</sup> | number | No | Priority. The value range is [1,1000]. The default value is **1**. |
The **console** module provides a simple debugging console, which is similar to the JavaScript console provided by the browser.
> The APIs of this module are no longer maintained since API version 7. You are advised to use ['@ohos.hilog](js-apis-hilog.md)' instead.
> **NOTE**
>
> The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## console.debug
## console.debug
debug(message: string): void
debug(message: string, ...arguments: any[]): void
Prints debugging information in formatted output mode.
| message | string | Yes | Error information to be printed.|
| arguments | any[] | No | Arguments in the message or other information to be printed.|
```
export default {
clickConsole(){
var versionCode = 1;
console.info('Hello World. The current version code is ' + versionCode);
console.log(`versionCode: ${versionCode}`);
/ / The following is supported since API version 6: console.log('versionCode:%d.', versionCode);
}
}
```
Switch to the HiLog window at the bottom of HUAWEI DevEco Studio. Specifically, select the current device and process, set the log level to Info, and enter Hello World in the search box. Logs that meet the search criteria are displayed, as shown in the following figure.
| type | string | Yes | Event type. The value is **interfaceStateChange**.|
| callback | AsyncCallback\<{ iface: string, active: boolean }\> | Yes | Callback used to return the result.<br>**iface**: NIC name.<br>**active**: whether the NIC is active. The value **true** indicates that the NIC is active, and the value **false** indicates the opposite.|
| type | string | Yes | Event type. The value is **interfaceStateChange**.|
| callback | AsyncCallback\<{ iface: string, active: boolean }> | No | Callback used to return the result.<br>**iface**: NIC name.<br>**active**: whether the NIC is active. The value **true** indicates that the NIC is active, and the value **false** indicates the opposite.|
@@ -32,11 +32,11 @@ Creates a **UDPSocket** object.
...
@@ -32,11 +32,11 @@ Creates a **UDPSocket** object.
letudp=socket.constructUDPSocketInstance();
letudp=socket.constructUDPSocketInstance();
```
```
## UDPSocket
## UDPSocket<sup>7+</sup>
Defines a **UDPSocket** connection. Before invoking UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object.
Defines a **UDPSocket** connection. Before invoking UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object.
@@ -653,7 +653,7 @@ Defines the destination address.
...
@@ -653,7 +653,7 @@ Defines the destination address.
| port | number | No | Port number. The value ranges from **0** to **65535**. If this parameter is not specified, the system randomly allocates a port. |
| port | number | No | Port number. The value ranges from **0** to **65535**. If this parameter is not specified, the system randomly allocates a port. |
| family | number | No | Network protocol type.<br>- **1**: IPv4<br>- **2**: IPv6<br>The default value is **1**.|
| family | number | No | Network protocol type.<br>- **1**: IPv4<br>- **2**: IPv6<br>The default value is **1**.|
## UDPSendOptions
## UDPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the UDPSocket connection.
Defines the parameters for sending data over the UDPSocket connection.
...
@@ -664,7 +664,7 @@ Defines the parameters for sending data over the UDPSocket connection.
...
@@ -664,7 +664,7 @@ Defines the parameters for sending data over the UDPSocket connection.
| data | string \| ArrayBuffer<sup>7+</sup> | Yes | Data to send. |
| data | string \| ArrayBuffer<sup>7+</sup> | Yes | Data to send. |
| broadcast | boolean | No | Whether to send broadcast messages. The default value is **false**. |
| broadcast | boolean | No | Whether to send broadcast messages. The default value is **false**. |
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. |
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms.|
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. The default value is **0**.|
## SocketStateBase
## SocketStateBase<sup>7+</sup>
Defines the status of the socket connection.
Defines the status of the socket connection.
...
@@ -690,7 +690,7 @@ Defines the status of the socket connection.
...
@@ -690,7 +690,7 @@ Defines the status of the socket connection.
| isClose | boolean | Yes | Whether the connection is in the closed state.|
| isClose | boolean | Yes | Whether the connection is in the closed state.|
| isConnected | boolean | Yes | Whether the connection is in the connected state.|
| isConnected | boolean | Yes | Whether the connection is in the connected state.|
## SocketRemoteInfo
## SocketRemoteInfo<sup>7+</sup>
Defines information about the socket connection.
Defines information about the socket connection.
...
@@ -709,7 +709,7 @@ The UDP error code mapping is in the format of 2301000 + Linux kernel error code
...
@@ -709,7 +709,7 @@ The UDP error code mapping is in the format of 2301000 + Linux kernel error code
For details about error codes, see [Socket Error Codes](../errorcodes/errorcode-net-socket.md).
For details about error codes, see [Socket Error Codes](../errorcodes/errorcode-net-socket.md).
## socket.constructTCPSocketInstance
## socket.constructTCPSocketInstance<sup>7+</sup>
constructTCPSocketInstance(): TCPSocket
constructTCPSocketInstance(): TCPSocket
...
@@ -729,11 +729,11 @@ Creates a **TCPSocket** object.
...
@@ -729,11 +729,11 @@ Creates a **TCPSocket** object.
lettcp=socket.constructTCPSocketInstance();
lettcp=socket.constructTCPSocketInstance();
```
```
## TCPSocket
## TCPSocket<sup>7+</sup>
Defines a TCPSocket connection. Before invoking TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object.
Defines a TCPSocket connection. Before invoking TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object.
| address | [NetAddress](#netaddress) | Yes | Bound IP address and port number. |
| address | [NetAddress](#netaddress) | Yes | Bound IP address and port number. |
| timeout | number | No | Timeout duration of the TCPSocket connection, in ms.|
| timeout | number | No | Timeout duration of the TCPSocket connection, in ms.|
## TCPSendOptions
## TCPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the TCPSocket connection.
Defines the parameters for sending data over the TCPSocket connection.
...
@@ -1541,7 +1541,7 @@ Defines the parameters for sending data over the TCPSocket connection.
...
@@ -1541,7 +1541,7 @@ Defines the parameters for sending data over the TCPSocket connection.
| data | string\| ArrayBuffer<sup>7+</sup> | Yes | Data to send. |
| data | string\| ArrayBuffer<sup>7+</sup> | Yes | Data to send. |
| encoding | string | No | Character encoding format. The options are as follows: **UTF-8**, **UTF-16BE**, **UTF-16LE**, **UTF-16**, **US-AECII**, and **ISO-8859-1**. The default value is **UTF-8**.|
| encoding | string | No | Character encoding format. The options are as follows: **UTF-8**, **UTF-16BE**, **UTF-16LE**, **UTF-16**, **US-AECII**, and **ISO-8859-1**. The default value is **UTF-8**.|
## TCPExtraOptions
## TCPExtraOptions<sup>7+</sup>
Defines other properties of the TCPSocket connection.
Defines other properties of the TCPSocket connection.
...
@@ -1553,10 +1553,10 @@ Defines other properties of the TCPSocket connection.
...
@@ -1553,10 +1553,10 @@ Defines other properties of the TCPSocket connection.
| OOBInline | boolean | No | Whether to enable OOBInline. The default value is **false**. |
| OOBInline | boolean | No | Whether to enable OOBInline. The default value is **false**. |
| TCPNoDelay | boolean | No | Whether to enable no-delay on the TCPSocket connection. The default value is **false**. |
| TCPNoDelay | boolean | No | Whether to enable no-delay on the TCPSocket connection. The default value is **false**. |
| socketLinger | Object | Yes | Socket linger.<br>- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.<br>- **linger**: linger time, in ms. The value ranges from **0** to **65535**.<br>Specify this parameter only when **on** is set to **true**.|
| socketLinger | Object | Yes | Socket linger.<br>- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.<br>- **linger**: linger time, in ms. The value ranges from **0** to **65535**.<br>Specify this parameter only when **on** is set to **true**.|
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. |
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. |
| socketTimeout | number | No | Timeout duration of the TCPSocket connection, in ms. The default value is **0**. |
// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
@@ -27,7 +27,7 @@ Obtains the current charging state and battery level.
...
@@ -27,7 +27,7 @@ Obtains the current charging state and battery level.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [GetStatusOptions](#getstatusoptions) | No| Object that contains the API calling result.|
| options | [GetStatusOptions](#getstatusoptions) | No| Object that contains the API calling result. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -44,15 +44,15 @@ battery.getStatus({
...
@@ -44,15 +44,15 @@ battery.getStatus({
## GetStatusOptions
## GetStatusOptions
Obtains the object that contains the API calling result.
| success | (data: [BatteryResponse](#batteryresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BatteryResponse](#batteryresponse) type.|
| success | (data: [BatteryResponse](#batteryresponse)) => void | No | Called when an API call is successful. **data** is a return value of the [BatteryResponse](#batteryresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
| complete | () => void | No | Called when an API call is complete. |
## BatteryResponse
## BatteryResponse
...
@@ -60,7 +60,7 @@ Defines a response that returns the charging status and remaining power of the d
...
@@ -60,7 +60,7 @@ Defines a response that returns the charging status and remaining power of the d
@@ -28,7 +28,7 @@ Obtains the current screen brightness.
...
@@ -28,7 +28,7 @@ Obtains the current screen brightness.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [GetBrightnessOptions](#getbrightnessoptions) | No | Options for obtaining the screen brightness.|
| options | [GetBrightnessOptions](#getbrightnessoptions) | No | Options for obtaining the screen brightness. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -56,7 +56,7 @@ Sets the screen brightness.
...
@@ -56,7 +56,7 @@ Sets the screen brightness.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [SetBrightnessOptions](#setbrightnessoptions) | No | Options for setting the screen brightness.|
| options | [SetBrightnessOptions](#setbrightnessoptions) | No | Options for setting the screen brightness. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -85,7 +85,7 @@ Obtains the screen brightness adjustment mode.
...
@@ -85,7 +85,7 @@ Obtains the screen brightness adjustment mode.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [GetBrightnessModeOptions](#getbrightnessmodeoptions) | No| Options for obtaining the screen brightness mode.|
| options | [GetBrightnessModeOptions](#getbrightnessmodeoptions) | No| Options for obtaining the screen brightness mode. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -112,7 +112,7 @@ Sets the screen brightness adjustment mode.
...
@@ -112,7 +112,7 @@ Sets the screen brightness adjustment mode.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [SetBrightnessModeOptions](#setbrightnessmodeoptions) | No | Options for setting the screen brightness mode.|
| options | [SetBrightnessModeOptions](#setbrightnessmodeoptions) | No | Options for setting the screen brightness mode. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -143,7 +143,7 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
...
@@ -143,7 +143,7 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| options | [SetKeepScreenOnOptions](#setkeepscreenonoptions) | No| Options for setting the screen to be steady on.|
| options | [SetKeepScreenOnOptions](#setkeepscreenonoptions) | No| Options for setting the screen to be steady on. This parameter is optional and is left blank by default.|
**Example**
**Example**
...
@@ -166,9 +166,9 @@ Defines the options for obtaining the screen brightness.
...
@@ -166,9 +166,9 @@ Defines the options for obtaining the screen brightness.
| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponse) type.|
| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No | Called when an API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when the API call is complete. |
| complete | () => void | No | Called when an API call is complete. |
## SetBrightnessOptions
## SetBrightnessOptions
...
@@ -178,10 +178,10 @@ Defines the options for setting the screen brightness.
...
@@ -178,10 +178,10 @@ Defines the options for setting the screen brightness.
| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**.<br>- If the value is less than or equal to **0**, value **1** will be used.<br>- If the value is greater than **255**, value **255** will be used.<br>- If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used.|
| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**.<br>- If the value is less than or equal to **0**, value **1** will be used.<br>- If the value is greater than **255**, value **255** will be used.<br>- If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used.|
| success | () => void | No | Callback upon a successful API call. |
| success | () => void | No | Called when an API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when the API call is complete. |
| complete | () => void | No | Called when an API call is complete. |
## BrightnessResponse
## BrightnessResponse
...
@@ -201,9 +201,9 @@ Defines the options for obtaining the screen brightness mode.
...
@@ -201,9 +201,9 @@ Defines the options for obtaining the screen brightness mode.
| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponse) type.|
| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No | Called when an API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when the API call is complete. |
| complete | () => void | No | Called when an API call is complete. |
## SetBrightnessModeOptions
## SetBrightnessModeOptions
...
@@ -214,9 +214,9 @@ Defines the options for setting the screen brightness mode.
...
@@ -214,9 +214,9 @@ Defines the options for setting the screen brightness mode.
| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
| success | () => void | No | Callback upon a successful API call. |
| success | () => void | No | Called when an API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when the API call is complete. |
| complete | () => void | No | Called when an API call is complete. |
## BrightnessModeResponse
## BrightnessModeResponse
...
@@ -237,6 +237,6 @@ Defines the options for setting the screen to be steady on.
...
@@ -237,6 +237,6 @@ Defines the options for setting the screen to be steady on.
| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. |
| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. |
| success | () => void | No | Callback upon a successful API call. |
| success | () => void | No | Called when an API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when the API call is complete. |
| complete | () => void | No | Called when an API call is complete. |