未验证 提交 846776c3 编写于 作者: O openharmony_ci 提交者: Gitee

!4513 翻译已完成4078/4194/4293/4317/4161

Merge pull request !4513 from shawn_he/OpenHarmony-3.1-Release
# HiLog
> **Note:**
>
The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs.
This document describes only API functions. For details about log printing requirements, see [Logging Guide](../../../contribute/OpenHarmony-Log-guide.md).
> **NOTE**<br>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
```js
import hilog from '@ohos.hilog';
```
## hilog.isLoggable
## hilog.debug
debug(domain: number, tag: string, format: string, ...args: any[]) : void
isLoggable(domain: number, tag: string, level: LogLevel) : boolean
Prints logs of the DEBUG level.
Checks whether logs are printable based on the specified service domain, log tag, and log level.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior. |
| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default.|
| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string.|
| Name| Type | Mandatory| Description |
| ------ | --------------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| level | [LogLevel](#loglevel) | Yes | Log level. |
**Return value**
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | Returns **true** logs are printable based on the specified service domain, log tag, and log level; returns **false** otherwise.|
**Example**
```
hilog.debug(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
```js
hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO);
```
**Output**
## LogLevel
```
09-08 12:49:35.941 1547 2452 D FF00/testTag: 1: hello World 3.0
```
Log level.
## hilog.info
**System capability**: SystemCapability.HiviewDFX.HiLog
info(domain: number, tag: string, format: string, ...args: any[]) : void
| Name | Default Value| Description |
| ----- | ------ | ------------------------------------------------------------ |
| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.|
| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>for example, no network signal or login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.|
| WARN | 5 | Log level used to record severe, unexpected faults that have little impact on users and can be rectified by the programs themselves or through simple operations.|
| ERROR | 6 | Log level used to record program or functional errors that affect the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data.|
| FATAL | 7 | Log level used to record program or functionality crashes that cannot be rectified. |
## hilog.debug
debug(domain: number, tag: string, format: string, ...args: any[]) : void
Prints DEBUG logs.
Prints logs of the INFO level.
DEBUG logs are not recorded in official versions by default. They are available in debug versions or in official versions with the debug function enabled.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior. |
| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default.|
| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
```
hilog.info(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
This example is used to output a DEBUG log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer.
```js
hilog.debug(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3);
```
**Output**
If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows:
```
09-08 12:49:35.941 1547 2452 I FF00/testTag: 1: hello World 3.0
08-05 12:21:47.579 2695-2703/com.example.myapplication D 00001/testTag: hello World <private>
```
## hilog.warn
## hilog.info
warn(domain: number, tag: string, format: string, ...args: any[]) : void
info(domain: number, tag: string, format: string, ...args: any[]) : void
Prints logs of the WARN level.
Prints INFO logs.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior. |
| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default.|
| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
```
hilog.warn(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
This example is used to output an INFO log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer.
```js
hilog.info(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3);
```
**Output**
If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows:
```
09-08 12:49:35.941 1547 2452 W FF00/testTag: 1: hello World 3.0
08-05 12:21:47.579 2695-2703/com.example.myapplication I 00001/testTag: hello World <private>
```
## hilog.error
## hilog.warn
error(domain: number, tag: string, format: string, ...args: any[]) : void
warn(domain: number, tag: string, format: string, ...args: any[]) : void
Prints logs of the ERROR level.
Prints WARN logs.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior. |
| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default.|
| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
```
hilog.error(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
This example is used to output a WARN log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer.
```js
hilog.warn(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3);
```
**Output**
If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows:
```
09-08 12:49:35.941 1547 2452 E FF00/testTag: 1: hello World 3.0
08-05 12:21:47.579 2695-2703/com.example.myapplication W 00001/testTag: hello World <private>
```
## hilog.fatal
## hilog.error
fatal(domain: number, tag: string, format: string, ...args: any[]) : void
error(domain: number, tag: string, format: string, ...args: any[]) : void
Prints logs of the FATAL level.
Prints ERROR logs.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior. |
| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default.|
| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
```
hilog.fatal(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
This example is used to output an ERROR log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer.
```js
hilog.error(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3);
```
**Output**
If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows:
```
09-08 12:49:35.941 1547 2452 F FF00/testTag: 1: hello World 3.0
08-05 12:21:47.579 2695-2703/com.example.myapplication E 00001/testTag: hello World <private>
```
## hilog.isLoggable
## hilog.fatal
isLoggable(domain: number, tag: string, level: LogLevel) : boolean
fatal(domain: number, tag: string, format: string, ...args: any[]) : void
Checks whether printing is enabled for a domain, tag, or log level.
Prints FATAL logs.
**System capability**: SystemCapability.HiviewDFX.HiLog
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | --------------------- | ---- | ------------------------------------------ |
| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. |
| tag | string | Yes | String constant used to identify the class or service behavior.|
| level | [LogLevel](#loglevel) | Yes | Log level. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
```
hilog.isLoggable(0xFF00, "testTag", hilog.DEBUG);
```
This example is used to output a FATAL log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer.
## LogLevel
Enumerates event types.
```js
hilog.fatal(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3);
```
**System capability**: SystemCapability.HiviewDFX.HiLog
If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows:
| Name | Default Value| Description |
| ----- | ------ | ----------- |
| DEBUG | 3 | DEBUG level|
| INFO | 4 | INFO level |
| WARN | 5 | WARN level |
| ERROR | 6 | ERROR level|
| FATAL | 7 | FATAL level|
```
08-05 12:21:47.579 2695-2703/com.example.myapplication F 00001/testTag: hello World <private>
```
......@@ -121,6 +121,8 @@ Sets the system language.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| -------- | ------ | ----- |
......@@ -145,6 +147,8 @@ Obtains the list of system languages.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Return Value**
| Type | Description |
| ------------------- | ------------ |
......@@ -164,6 +168,8 @@ Obtains the list of countries and regions supported for the specified language.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| -------- | ------ | ----- |
......@@ -209,6 +215,8 @@ Sets the system region.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| ------ | ------ | ----- |
......@@ -221,7 +229,7 @@ Sets the system region.
**Example**
```
i18n.setSystemRegion();
i18n.setSystemRegion('CN');
```
......@@ -254,6 +262,8 @@ Sets the system locale.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| ------ | ------ | --------------- |
......@@ -278,6 +288,8 @@ Checks whether the system language matches the specified region.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------- |
......@@ -338,7 +350,7 @@ Sets the date for this **Calendar** object.
**Example**
```
var calendar = I18n.getCalendar("en-US", "gregory");
var calendar = i18n.getCalendar("en-US", "gregory");
var date = new Date(2021, 10, 7, 8, 0, 0, 0);
calendar.setTime(date);
```
......@@ -385,7 +397,7 @@ Sets the year, month, day, hour, minute, and second for this **Calendar** object
**Example**
```
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
calendar.set(2021, 10, 1, 8, 0, 0); // Set time to 2021.10.1 08:00:00
```
......@@ -445,7 +457,7 @@ Obtains the start day of a week for this **Calendar** object.
**Example**
```
var calendar = I18n.getCalendar("en-US", "gregory");
var calendar = i18n.getCalendar("en-US", "gregory");
calendar.getFirstDayOfWeek();
```
......@@ -531,7 +543,7 @@ Obtains the value of the specified field in the **Calendar** object.
**Example**
```
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
calendar.set(2021, 10, 1, 8, 0, 0); // Set time to 2021.10.1 08:00:00
calendar.get("hour_of_day"); // 8
```
......@@ -582,7 +594,7 @@ Checks whether the specified date in this **Calendar** object is a weekend.
**Example**
```
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
calendar.set(2021, 11, 11, 8, 0, 0); // Set time to 2021.11.11 08:00:00
calendar.isWeekend(); // false
var date = new Date(2011, 11, 6, 9, 0, 0);
calendar.isWeekend(date); // true
......@@ -712,7 +724,7 @@ Converts one measurement unit into another and formats the unit based on the spe
**Example**
```
I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
i18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
```
......@@ -736,7 +748,7 @@ Creates an **IndexUtil** object.
**Example**
```
var indexUtil= i18n.IndexUtil.getInstance("zh-CN");
var indexUtil= i18n.getInstance("zh-CN");
```
......@@ -831,7 +843,7 @@ Checks whether the input character string is composed of digits.
**Example**
```
var isdigit = Character.isDigit("1"); // Return true.
var isdigit = i18n.Character.isDigit("1"); // Return true.
```
......@@ -855,7 +867,7 @@ Checks whether the input character is a space.
**Example**
```
var isspacechar = Character.isSpaceChar("a"); // Return false.
var isspacechar = i18n.Character.isSpaceChar("a"); // Return false.
```
......@@ -879,7 +891,7 @@ Checks whether the input character is a white space.
**Example**
```
var iswhitespace = Character.isWhitespace("a"); // Return false.
var iswhitespace = i18n.Character.isWhitespace("a"); // Return false.
```
......@@ -903,7 +915,7 @@ Checks whether the input character is of the right to left (RTL) language.
**Example**
```
var isrtl = Character.isRTL("a"); // Return false.
var isrtl = i18n.Character.isRTL("a"); // Return false.
```
......@@ -927,7 +939,7 @@ Checks whether the input character is an ideographic character.
**Example**
```
var isideograph = Character.isIdeograph("a"); // Return false.
var isideograph = i18n.Character.isIdeograph("a"); // Return false.
```
......@@ -951,7 +963,7 @@ Checks whether the input character is a letter.
**Example**
```
var isletter = Character.isLetter("a"); // Return true.
var isletter = i18n.Character.isLetter("a"); // Return true.
```
......@@ -975,7 +987,7 @@ Checks whether the input character is a lowercase letter.
**Example**
```
var islowercase = Character.isLowerCase("a"); // Return true.
var islowercase = i18n.Character.isLowerCase("a"); // Return true.
```
......@@ -999,7 +1011,7 @@ Checks whether the input character is an uppercase letter.
**Example**
```
var isuppercase = Character.isUpperCase("a"); // Return false.
var isuppercase = i18n.Character.isUpperCase("a"); // Return false.
```
......@@ -1023,7 +1035,7 @@ Obtains the type of the input character string.
**Example**
```
var type = Character.getType("a");
var type = i18n.Character.getType("a");
```
......@@ -1047,7 +1059,7 @@ Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
**Example**
```
i18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
```
......@@ -1069,7 +1081,7 @@ Sets the text to be processed by the [BreakIterator](#breakiterator8) object.
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
```
......@@ -1089,7 +1101,7 @@ Obtains the text being processed by the [BreakIterator](#breakiterator8) object.
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.getLineBreakText(); // Apple is my favorite fruit.
```
......@@ -1110,7 +1122,7 @@ Obtains the position of the [BreakIterator](#breakiterator8) object in the text
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
breakIter.current(); // 0
```
......@@ -1131,7 +1143,7 @@ Puts the [BreakIterator](#breakiterator8) object to the first text boundary, whi
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
breakIter.first(); // 0
```
......@@ -1152,7 +1164,7 @@ Puts the [BreakIterator](#breakiterator8) object to the last text boundary, whic
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.last(); // 27
```
......@@ -1178,7 +1190,7 @@ Moves the [BreakIterator](#breakiterator8) object backward by the specified numb
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.first(); // 0
iterator.next(); // 6
......@@ -1201,7 +1213,7 @@ Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.first(); // 0
iterator.next(3); // 12
......@@ -1229,7 +1241,7 @@ Moves the [BreakIterator](#breakiterator8) object to the text boundary after the
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.following(0); // 6
iterator.following(100); // -1
......@@ -1257,7 +1269,7 @@ Checks whether the position specified by the offset is a text boundary. If **tru
**Example**
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.isBoundary(0); // true;
iterator.isBoundary(5); // false;
......@@ -1306,7 +1318,7 @@ Sets the 24-hour clock.
**Example**
```
// Set the system time to the 24-hour clock.
var success = I18n.set24HourClock(true);
var success = i18n.set24HourClock(true);
```
......
# Combination Key
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.
......@@ -17,66 +18,69 @@ import inputConsumer from '@ohos.multimodalInput.inputConsumer';
## inputConsumer.on
on(type: "key", keyOption: KeyOption, callback: Callback&lt;KeyOption&gt;): void
on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): void
Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **keyOption** will be passed as an input parameter to **callback**.
Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **KeyOptions** will be passed as an input parameter to **callback**.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
**Parameters**
| Name | Type | Mandatory | Description |
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the key input event to listen for. Only **key** is supported. |
| keyOption | [KeyOption](#keyoption) | Yes | Key option, which specifies the condition for combination key input. |
| callback | Callback&lt;KeyOption&gt; | Yes | Callback function. When a key input event that meets the specified options occurs, **keyOption** will be passed as an input parameter to **callback**. |
| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.|
| keyOptions | [KeyOptions](#keyoption) | Yes| Key option, which specifies the condition for combination key input.|
| callback | Callback&lt;KeyOptions&gt; | Yes| Callback used to return the result. When a key input event that meets the specified options occurs, **keyOptions** will be passed as an input parameter to **callback**.|
**Example**
**Example**
```
let keyOption = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOption) {
console.info("preKeys: " + keyOption.preKeys, "finalKey: " + keyOption.finalKey,
"isFinalKeyDown: " + keyOption.isFinalKeyDown, "finalKeyDownDuration: " + keyOption.finalKeyDownDuration)
let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
}
inputConsumer.on('key', keyOption, callback);
inputConsumer.on('key', keyOptions, callback);
```
## inputConsumer.off
off(type: "key", keyOption: KeyOption, callback: Callback&lt;KeyOption&gt;): void
off(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): void
Stops listening for combination key events.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
**Parameters**
| Name | Type | Mandatory | Description |
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the key input event to listen for. Only **key** is supported. |
| keyOption | [KeyOption](#keyoption) | Yes | Key option passed to the key input event when listening starts. |
| callback | Callback&lt;KeyOption&gt; | Yes | Callback function passed to the key input event with the key option when listening starts. |
| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.|
| keyOptions | [KeyOptions](#keyoption) | Yes| Key options passed to the key input event when listening starts.|
| callback | Callback&lt;KeyOptions&gt; | Yes| Callback function passed to the key input event with the key options when listening starts.|
**Example**
**Example**
```
let keyOption = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOption) {
console.info("preKeys: " + keyOption.preKeys, "finalKey: " + keyOption.finalKey,
"isFinalKeyDown: " + keyOption.isFinalKeyDown, "finalKeyDownDuration: " + keyOption.finalKeyDownDuration)
let keyOptions = { preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
}
inputConsumer.off('key', keyOption, callback);
inputConsumer.off('key', keyOptions, callback);
```
## KeyOption
## KeyOptions
Defines the key options that are met when a combination key input event occurs.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
| Name | Type | Mandatory | Description |
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| preKeys | Array | Yes | Array of precedent keys. This parameter can be left empty. There is no requirement on the sequence of precedent keys. |
| finalKey | Number | Yes | Final key in the combination key. This parameter cannot be left blank. |
| isFinalKeyDown | boolean | Yes | Indicates whether the final key is pressed or released. By default, the final key is pressed. |
| finalKeyDownDuration | Number | Yes | Duration for pressing the final key. By default, there is no requirement on the duration. |
| preKeys | Array | Yes| Array of precedent keys. This parameter can be left empty. There is no requirement on the sequence of precedent keys.|
| finalKey | Number | Yes| Final key in the combination key. This parameter cannot be left blank.|
| isFinalKeyDown | boolean | Yes| Indicates whether the final key is pressed or released. By default, the final key is pressed.|
| finalKeyDownDuration | Number | Yes| Duration for pressing the final key. By default, there is no requirement on the duration.|
......@@ -4,7 +4,7 @@
The input device management module is used to listen for the connection, disconnection, and updates of input devices and display information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -59,7 +59,7 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value**
| Name | Description |
| Parameter | Description |
| ---------------------- | ------------------ |
| Promise<Array<number>> | Promise used to return the result.|
......@@ -130,7 +130,7 @@ Obtains the information about an input device. This API uses a promise to return
**Return value**
| Name | Description |
| Parameter | Description |
| ------------------------ | ------------------ |
| Promise<InputDeviceData> | Promise used to return the result.|
......@@ -165,11 +165,18 @@ Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| ------- | -------------------------------------- | ---------------------------------------- |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| Name | Type | Description |
| ---------- | -------------------------------------- | ------------------------------------------------------------ |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | Axis information of the input device. |
| bus | number | Bus type of the input device. |
| product | number | Product information of the input device. |
| vendor | number | Vendor information of the input device. |
| version | number | Version information of the input device. |
| phys | string | Physical address of the input device. |
| uniq | string | Unique ID of the input device. |
## AxisType
......
# Input Monitor
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.
......@@ -15,7 +15,7 @@ import inputMonitor from '@ohos.multimodalInput.inputMonitor';
```
## Required Permissions
## Permissions
ohos.permission.INPUT_MONITORING
......@@ -63,7 +63,7 @@ export default {
## inputMonitor.off
off(type: "touch", receiver: TouchEventReceiver): void
off(type: "touch", receiver?: TouchEventReceiver): void
Stops listening for global input events.
......@@ -109,7 +109,7 @@ Represents the class of the callback used to return the touch event. The value *
### (touchEvent: TouchEvent): Boolean
Represents the callback used to return the touch event. You need to define the name of the callback function in the correct format. Ensure that the input parameter is of the TouchEvent type, and the return value is of the Boolean type.
Represents the callback used to return the touch event. You need to define the name of the callback function in the correct format. Ensure that the input parameter is of the **TouchEvent** type, and the return value is of the **Boolean** type.
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
......
......@@ -110,6 +110,8 @@ send\(options: UDPSendOptions, callback: AsyncCallback<void\>\): void
Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -148,6 +150,8 @@ send\(options: UDPSendOptions\): Promise<void\>
Sends data over a UDPSocket connection. This API uses a promise to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......
# Multimodal Input<a name="EN-US_TOPIC_0000001086316185"></a>
# Multimodal Input
## Overview<a name="section11660541593"></a>
## Overview
OpenHarmony provides a Natural User Interface \(NUI\) for you to interact with your users. Unlike conventional categorization of input methods, OpenHarmony combines input methods of different dimensions into multimodal inputs, so you can easily arm your application with multi-dimensional, natural interaction features by using the application framework and system built-in UI components or APIs.
OpenHarmony provides a Natural User Interface (NUI) for you to interact with your users. Unlike conventional categorization of input methods, OpenHarmony combines input methods of different dimensions into multimodal inputs, so you can easily arm your application with multi-dimensional, natural interaction features by using the application framework and system built-in UI components or APIs.
Specifically, OpenHarmony currently supports traditional input methods such as key and touch inputs.
Specifically, the Multimodal Input subsystem receives input events from various input devices, such as the keyboard, mouse, touchscreen, and touchpad, via the Linux native driver and HDF driver. After that, it normalizes and standardizes the input events, and distributes the events to the Inner SDK. The Inner SDK distributes the events to the ArkUI framework, which then encapsulates the input events and passes them to applications. Alternatively, the Inner SDK can also directly distribute input events to applications through JsKit APIs.
## Directory Structure<a name="section14408467105"></a>
![](figures/multimodal-architecture.png)
## Contents
```
/foundation/multimodalinput/input
......@@ -19,13 +21,51 @@ Specifically, OpenHarmony currently supports traditional input methods such as k
├── uinput # Input event injection module
```
## Usage<a name="section18111235161011"></a>
## Usage
Available APIs of Multimodal Input are event injection ones, which are open only to system apps currently.
### Available APIs
## Repositories Involved<a name="section135327891219"></a>
Available APIs of the Multimodal Input subsystem are event injection ones, which are open only to system applications currently.
**Multimodal input subsystem**
The **inputEventClient** class provides APIs for event injection.
multimodalinput\_input
**Table 1** Major APIs in inputEventClient
| Category| API | Description |
| :------: | :-----------------------------------------------: | :----------------: |
| Key injection| function injectEvent(keyEvent: KeyEvent): number; | Injects events.|
### Usage Description
Currently, only the **BACK** key event can be injected.
When a system app needs to return to the previous directory, you can call the API to inject the **BACK** key event to Multimodal Input, which then transfers this event to the system app, thereby achieving the return effect. The example code is as follows:
```
// Import the required JavaScript API library.
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
// Call the API for injecting events.
let keyEvent = {
isPressed: true, // Action type of the key event. true indicates that the key is being pressed down, and false indicates that the key is being released.
keyCode: 2, // Keycode for the key, for example, 2 for the BACK key.
keyDownDuration: 0, // Duration in which the current key is pressed down before it is released, in milliseconds.
isIntercepted: false // Whether interception is enabled
}
res = inputEventClient.injectEvent({KeyEvent: keyEvent});
```
> **Note:** New APIs must be downward compatible.
### Supported Devices
| Device | Touchscreen| Touchpad| Mouse| Keyboard|
| :---------: | :----: | :----: | :--: | :--: |
| rk3568 | Yes | Yes | Yes | Yes |
| hi3516dv300 | Yes | No | No | No |
## Repositories Involved
**Multimodal Input Subsystem**
multimodalinput\_input
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册