提交 e8afcfc0 编写于 作者: C chyyy0213

modify interface use

Change-Id: Icca7e87a4ecf85661077153a820b57bc89b07a6b
Signed-off-by: Nchyyy0213 <chenhaiying3@huawei.com>
......@@ -3,7 +3,6 @@
- [Application Development Overview](application-dev-guide.md)
- [DevEco Studio \(OpenHarmony\) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [Directory Structure](quick-start/package-structure.md)
- [Getting Started](quick-start/start.md)
- [ArkUI](ui/ui-arkui.md)
- [JavaScript-based Web-like Development Paradigm](ui/ui-arkui-js.md)
......
......@@ -11,7 +11,4 @@
- [Configuring the OpenHarmony App Signature](configuring-openharmony-app-signature.md)
- [Installing and Running Your OpenHarmony App](installing-openharmony-app.md)
- [Directory Structure](package-structure.md)
- [Getting Started](start.md)
- [Preparations](start-overview.md)
- [Getting Started with JavaScript](start-with-js.md)
# Preparations<a name="EN-US_TOPIC_0000001063968051"></a>
## Task Description<a name="section2073881513322"></a>
This document is intended for novices at developing apps. You will learn the development procedure from the following sections to build two pages and implement redirection from the first page to the second one. The following figure shows how the pages look on the [Previewer](https://developer.harmonyos.com/en/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252).
For best results, use the [latest version of DevEco Studio](https://developer.harmonyos.com/en/develop/deveco-studio#download) for your development.
![](figures/3.png)
**Table 1** Comparison between ArkUI paradigms
<a name="table1663194773617"></a>
<table><thead align="left"><tr id="row20632174793610"><th class="cellrowborder" valign="top" width="17.88%" id="mcps1.2.4.1.1"><p id="p1863274783615"><a name="p1863274783615"></a><a name="p1863274783615"></a>Comparison Item</p>
</th>
<th class="cellrowborder" valign="top" width="41.730000000000004%" id="mcps1.2.4.1.2"><p id="p344415455554"><a name="p344415455554"></a><a name="p344415455554"></a>JavaScript-based Web-like Development Paradigm</p>
</th>
<th class="cellrowborder" valign="top" width="40.39%" id="mcps1.2.4.1.3"><p id="p20391115416559"><a name="p20391115416559"></a><a name="p20391115416559"></a>TypeScript-based Declarative Development Paradigm</p>
</th>
</tr>
</thead>
<tbody><tr id="row15632164733618"><td class="cellrowborder" valign="top" width="17.88%" headers="mcps1.2.4.1.1 "><p id="p166323477367"><a name="p166323477367"></a><a name="p166323477367"></a>Language</p>
</td>
<td class="cellrowborder" valign="top" width="41.730000000000004%" headers="mcps1.2.4.1.2 "><p id="p16321947123618"><a name="p16321947123618"></a><a name="p16321947123618"></a>JS</p>
</td>
<td class="cellrowborder" valign="top" width="40.39%" headers="mcps1.2.4.1.3 "><p id="p1563224773617"><a name="p1563224773617"></a><a name="p1563224773617"></a>eTS</p>
</td>
</tr>
<tr id="row17632144716361"><td class="cellrowborder" valign="top" width="17.88%" headers="mcps1.2.4.1.1 "><p id="p10632184713363"><a name="p10632184713363"></a><a name="p10632184713363"></a>Paradigm</p>
</td>
<td class="cellrowborder" valign="top" width="41.730000000000004%" headers="mcps1.2.4.1.2 "><p id="p13632447133617"><a name="p13632447133617"></a><a name="p13632447133617"></a>Web-like paradigm</p>
</td>
<td class="cellrowborder" valign="top" width="40.39%" headers="mcps1.2.4.1.3 "><p id="p15632114710367"><a name="p15632114710367"></a><a name="p15632114710367"></a>Declarative paradigm</p>
</td>
</tr>
<tr id="row2632134753615"><td class="cellrowborder" valign="top" width="17.88%" headers="mcps1.2.4.1.1 "><p id="p46321947183612"><a name="p46321947183612"></a><a name="p46321947183612"></a>Execution</p>
</td>
<td class="cellrowborder" valign="top" width="41.730000000000004%" headers="mcps1.2.4.1.2 "><p id="p1363244717361"><a name="p1363244717361"></a><a name="p1363244717361"></a>Handled by the framework; data-driven automatic UI update</p>
</td>
<td class="cellrowborder" valign="top" width="40.39%" headers="mcps1.2.4.1.3 "><p id="p1463274733610"><a name="p1463274733610"></a><a name="p1463274733610"></a>Handled by the framework; data-driven automatic UI update</p>
</td>
</tr>
<tr id="row126321547173610"><td class="cellrowborder" valign="top" width="17.88%" headers="mcps1.2.4.1.1 "><p id="p963314717366"><a name="p963314717366"></a><a name="p963314717366"></a>Advantages</p>
</td>
<td class="cellrowborder" valign="top" width="41.730000000000004%" headers="mcps1.2.4.1.2 "><p id="p963314710361"><a name="p963314710361"></a><a name="p963314710361"></a>Simple and easy to use</p>
</td>
<td class="cellrowborder" valign="top" width="40.39%" headers="mcps1.2.4.1.3 "><p id="p963315474367"><a name="p963315474367"></a><a name="p963315474367"></a>Simplified development, less memory usage, and higher running performance</p>
</td>
</tr>
</tbody>
</table>
## Before You Start<a name="section965173113911"></a>
1. Install DevEco Studio and configure the development environment. For details, see [Configuring the OpenHarmony SDK](configuring-openharmony-sdk.md).
2. Create a project as instructed in [Creating an OpenHarmony Project](create-openharmony-project.md).
- If you are using the JavaScript language, select **Empty Ability** for **Template** and **JS** for **Language**.
3. Use the [previewer](https://developer.harmonyos.com/en/docs/documentation/doc-guides/previewer-0000001054328973#EN-US_TOPIC_0000001056725592__section16523172216252) or [emulator](https://developer.harmonyos.com/en/docs/documentation/doc-guides/run_simulator-0000001053303709) to run the project.
Now you have created your first OpenHarmony project. You can continue the development by following instructions in [Getting Started with JavaScript](start-with-js.md).
# Getting Started with JavaScript<a name="EN-US_TOPIC_0000001168007068"></a>
For best results, use the [latest version of DevEco Studio](https://developer.harmonyos.com/en/develop/deveco-studio#download) for your development.
## Building the First Page<a name="section1754373063820"></a>
1. Add a **Text** and a **Button** component to the first page.
In the **Project** window, choose **entry** \> **src** \> **main** \> **js** \> **default** \> **pages** \> **index**, open the **index.hml** file, and add the components.
```
<!-- index.hml -->
<div class="container">
<!-- Add text. -->
<text class="text">
Hello World
</text>
<!-- Add a button, set its type to capsule, set button text to Next, and bind it to the launch event. -->
<button class="button" type="capsule" value="Next" onclick="launch"></button>
</div>
```
2. Open the **index.css** file and set text and button styles.
```
/* index.css */
.container {
flex-direction: column; /* Arrange container items vertically. */
justify-content: center; /* Center the items along the main axis of the container. */
align-items: center; /* Center the items along the cross axis of the container. */
width:100%;
height:100%;
}
/* Set the style for the component of the text class. */
.text{
font-size: 42px;
}
/* Set the style for the component of the button class. */
.button {
width: 240px;
height: 60px;
background-color: #007dff;
font-size: 30px;
text-color: white;
margin-top: 20px;
}
```
3. [Preview](https://developer.harmonyos.com/en/docs/documentation/doc-guides/previewer-0000001054328973#EN-US_TOPIC_0000001056725592__section16523172216252) or [run your app on the emulator](https://developer.harmonyos.com/en/docs/documentation/doc-guides/run_simulator-0000001053303709). The following figure shows the running effect.
![](figures/1.png)
## Creating the Second Page<a name="section11544830123813"></a>
1. In the **Project** window, choose **entry** \> **src** \> **main** \> **js** \> **default**, right-click the **pages** folder, and then choose **New** \> **JS Page**. Name the new page **details** and press **Enter**.
Below is the structure of the **pages** folder:
![](figures/en-us_image_0000001167850660.png)
2. Open the **details.hml** file, add the **<text\>** component, and set its layout.
```
<!-- details.hml -->
<div class="container">
<text class="text">
Hi there
</text>
</div>
```
3. Open the **details.css** file and set the text style.
```
/* details.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width:100%;
height:100%;
}
.text {
font-size: 42px;
text-align: center;
}
```
## Implementing Page Redirection<a name="section55441830123814"></a>
1. Open the **index.js** file and import the router module. The page router finds the target page based on its URI for the redirection. The sample code is as follows:
```
// index.js
import router from '@system.router';
export default {
launch() {
router.push ({
uri:'pages/details/details', // Specify the page to be redirected to.
})
}
}
```
2. [Preview](https://developer.harmonyos.com/en/docs/documentation/doc-guides/previewer-0000001054328973#EN-US_TOPIC_0000001056725592__section16523172216252) or [run your app on the emulator](https://developer.harmonyos.com/en/docs/documentation/doc-guides/run_simulator-0000001053303709) again. The following figure shows the running effect.
![](figures/2.png)
Congratulations! You have finished developing your app in JavaScript.
# Getting Started<a name="EN-US_TOPIC_0000001115740240"></a>
- **[Preparations](start-overview.md)**
- **[Getting Started with JavaScript](start-with-js.md)**
......@@ -2111,7 +2111,7 @@ let deviceName = gattClient.getDeviceName().then((data) => {
getRssiValue(callback: AsyncCallback&lt;number&gt;): void
Obtains the received signal strength indication (RSSI) of the peer BLE device. This method uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect-boolean).
Obtains the received signal strength indication (RSSI) of the peer BLE device. This method uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Parameters:**
......@@ -2140,7 +2140,7 @@ let rssi = gattClient.getRssiValue((err, data)=> {
getRssiValue(): Promise&lt;number&gt;
Obtains the RSSI of the peer BLE device. This method uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect-boolean).
Obtains the RSSI of the peer BLE device. This method uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Return values:**
......
......@@ -8,7 +8,7 @@ SystemCapability.DistributedDataManager.RelationalStore.Core
## Usage<a name="section42211227142416"></a>
The **resultSet** object is obtained by using [**RdbStore.query\(\)**](js-apis-data-rdb.md#section6231155031814).
The **resultSet** object is obtained by using [**RdbStore.query\(\)**](js-apis-data-rdb.md#query).
```
import dataRdb from '@ohos.data.rdb';
......@@ -795,4 +795,3 @@ Closes the result set.
})
```
......@@ -22,7 +22,7 @@ Provides the constants of all rule types.
| Name| Type| Description|
| ---------------------------------- | -------- | ------------------------------------------------------ |
| RULE_CAUTION_PRINT_LOG | BigInt | Alarm rule, which is programmed to print a log when an alarm is generated.|
| RULE_CAUTION_TRIGGER_CRASH | BigInt | Alarm rule. When an alarm is generated, the application exits.|
| RULE_CAUTION_TRIGGER_CRASH | BigInt | Alarm rule, which is programmed to force the application to exit when an alarm is generated.|
| RULE_THREAD_CHECK_SLOW_PROCESS | BigInt | Caution rule, which is programmed to detect whether any time-consuming function is invoked.|
| RULE_CHECK_SLOW_EVENT | BigInt | Caution rule, which is programmed to detect whether the event distribution or processing time has exceeded the specified time threshold.|
| RULE_CHECK_ABILITY_CONNECTION_LEAK | BigInt | Caution rule, which is programmed to detect whether ability leakage has occurred.|
......
......@@ -19,9 +19,9 @@ import settings from '@ohos.settings';
None
## settings.getUri
## settings.getUriSync
getUri(name: string): string
getUriSync(name: string): string
Obtains the URI of a data item.
......@@ -38,13 +38,13 @@ Obtains the URI of a data item.
- Example
```
// Obtain the URI of a data item.
let urivar = settings.getUri('settings.screen.brightness');
let urivar = settings.getUriSync('settings.screen.brightness');
```
## settings.getValue
## settings.getValueSync
getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
Obtains the value of a data item.
......@@ -66,18 +66,18 @@ Obtains the value of a data item.
// Obtain the value of 'settings.screen.brightness' (this data item already exists in the database).
let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness);
let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri);
let value = settings.getValue(helper, brightness, '10');
let value = settings.getValueSync(helper, brightness, '10');
```
## settings.setValue
## settings.setValueSync
setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
Sets the value of a data item.
If the specified data item exists in the database, the **setValue** method updates the value of the data item. If the data item does not exist in the database, the **setValue** method inserts the data item into the database.
If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database.
To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** permission.
......@@ -97,10 +97,10 @@ To use this method, you must have the **ohos.permission.WRITE_SYSTEM_SETTING** p
```
import featureAbility from '@ohos.featureAbility';
// Update the value of 'settings.screen.brightness'. (As this data item exists in the database, the setValue method
// Update the value of 'settings.screen.brightness'. (As this data item exists in the database, the setValueSync method
will update the value of the data item.)
let brightness = 'settings.screen.brightness';
let uri = settings.getUri(brightness);
let uri = settings.getUriSync(brightness);
let helper = featureAbility.acquireDataAbilityHelper(uri);
let ret = settings.setValue(helper, brightness, '100');
let ret = settings.setValueSync(helper, brightness, '100');
```
......@@ -586,7 +586,7 @@ Obtains the size of the element and its position relative to the window.
## createIntersectionObserver<a name="section7425195215615"></a>
createIntersectionObserver\(param?: [ObserverParam](#table143341035121917)\):[Observer](#table4506633141711)
createIntersectionObserver\(param?: ObserverParam):Observer
Gets notified of the visibility of an element on the current page.
......
......@@ -61,8 +61,7 @@ Before creating a project, you need to install DevEco Studio. For details, see
![](figures/en-us_image_0000001148858818.png)
Before the installation, you must configure an application signature. For details, see [Configuring the OpenHarmony App Signature](https://gitee.com/openharmony/docs/blob/master/en/application-dev/quick-start/configuring-the-openharmony-app-signature.md). After the installation is complete, click the **Run** icon on the screen to open the application. **Hello World** is displayed in the center of the screen.
Before the installation, you must configure an application signature. For details, see [Configuring the OpenHarmony App Signature](../quick-start/configuring-openharmony-app-signature.md). After the installation is complete, click the **Run** icon on the screen to open the application. **Hello World** is displayed in the center of the screen.
![](figures/en-us_image_0000001158896538.png)
......@@ -3,7 +3,6 @@
- [Compilation and Building](subsys-build.md)
- [Building Guidelines for Mini and Small Systems](subsys-build-mini-lite.md)
- [Building Guidelines for Standard Systems](subsys-build-standard-large.md)
- [Build System Coding Specifications and Best Practices](subsys-build-gn-coding-style-and-best-practice.md)
- [Distributed Remote Startup](subsys-remote-start.md)
- [Graphics](subsys-graphics.md)
- [Graphics](subsys-graphics-overview.md)
......@@ -80,12 +79,10 @@
- [Testing](subsys-testguide-test.md)
- [DFX](subsys-dfx.md)
- [DFX](subsys-dfx-overview.md)
- [Development Guidelines on HiLog ](subsys-dfx-hilog-rich.md)
- [Development Guidelines on HiLog\_Lite](subsys-dfx-hilog-lite.md)
- [HiTrace Development](subsys-dfx-hitrace.md)
- [HiCollie Development](subsys-dfx-hicollie.md)
- [Development Guidelines on HiSysEvent](subsys-dfx-hisysevent.md)
- [HiLog Development](subsys-dfx-hilog-rich.md)
- [HiLog_Lite Development](subsys-dfx-hilog-lite.md)
- [HiSysEvent Development](subsys-dfx-hisysevent.md)
- [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md)
- [HiSysEvent Logging](subsys-dfx-hisysevent-logging.md)
- [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md)
- [HiSysEvent Query](subsys-dfx-hisysevent-query.md)
......
# Development Guidelines on HiLog\_Lite<a name="EN-US_TOPIC_0000001185815838"></a>
# HiLog\_Lite Development<a name="EN-US_TOPIC_0000001185815838"></a>
## Overview<a name="section775017517390"></a>
......
# HiSysEvent Listening<a name="EN-US_TOPIC_0000001185655868"></a>
- [Overview](#section315316685112)
- [Introduction](#section123181433335224)
- [Constraints](#section123181433375224)
- [Development Guidelines](#section315316685113)
- [Available APIs](#section0342191810519)
- [Development Example](#section123181432175110)
## Overview<a name="section315316685112"></a>
HiSysEvent supports listening for events across processes. You can register a listener to listen for concerned events on a real-time basis. For example, you can enable the battery module to listen for power consumption event for power usage analysis.
## Available APIs<a name="section0342191810519"></a>
**Table 1** HiSysEvent listener APIs
<a name="table1844019587496"></a>
<table><thead align="left"><tr id="row1440058184916"><th class="cellrowborder" valign="top" width="48.120000000000005%" id="mcps1.2.3.1.1"><p id="p19441135844915"><a name="p19441135844915"></a><a name="p19441135844915"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.88%" id="mcps1.2.3.1.2"><p id="p13441195815491"><a name="p13441195815491"></a><a name="p13441195815491"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row16441155818499"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p877916438211"><a name="p877916438211"></a><a name="p877916438211"></a>bool HiSysEventManager::AddEventListener(std::shared_ptr&lt;HiSysEventSubscribeCallBack&gt; listener, std::vector&lt;struct ListenerRule&gt;&amp; rules)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Registers a listener for system events. You can listen for certain events by specifying rules.</p>
<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input arguments:</p>
<a name="ul6717142214919"></a><a name="ul6717142214919"></a><ul id="ul6717142214919"><li><strong id="b5330432115819"><a name="b5330432115819"></a><a name="b5330432115819"></a>listener</strong>: callback object for system events.</li><li><strong id="b1518805912597"><a name="b1518805912597"></a><a name="b1518805912597"></a>rules</strong>: rules for event listening.</li></ul>
<p id="p83591223153818"><a name="p83591223153818"></a><a name="p83591223153818"></a>Return values</p>
<a name="ul12105842111913"></a><a name="ul12105842111913"></a><ul id="ul12105842111913"><li><strong id="b117641849702"><a name="b117641849702"></a><a name="b117641849702"></a>0</strong>: Repeated registration is successful.</li><li><strong id="b2682415314"><a name="b2682415314"></a><a name="b2682415314"></a>1</strong>: Initial registration is successful.</li><li>Other values: Registration has failed.</li></ul>
</td>
</tr>
<tr id="row910319443242"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p15104154411248"><a name="p15104154411248"></a><a name="p15104154411248"></a>bool HiSysEventManager::RemoveListener(std::shared_ptr&lt;HiSysEventSubscribeCallBack&gt; listener)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p1104194420248"><a name="p1104194420248"></a><a name="p1104194420248"></a>Removes the listener for system events.</p>
<p id="p7943171095411"><a name="p7943171095411"></a><a name="p7943171095411"></a>Input arguments:</p>
<a name="ul894321075411"></a><a name="ul894321075411"></a><ul id="ul894321075411"><li><strong id="b178371510181317"><a name="b178371510181317"></a><a name="b178371510181317"></a>listener</strong>: callback object for system events.</li></ul>
<p id="p9744631162515"><a name="p9744631162515"></a><a name="p9744631162515"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
**Table 2** HiSysEvent listener rules
<a name="table1144011610564"></a>
<table><thead align="left"><tr id="row124411716175611"><th class="cellrowborder" valign="top" width="48.11%" id="mcps1.2.3.1.1"><p id="p19441151675610"><a name="p19441151675610"></a><a name="p19441151675610"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="51.89%" id="mcps1.2.3.1.2"><p id="p16441171616563"><a name="p16441171616563"></a><a name="p16441171616563"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row174411216105615"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p496413536613"><a name="p496413536613"></a><a name="p496413536613"></a><span>uint32_t</span> ruleType</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><p id="p94416160565"><a name="p94416160565"></a><a name="p94416160565"></a>Rule type. The matching scope includes <strong id="b638713414175"><a name="b638713414175"></a><a name="b638713414175"></a>domain</strong> and <strong id="b128648618171"><a name="b128648618171"></a><a name="b128648618171"></a>eventName</strong>. The value can be any of the following:</p>
<a name="ul1652866141814"></a><a name="ul1652866141814"></a><ul id="ul1652866141814"><li>1: whole word matching.</li><li>2: prefix matching.</li><li>3: regular expression matching.</li><li>Other values: invalid matching mode.</li></ul>
</td>
</tr>
<tr id="row64411816125614"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p1258135313712"><a name="p1258135313712"></a><a name="p1258135313712"></a>std::string domain</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><a name="ul14905926102311"></a><a name="ul14905926102311"></a><ul id="ul14905926102311"><li><strong id="b152431514132110"><a name="b152431514132110"></a><a name="b152431514132110"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
</td>
</tr>
<tr id="row244161615619"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p227913101887"><a name="p227913101887"></a><a name="p227913101887"></a>std::string eventName</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><a name="ul248063132319"></a><a name="ul248063132319"></a><ul id="ul248063132319"><li><strong id="b197622401229"><a name="b197622401229"></a><a name="b197622401229"></a>eventName</strong>: event name. By default, an empty string indicates that the event name is successfully matched.</li></ul>
</td>
</tr>
</tbody>
</table>
**Table 3** HiSysEvent callback object
<a name="table1011703742711"></a>
<table><thead align="left"><tr id="row121187375270"><th class="cellrowborder" valign="top" width="48.25%" id="mcps1.2.3.1.1"><p id="p2118143782719"><a name="p2118143782719"></a><a name="p2118143782719"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.74999999999999%" id="mcps1.2.3.1.2"><p id="p4118037152710"><a name="p4118037152710"></a><a name="p4118037152710"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row111823719274"><td class="cellrowborder" valign="top" width="48.25%" headers="mcps1.2.3.1.1 "><p id="p161181537112712"><a name="p161181537112712"></a><a name="p161181537112712"></a>void HiSysEventSubscribeCallBack::OnHandle(const std::string&amp; domain, const std::string&amp; eventName, const int eventType, const std::string&amp; eventDetail)</p>
</td>
<td class="cellrowborder" valign="top" width="51.74999999999999%" headers="mcps1.2.3.1.2 "><p id="p1772213111011"><a name="p1772213111011"></a><a name="p1772213111011"></a>Callback object for system events.</p>
<p id="p182081719151016"><a name="p182081719151016"></a><a name="p182081719151016"></a>Input arguments:</p>
<a name="ul02091819131015"></a><a name="ul02091819131015"></a><ul id="ul02091819131015"><li><strong id="b19691125212280"><a name="b19691125212280"></a><a name="b19691125212280"></a>domain</strong>: domain to which the event belongs.</li><li><strong id="b144121713192910"><a name="b144121713192910"></a><a name="b144121713192910"></a>eventName</strong>: event name.</li><li><strong id="b410512122915"><a name="b410512122915"></a><a name="b410512122915"></a>eventType</strong>: event type.</li><li><strong id="b89521717103013"><a name="b89521717103013"></a><a name="b89521717103013"></a>eventDetail</strong>: JSON string containing event information.</li></ul>
<p id="p18209419201010"><a name="p18209419201010"></a><a name="p18209419201010"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section123181432175110"></a>
### **C++**<a name="section2016116181902"></a>
In this example, you'll be instructed to register a listener for all system events that belong to the **HIVIEWDFX** domain.
### Introduction<a name="section123181433335224"></a>
HiSysEvent supports listening for events across processes. You can register a listener to listen for concerned events on a real-time basis. For example, you can enable the battery module to listen for power consumption events for power usage analysis.
### Constraints<a name="section123181433375224"></a>
Before subscribing to system events, you need to configure HiSysEvent logging. For details, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
## Development Guidelines<a name="section315316685113"></a>
### Available APIs<a name="section0342191810519"></a>
**Table 1** EventListener APIs
| API| Description|
| -------- | --------- |
|bool HiSysEventManager::AddEventListener(std::shared_ptr&lt;HiSysEventSubscribeCallBackBase&gt; listener, std::vector&lt;ListenerRule&gt;&amp; rules)|Registers a listener for system events. You can listen for certain events by specifying rules. <br><br>Input arguments: <ul><li>**listener**: callback object for system events. </li><li>**rules**: rules for event listening. </li></ul>Return value:<ul><li>**0**: Repeated registration is successful. </li><li>**1**: Initial registration is successful. </li><li>Other values: Registration has failed.</li></ul>|
|bool HiSysEventManager::RemoveListener(std::shared_ptr&lt;HiSysEventSubscribeCallBackBase&gt; listener)|Removes the listener for system events. <br><br>Input argument: <ul><li>**listener**: callback object for system events. </ul>Return value:<br>&emsp;&emsp;None.|
**Table 2** Description of ListenerRule
| API| Description|
| -------- | --------- |
|ListenerRule(const std::string&amp; tag, RuleType ruleType = RuleType::WHOLE_WORD)|Constructor used to create a **ListenerRule** object based on the event tag. <br><br>Input arguments:<ul><li>**tag**: indicates the event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits. </li><li>**ruleType**: indicates the type of the **ListenerRule** object. The value is an enum defined by **RuleType**.</li></ul>|
|ListenerRule(const std::string&amp; domain, const std::string&amp; eventName, RuleType ruleType = RuleType::WHOLE_WORD)|Constructor used to create a **ListenerRule** object based on the event domain and event name. <br><br>Input arguments: <ul><li>**domain**: indicates the event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores (&#95;). </li><li>**eventName**: indicates the event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores (&#95;). </li><li>**ruleType**: indicates the type of the **ListenerRule** object. The value is an enum defined by **RuleType**.</li></ul>|
|ListenerRule(const std::string&amp; domain, const std::string& eventName, const std::string&amp; tag, RuleType ruleType = RuleType::WHOLE_WORD)|Constructor used to create a **ListenerRule** object based on the event domain, event name, and event tag. <br><br>Input arguments:<ul><li>**tag**: indicates the event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits. </li><li>**domain**: indicates the event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores (&#95;). </li><li>**eventName**: indicates the event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores (&#95;). </li><li>**ruleType**: indicates the type of the **ListenerRule** object. The value is an enum defined by **RuleType**.</li></ul>|
**Table 3** Description of RuleType
| Enum| Description|
| ------------ | ------------- |
| WHOLE_WORD | Whole word matching|
| PREFIX | Prefix matching|
| REGULAR | Regular expression matching|
**Table 4** Description of HiSysEventSubscribeCallBackBase
| API| Description|
| -------- | --------- |
|void HiSysEventSubscribeCallBackBase::OnHandle(const std::string&amp; domain, const std::string&amp; eventName, const int eventType, const std::string&amp; eventDetail)|Provides the callback of system events. <br><br>Input arguments: <ul><li>**domain**: indicates the domain to which the event belongs. </li><li>**eventName**: indicates the event name. </li><li>**eventType**: indicates the event type. </li><li>**eventDetail**: indicates the event information, in JSON format. </li></ul>Return value:<br>&emsp;&emsp;None.|
### Development Example<a name="section123181432175110"></a>
C++
1. Develop the source code.
- Import the corresponding header file:
Import the **DemoListener.h** header file, which contains the **DemoListener** class for implementing the custom event callback.
hisysevent\_manager.h
```
#ifndef DEMO_LISTENER_H
#define DEMO_LISTENER_H
- Implement the callback API.
#include "hisysevent_subscribe_callback.h"
HiSysEventSubscribeCallBack::OnHandle\(const std::string& domain, const std::string& eventName, const int eventType, const std::string& eventDetail\)
#include <string>
- Register a callback object.
class DemoListener : public OHOS::HiviewDFX::HiSysEventSubscribeCallBackNative {
public:
explicit DemoListener() : HiSysEventSubscribeCallBackNative() {}
void OnHandle(const std::string& domain, const std::string& eventName, const int eventType,
const std::string& eventDetail);
virtual ~DemoListener() {}
void OnServiceDied();
};
HiSysEventManager::AddEventListener\(std::shared\_ptr<HiSysEventSubscribeCallBack\> listener, std::vector<struct ListenerRule\>& rules\)
#endif DEMO_LISTENER_H
```
Create the **DemoListener.cpp** file, and add the implementation logic of the custom event callback API in the **DemoListener** class.
```
// Register a listener for all system events that belong to the HIVIEWDFX domain.
#include "hisysevent_manager.h"
#include "demo_listener.h"
#include <iostream>
namespace OHOS {
namespace HiviewDFX {
// Implement the API for registering a listener for callback objects.
void HiSysEventToolListener::OnHandle(const std::string& domain, const std::string& eventName,
void DemoListener::OnHandle(const std::string& domain, const std::string& eventName,
const int eventType, const std::string& eventDetail)
{
std::cout << eventDetail << std::endl;
}
void HiSysEventToolListener::OnServiceDied()
void DemoListener::OnServiceDied()
{
std::cout << std::string("service disconnect, exit") << std::endl;
exit(0);
}
} // namespace HiviewDFX
} // namespace OHOS
// Register a listener for callback objects.
auto toolListener = std::make_shared<HiSysEventToolListener>();
struct ListenerRule rule;
rule.ruleType = 1; // 1: default type
rule.domain = "HIVIEWDFX";
std::vector<struct ListenerRule> sysRules;
sysRules.push_back(rule);
HiSysEventManager::AddEventListener(toolListener, sysRules);
```
2. Modify the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the** hisysevent\_native** component.
Call the **AddEventListener** API of the **HiSysEventManager** class to add a listener for system events.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
auto demoListener = std::make_shared<DemoListener>();
// Add a ListenerRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD).
ListenerRule tagRule("dfx");
// Add a ListenerRule object based on the event tag, with RuleType set as REGULAR.
ListenerRule regRule("dfx.*", RuleType::REGULAR);
// Add a ListenerRule object based on the event domain and event name, with RuleType set as PREFIX.
ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX);
std::vector<ListenerRule> sysRules;
sysRules.push_back(tagRule);
sysRules.push_back(regRule);
sysRules.push_back(domainNameRule);
HiSysEventManager::AddEventListener(demoListener, sysRules);
```
2. Configure the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the **hisysevent\_native** component.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
```
# HiSysEvent Logging Configuration<a name="EN-US_TOPIC_0000001080478132"></a>
- [Overview](#section315316685115)
- [Basic Concepts](#section123181432175143)
- [Constraints](#section123181432175114)
- [Writing a YAML File](#section123181432175113)
- [Writing Rules](#section123181432175133)
- [Example](#section123181432175123)
- [Verifying the YAML File](#section123181432175115)
- [Configuring the YAML File Path](#section123181432175135)
- [Compiling the YAML File](#section123181432175137)
- [Logging and Querying Events](#section123181432175139)
## Overview<a name="section315316685115"></a>
If HiSysEvent logging is required for a component, you need to define a YAML file and [configure the YAML file path](#section123181432175135) in the **bundle.js** file. During compilation, the OpenHarmony compilation framework will use the Python compilation script to parse and verify all the YAML files configured in the **bundle.js** file. On completion, the compilation framework will summarize the configuration information in the YAML files and convert the information into a JSON file named **hisysevent.def**. After that, the compilation framework will put the JSON file to a specified path as the basis for the system to determine whether to log system events.
### Basic Concepts<a name="section123181432175143"></a>
Understanding the following concepts would be helpful for you in configuring HiSysEvent logging.
- Event domain
Represents the domain to which an event belongs. It is specified by the **domain** field in the YAML file. For details, see [domain](#section123181432175123) in the example YAML file.
- Event name
Indicates the events in an event domain. For details, see [EVENT\_NAMEA/EVENT\_NAMEB](#section123181432175123) in the example YAML file.
- Parameter
Defines the key values in an event name. For details, see [__BASE/NAME1/NAME2](#section123181432175123) in the example YAML file.
### Constraints<a name="section123181432175114"></a>
- Each YAML file can contain only one event domain, and the domain name cannot be the same as that defined in other YAML files.
- Zero or more event names can be defined for one event domain. The event names in the same event domain must be unique.
- Multiple parameters can be defined for one event name. The parameters in the same event name must be unique. There must be one and only one parameter named **\__BASE** in each event name. See Table 1 for the fields of this parameter and Table 2 for the fields of other custom parameters.
**Table 1** Fields in the \__BASE parameter
| Field| Description|
| ----- | ----- |
| type | Indicates the type of the event. This field is mandatory. <br><br>Value:<ul><li>**FAULT**: fault </li><li>**STATISTIC**: statistics </li><li>**SECURITY**: security </li><li>**BEHAVIOR**: user behavior</li></ul> |
| level | Indicates the level of the event. This field is mandatory. <br><br>Value: <ul><li>**CRITICAL**: critical </li><li>**MINOR**: minor</li></ul> |
| tag | Indicates the tag of the event. This field is mandatory. <br><br>Rule:<ul><li>You can define a maximum of five tags,separated with a space. </li><li>A single tag can contain a maximum of 16 characters, including a to z, A to Z, and 0 to 9.</li></ul>|
| desc | Describes the event name. This field is mandatory. <br><br>Rule:<ul><li>The description contains 3 to 128 characters, including a to z, A to Z, 0 to 9, and underscores (&#95;).</li></ul>|
**Table 2** Description of custom parameters
| Field| Description|
| ----- | ----- |
| type | Indicates the type of a parameter. This field is mandatory. <br><br>Value: <ul><li>BOOL</li><li>UINT8</li><li>UINT16</li><li>INT32</li><li>UINT32</li><li>UINT64</li><li>FLOAT</li><li>DOUBLE</li><li>STRING</li></ul>|
| arrsize | Specifies the length of the parameter of the array type. This field is optional. <br><br>Value range: <ul><li>1-100</li></ul>|
| desc | Describes the parameter. This field is mandatory. <br><br>Rule:<ul><li>The description contains 3 to 128 characters, including a to z, A to Z, 0 to 9, and underscores (&#95;).</li></ul>|
## Writing a YAML File<a name="section123181432175113"></a>
### Writing Rules<a name="section123181432175133"></a>
- Event domain naming rules:
- The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
- The name contains 1 to 16 characters.
- Event naming rules:
- The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
- The name contains 1 to 32 characters.
- The number of internal event names in an event domain cannot exceed 4096.
- Parameter naming rules:
- The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
- The name contains 1 to 32 characters.
- The number of parameters in an event domain cannot exceed 128.
### Example<a name="section123181432175123"></a>
- In the example YAML file, the event domain name is **MODULEA**. The event domain contains two events named **EVENT\_NAMEA** and **EVENT\_NAMEB**.
- **EVENT\_NAMEA** is defined as a critical event of the fault type. The event contains the **NAME1** parameter of the string type, the **NAME2** parameter of the string type, and the **NAME3** parameter of the unsigned short integer type. Therefore, you can perform [real-time subscription](subsys-dfx-hisysevent-listening.md) to the event based on the event domain **MODULEA** and event name **EVENT\_NAMEA**.
- **EVENT\_NAMEB** is defined as a general event of the statistics type. The event contains the **NAME1** parameter of the unsigned short integer type and the **NAME2** parameter of the integer type. Because two event tags named **tag1** and **tag2** are defined for **EVENT\_NAMEB** in the **\__BASE** parameter, you can perform [real-time subscription](subsys-dfx-hisysevent-read.md) to the event based on the event domain **MODULEA** and event name **EVENT\_NAMEB**, or based on the event tag.
```
##########################################
# HiSysEvent definition for MODULEA
##########################################
domain: MODULEA
EVENT_NAMEA:
__BASE: {type: FAULT, level: CRITICAL, desc: event name a}
NAME1: {type: STRING, desc: name1}
NAME2: {type: STRING, desc: name2}
NAME3: {type: UINT16, desc: name3}
EVENT_NAMEB:
__BASE: {type: STATISTIC, level: MINOR, tag: tag1 tag2, desc: event name b}
NAME1: {type: UINT16, desc: name1}
NAME2: {type: INT32, desc: name2}
```
## Verifying the YAML File<a name="section123181432175115"></a>
### Configuring the YAML File Path<a name="section123181432175135"></a>
In the **bundle.js** file, use the ```hisysevent_config``` attribute to specify the YAML file path.
```
{
"name": "@ohos/moduel_a",
"description": "module a",
"version": "3.1",
"license": "Apache License 2.0",
"publishAs": "code-segment",
"segment": {
"destPath": "moduel_a_path"
},
"dirs": {},
"scripts": {},
"component": {
"name": "hisysevent_native",
"subsystem": "hiviewdfx",
"adapted_system_type": [
"standard"
],
"rom": "",
"ram": "",
"hisysevent_config": [
"//moduel_a_path/yaml_file1.yaml",
"//moduel_a_path/yaml_file2.yaml"
],
"deps": {
"components": [
"hilog_native",
"hitrace_native",
"ipc",
"safwk",
"samgr_standard",
"utils_base"
],
"third_party": []
},
"build": {
}
}
}
```
>![](../public_sys-resources/icon-note.gif) **Note:**
>The YAML file can be placed in any directory of the component project as needed. You only need to specify the path in the **bundle.js** file.
### Compiling the YAML File<a name="section123181432175137"></a>
- Perform full compilation.
- During full compilation of the system, the configuration in the YAML files of all components are summarized. After the compilation is complete, the **hisysevent.def** file will be generated in the specified directory.
```
cd absolute path of the project's root directory
./build --product-name <product name>
```
- To obtain the **hisysevent.def** file generated after full compilation, run the following command:
```
cd absolute path of the project's root directory
find out -name hisysevent.def -type f
```
- Single-file compilation:
You can also compile the YAML file of a single component by running the following commands:
```
cd absolute path of the project's root directory
./build/ohos/hisysevent/gen_def_from_all_yaml.py --yaml-list <yaml file list> --def-path <file store directory>
```
**Table 3** Parameters for single-file compilation
| Parameter| Description|
| ------ | ------ |
| --yaml-list | Specifies the paths of the YAML files to be compiled. If there are multiple YAML file paths, separate each of them with a space.|
| --def-path | Specifies the path of the **hisysevent.def** file generated after compilation.|
### Logging and Querying Events<a name="section123181432175139"></a>
1. Push the **hisysevent.def** file to the **/system/etc/hiview/** directory of the device by using the [hdc_std tool](subsys-toolchain-hdc-guide.md).
2. Trigger logging of the custom system events in the YAML file. Then, run [hisysevent -l](subsys-dfx-hisysevent-tool.md) to query historical system events to find out if the logging of the custom system events is successful.
# HiSysEvent Query<a name="EN-US_TOPIC_0000001231455461"></a>
- [Overview](#section279684125212)
- [Development Guidelines](#section315316761113)
- [Available APIs](#section03869128521)
- [Development Example](#section14286111855212)
## Overview<a name="section279684125212"></a>
HiSysEvent provides an API for you to query system events. You can query concerned events by specifying search criteria. For example, for a power consumption module, you can query required system events for analysis.
## Development Guidelines<a name="section315316761113"></a>
### Available APIs<a name="section03869128521"></a>
**Table 1** HiSysEvent query API
| API| Description|
| -------- | --------- |
| bool HiSysEventManager::QueryHiSysEvent(struct QueryArg&amp; queryArg, std::vector&lt;struct QueryRule&gt;&amp; queryRules, std::shared_ptr&lt;HiSysEventQueryCallBackBase&gt; queryCallBack) | Queries system events by specifying search criteria such as the time segment, event domain, and event name. <br><br>Input arguments:<ul><li>**queryArg**: event query parameter. </li><li>**queryRules**: event filtering rules. </li><li>**queryRules**: callback object for query results. </li></ul>Return value:<ul><li>**true**: The query is successful. </li><li>**false**: The query has failed.</li></ul> |
**Table 2** Description of QueryArg
| Attribute| Description|
| -------- | --------- |
| beginTime | Start time, in the **long long int** format.|
| endTime | End time, in the **long long int** format.|
| maxEvents | Maximum number of returned events, in the **int** format.|
**Table 3** Description of QueryRule
| Attribute| Description|
| -------- | --------- |
| ruleType | Rule type, in the **uint32_t** format. The default value is **0**.|
| domain | Domain to which the event belongs, in the **string** format. By default, an empty string indicates that the domain is successfully matched.|
| eventList | Event name list, in the std::vector&lt;std::string&gt; format. By default, an empty string indicates that the event names on the list are successfully matched.|
**Table 4** Description of HiSysEventQueryCallBackBase
| API| Description|
| -------- | --------- |
| void HiSysEventQueryCallBackBase::OnQuery(const ::std::vector&lt;std::string&gt;&amp; sysEvent, const ::std::vector&lt;int64_t&gt;&amp; seq) | Callback object for event query. <br><br>Input arguments:<ul><li>**sysEvent**: event set. </li><li>**seq**: event sequence set. </li></ul>Return value:<br>&emsp;&emsp;None.|
| void HiSysEventQueryCallBackBase::OnComplete(int32_t reason, int32_t total) | Callback object for completion of event query. <br><br>Input arguments:<ul><li>**reason**: reason for completion of event query. The default value is **0**. </li><li>**total**: total number of events returned in this query. </li></ul>Return value:<br>&emsp;&emsp;None.|
### Development Example<a name="section14286111855212"></a>
C++
1. Develop the source code.
- Import the corresponding header file:
hisysevent\_manager.h
- Implement the callback API.
void HiSysEventQueryCallBackBase::OnQuery\(const ::std::vector<std::string\>& sysEvent, const ::std::vector<int64\_t\>& seq\)
void HiSysEventQueryCallBackBase::OnComplete\(int32\_t reason, int32\_t total\)
- Invoke the query API in the corresponding service logic.
HiSysEventManager::QueryHiSysEvent\(struct QueryArg& queryArg, std::vector<struct QueryRule\>& queryRules, std::shared\_ptr<HiSysEventQueryCallBackBase\> queryCallBack\)
```
// In this example, you'll query all system events.
#include "hisysevent_manager.h"
#include <iostream>
namespace OHOS {
namespace HiviewDFX {
// Implement the query callback API.
void HiSysEventToolQuery::OnQuery(const ::std::vector<std::string>& sysEvent,
const ::std::vector<int64_t>& seq)
{
for_each(sysEvent.cbegin(), sysEvent.cend(), [](const std::string &tmp) {
std::cout << tmp << std::endl;
});
}
void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total)
{
return;
}
} // namespace HiviewDFX
} // namespace OHOS
// Invoke the query callback API to obtain system events.
auto queryCallBack = std::make_shared<HiSysEventToolQuery>();
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<struct QueryRule> mRules;
HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack);
```
2. Modify the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the **hisysevent\_native** component.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
```
# HiSysEvent Query<a name="EN-US_TOPIC_0000001231455461"></a>
## Overview<a name="section279684125212"></a>
HiSysEvent provides an API for you to query system events. You can query concerned events by specifying search criteria. For example, for a power consumption module, you can query required system events for analysis.
## Available APIs<a name="section03869128521"></a>
**Table 1** HiSysEvent query API
<a name="table1844019587496"></a>
<table><thead align="left"><tr id="row1440058184916"><th class="cellrowborder" valign="top" width="48.120000000000005%" id="mcps1.2.3.1.1"><p id="p19441135844915"><a name="p19441135844915"></a><a name="p19441135844915"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.88%" id="mcps1.2.3.1.2"><p id="p13441195815491"><a name="p13441195815491"></a><a name="p13441195815491"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row16441155818499"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p114411558204915"><a name="p114411558204915"></a><a name="p114411558204915"></a>bool HiSysEventManager::QueryHiSysEvent(struct QueryArg&amp; queryArg, std::vector&lt;struct QueryRule&gt;&amp; queryRules, std::shared_ptr&lt;HiSysEventQueryCallBack&gt; queryCallBack)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Queries system events by specifying search criteria such as the time segment, event domain, and event name.</p>
<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input arguments:</p>
<a name="ul6717142214919"></a><a name="ul6717142214919"></a><ul id="ul6717142214919"><li><strong id="b13783124325410"><a name="b13783124325410"></a><a name="b13783124325410"></a>queryArg</strong>: event query parameter.</li><li><strong id="b179229305560"><a name="b179229305560"></a><a name="b179229305560"></a>queryRules</strong>: event filtering rules.</li><li><strong id="b1244153910574"><a name="b1244153910574"></a><a name="b1244153910574"></a>queryCallBack</strong>: callback object for query results.</li></ul>
<p id="p83591223153818"><a name="p83591223153818"></a><a name="p83591223153818"></a>Return values</p>
<a name="ul12105842111913"></a><a name="ul12105842111913"></a><ul id="ul12105842111913"><li><strong id="b16711328155919"><a name="b16711328155919"></a><a name="b16711328155919"></a>true</strong>: Operation successful.</li><li><strong id="b1421823714591"><a name="b1421823714591"></a><a name="b1421823714591"></a>false</strong>: Operation failed.</li></ul>
</td>
</tr>
</tbody>
</table>
**Table 2** HiSysEvent query parameters
<a name="table13783145132014"></a>
<table><thead align="left"><tr id="row11784451112013"><th class="cellrowborder" valign="top" width="47.85%" id="mcps1.2.3.1.1"><p id="p187841351152012"><a name="p187841351152012"></a><a name="p187841351152012"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="52.15%" id="mcps1.2.3.1.2"><p id="p4784105182019"><a name="p4784105182019"></a><a name="p4784105182019"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row3784451122012"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p2078414512209"><a name="p2078414512209"></a><a name="p2078414512209"></a>long long beginTime</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p37844517207"><a name="p37844517207"></a><a name="p37844517207"></a>Start time.</p>
</td>
</tr>
<tr id="row1564913158230"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p11649191511239"><a name="p11649191511239"></a><a name="p11649191511239"></a>long long endTime</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p126491715182314"><a name="p126491715182314"></a><a name="p126491715182314"></a>End time.</p>
</td>
</tr>
<tr id="row461821212236"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p461841262313"><a name="p461841262313"></a><a name="p461841262313"></a>int maxEvents</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p1161901214232"><a name="p1161901214232"></a><a name="p1161901214232"></a>Maximum number of query records.</p>
</td>
</tr>
</tbody>
</table>
**Table 3** HiSysEvent query rules
<a name="table1144011610564"></a>
<table><thead align="left"><tr id="row124411716175611"><th class="cellrowborder" valign="top" width="48.03%" id="mcps1.2.3.1.1"><p id="p19441151675610"><a name="p19441151675610"></a><a name="p19441151675610"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="51.970000000000006%" id="mcps1.2.3.1.2"><p id="p16441171616563"><a name="p16441171616563"></a><a name="p16441171616563"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row174411216105615"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p496413536613"><a name="p496413536613"></a><a name="p496413536613"></a><span>uint32_t</span> ruleType</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p94416160565"><a name="p94416160565"></a><a name="p94416160565"></a>Rule type. The default value is <strong id="b196007205817"><a name="b196007205817"></a><a name="b196007205817"></a>0</strong>.</p>
</td>
</tr>
<tr id="row64411816125614"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p1258135313712"><a name="p1258135313712"></a><a name="p1258135313712"></a>std::string domain;</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><a name="ul14905926102311"></a><a name="ul14905926102311"></a><ul id="ul14905926102311"><li><strong id="b9813231789"><a name="b9813231789"></a><a name="b9813231789"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
</td>
</tr>
<tr id="row244161615619"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p227913101887"><a name="p227913101887"></a><a name="p227913101887"></a>std::vector&lt;std::string&gt; eventList</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><a name="ul248063132319"></a><a name="ul248063132319"></a><ul id="ul248063132319"><li><strong id="b172129351784"><a name="b172129351784"></a><a name="b172129351784"></a>eventList</strong>: event name list. By default, an empty string indicates that the event names on the list are successfully matched.</li></ul>
</td>
</tr>
</tbody>
</table>
**Table 4** HiSysEvent query callback objects
<a name="table1451320549112"></a>
<table><thead align="left"><tr id="row951420547116"><th class="cellrowborder" valign="top" width="48.03%" id="mcps1.2.3.1.1"><p id="p15141546117"><a name="p15141546117"></a><a name="p15141546117"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.970000000000006%" id="mcps1.2.3.1.2"><p id="p165141654151113"><a name="p165141654151113"></a><a name="p165141654151113"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row35141554151115"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p4714143785410"><a name="p4714143785410"></a><a name="p4714143785410"></a>void HiSysEventQueryCallBack::OnQuery(const ::std::vector&lt;std::string&gt;&amp; sysEvent, const ::std::vector&lt;int64_t&gt;&amp; seq)</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p1772213111011"><a name="p1772213111011"></a><a name="p1772213111011"></a>Callback object for event query.</p>
<p id="p182081719151016"><a name="p182081719151016"></a><a name="p182081719151016"></a>Input arguments:</p>
<a name="ul02091819131015"></a><a name="ul02091819131015"></a><ul id="ul02091819131015"><li><strong id="b132316517135"><a name="b132316517135"></a><a name="b132316517135"></a>sysEvent</strong>: event set.</li><li><strong id="b185101961310"><a name="b185101961310"></a><a name="b185101961310"></a>seq</strong>: event sequence set.</li></ul>
<p id="p18209419201010"><a name="p18209419201010"></a><a name="p18209419201010"></a>Return value: none</p>
</td>
</tr>
<tr id="row15141154161111"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p561110151119"><a name="p561110151119"></a><a name="p561110151119"></a>void HiSysEventQueryCallBack::OnComplete(int32_t reason, int32_t total)</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p126315352130"><a name="p126315352130"></a><a name="p126315352130"></a>Callback object for completion of event query.</p>
<p id="p6631235191316"><a name="p6631235191316"></a><a name="p6631235191316"></a>Input arguments:</p>
<a name="ul106383518130"></a><a name="ul106383518130"></a><ul id="ul106383518130"><li><strong id="b855743017177"><a name="b855743017177"></a><a name="b855743017177"></a>reason</strong>: reason for completion of event query. The default value is <strong id="b5175337111718"><a name="b5175337111718"></a><a name="b5175337111718"></a>0</strong>.</li><li><strong id="b1196583151911"><a name="b1196583151911"></a><a name="b1196583151911"></a>total</strong>: total number of events returned in this query.</li></ul>
<p id="p176313516133"><a name="p176313516133"></a><a name="p176313516133"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section14286111855212"></a>
### **C++**<a name="section162045551743"></a>
In this example, you'll be instructed to query all system events.
1. Develop the source code.
- Import the corresponding header file:
hisysevent\_manager.h
- Implement the callback API.
void HiSysEventQueryCallBack::OnQuery\(const ::std::vector<std::string\>& sysEvent, const ::std::vector<int64\_t\>& seq\)
void HiSysEventQueryCallBack::OnComplete\(int32\_t reason, int32\_t total\)
- Invoke the query API in the corresponding service logic.
HiSysEventManager::QueryHiSysEvent\(struct QueryArg& queryArg, std::vector<struct QueryRule\>& queryRules, std::shared\_ptr<HiSysEventQueryCallBack\> queryCallBack\)
```
// In this example, you'll query all system events.
#include "hisysevent_manager.h"
#include <iostream>
namespace OHOS {
namespace HiviewDFX {
// Implement the query callback API.
void HiSysEventToolQuery::OnQuery(const ::std::vector<std::string>& sysEvent,
const ::std::vector<int64_t>& seq)
{
for_each(sysEvent.cbegin(), sysEvent.cend(), [](const std::string &tmp) {
std::cout << tmp << std::endl;
});
}
void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total)
{
return;
}
} // namespace HiviewDFX
} // namespace OHOS
// Invoke the query callback API to obtain system events.
auto queryCallBack = std::make_shared<HiSysEventToolQuery>();
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<struct QueryRule> mRules;
HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack);
```
2. Modify the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the** hisysevent\_native** component.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
```
# HiSysEvent Development<a name="EN-US_TOPIC_0000001195021448"></a>
# DHiSysEvent Development<a name="EN-US_TOPIC_0000001195021448"></a>
- **[HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md)**
- **[HiSysEvent Logging](subsys-dfx-hisysevent-logging.md)**
- **[HiSysEvent Listening](subsys-dfx-hisysevent-listening.md)**
- **[HiSysEvent Query](subsys-dfx-hisysevent-querying.md)**
- **[HiSysEvent Query](subsys-dfx-hisysevent-query.md)**
- **[HiSysEvent Tool Usage](subsys-dfx-hisysevent-tool.md)**
......
......@@ -3,7 +3,6 @@
- [应用开发导读](application-dev-guide.md)
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [包结构说明](quick-start/package-structure.md)
- [快速入门](quick-start/start.md)
- [Ability框架](ability/Readme-CN.md)
- 方舟开发框架(ArkUI)
- [基于JS扩展的类Web开发范式](ui/ui-arkui-js.md)
......
......@@ -25,6 +25,9 @@
AudioPlayer支持的src媒体源输入类型可参考:[src属性说明](../reference/apis/js-apis-media.md#audioplayer_属性)
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
......@@ -80,7 +83,18 @@ function printfDescription(obj) {
let audioPlayer = media.createAudioPlayer();
SetCallBack(audioPlayer); //设置事件回调
//2、用户选择音频,设置uri
audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
//3、播放音频
audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调
//4、跳转播放位置
......@@ -111,6 +125,9 @@ audioPlayer = undefined;
### 正常播放场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
......@@ -128,13 +145,27 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
/* 用户选择音频,设置uri */
audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
/* 用户选择视频设置fd(本地播放) */
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
```
### 切歌场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
......@@ -152,16 +183,42 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
/* 用户选择音频,设置uri */
audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
/* 用户选择视频设置fd(本地播放) */
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
/* 播放一段时间后,下发切歌指令 */
audioPlayer.reset();
audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/next.mp3';
/* 用户选择视频设置fd(本地播放) */
let fdNextPath = 'fd://'
let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(nextPath).then(fdNumber) => {
fdNextPath = fdNextPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdNextPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdNextPath;
```
### 单曲循环场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
......@@ -179,7 +236,19 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
/* 用户选择音频,设置uri */
audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
audioPlayer.loop = true; //设置循环播放属性
/* 用户选择视频设置fd(本地播放) */
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
audioPlayer.loop = true; //设置循环播放属性
```
\ No newline at end of file
......@@ -23,6 +23,11 @@
包含流程:创建实例,设置录制参数,录制音频,暂停录制,恢复录制,停止录制,释放资源等流程。
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber;
function SetCallBack(audioRecorder) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调
console.log('prepare success');
......@@ -57,6 +62,31 @@ function SetCallBack(audioRecorder) {
});
}
// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
async function getFd(pathName) {
let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) {
let args = dataUri.id.toString();
let fetchOp = {
selections : fileKeyObj.ID + "=?",
selectionArgs : [args],
}
let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber;
}
}
await getFd('01.mp3');
// 1.创建实例
let audioRecorder = media.createAudioRecorder();
// 2.设置回调
......@@ -68,7 +98,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
uri : testFdNumber, // testFdNumber由getFd生成
location : { latitude : 30, longitude : 130},
}
audioRecorder.prepare(audioRecorderConfig);
......@@ -92,6 +122,11 @@ audioRecorder = undefined;
与全流程场景不同,不包括暂停录制,恢复录制的过程。
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber;
function SetCallBack(audioPlayer) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调
console.log('prepare success');
......@@ -108,6 +143,32 @@ function SetCallBack(audioPlayer) {
console.log('audio recorder release success');
});
}
// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
async function getFd(pathName) {
let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) {
let args = dataUri.id.toString();
let fetchOp = {
selections : fileKeyObj.ID + "=?",
selectionArgs : [args],
}
let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber;
}
}
await getFd('01.mp3');
// 1.创建实例
let audioRecorder = media.createAudioRecorder();
// 2.设置回调
......@@ -119,7 +180,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
uri : testFdNumber, // testFdNumber由getFd生成
location : { latitude : 30, longitude : 130},
}
audioRecorder.prepare(audioRecorderConfig)
......
......@@ -30,10 +30,21 @@
VideoPlayer支持的url媒体源输入类型可参考:[url属性说明](../reference/apis/js-apis-media.md#videoplayer_属性)
Xcomponent创建方法可参考:[Xcomponent创建方法](#Xcomponent创建方法)
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
......@@ -67,10 +78,19 @@ await media.createVideoPlayer().then((video) => {
}
}, failureCallback).catch(catchCallback);
// 用户选择视频设置url
videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
// 用户选择视频设置fd(本地播放)
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
......@@ -147,9 +167,18 @@ surfaceID = undefined;
### 正常播放场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
......@@ -191,10 +220,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
// 用户选择视频设置url
videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
// 用户选择视频设置fd(本地播放)
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
......@@ -215,9 +253,18 @@ await videoPlayer.play().then(() => {
### 切视频场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
......@@ -259,10 +306,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
// 用户选择视频设置url
videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
// 用户选择视频设置fd(本地播放)
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
......@@ -285,7 +341,19 @@ await videoPlayer.reset().then(() => {
console.info('reset success');
}, failureCallback).catch(catchCallback);
videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/next.mp4';
// 用户选择视频设置fd(本地播放)
let fdNextPath = 'fd://'
let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4';
await fileIO.open(nextPath).then(fdNumber) => {
fdNextPath = fdNextPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdNextPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
videoPlayer.url = fdNextPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
......@@ -306,9 +374,18 @@ await videoPlayer.play().then(() => {
### 单个视频循环场景
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
......@@ -350,10 +427,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
// 用户选择视频设置url
videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
// 用户选择视频设置fd(本地播放)
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}),catch((err) => {
console.info('open fd failed err is' + err);
});
// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
......@@ -372,4 +458,16 @@ videoPlayer.loop = true;
await videoPlayer.play().then(() => {
console.info('play success');
}, failureCallback).catch(catchCallback);
```
\ No newline at end of file
```
### Xcomponent创建方法
```js
播放视频中获取surfaceID依赖了Xcomponent,需要创建一个和xxx.js同名的xxx.hml文件,xxx.hml里面需要添加如下代码
<xcomponent id = 'Xcomponent'
if = "{{isFlush}}" // 刷新surfaceID,isFlush赋值false再赋值true为一次刷新,会主动再次加载LoadXcomponet获取新的surfaceID
type = 'surface'
onload = 'LoadXcomponet' // 默认加载接口
style = "wodth:720px;height:480px;border-color:red;border-width:5px;"> // 设置窗口宽高等属性
</xcomponent>
```
......@@ -23,6 +23,36 @@
包含流程:创建实例,设置录制参数,录制视频,暂停录制,恢复录制,停止录制,释放资源等流程。
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber;
// pathName是传入的录制文件名,例如:01.mp4,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp4
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
async function getFd(pathName) {
let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) {
let args = dataUri.id.toString();
let fetchOp = {
selections : fileKeyObj.ID + "=?",
selectionArgs : [args],
}
let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber;
}
}
await getFd('01.mp4');
let videoProfile = {
audioBitrate : 48000,
audioChannels : 2,
......@@ -40,7 +70,7 @@ let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
url : 'file:///data/media/01.mp4',
url : testFdNumber, // testFdNumber由getFd生成
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
......@@ -61,6 +91,7 @@ function catchCallback(error) {
let videoRecorder = null; // videoRecorder空对象在createVideoRecorder成功后赋值
let surfaceID = null; // 用于保存getInputSurface返回的surfaceID
// 创建videoRecorder对象
await media.createVideoRecorder().then((recorder) => {
console.info('case createVideoRecorder called');
......
......@@ -10,7 +10,3 @@
- [配置OpenHarmony应用签名信息](configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](installing-openharmony-app.md)
- [包结构说明](package-structure.md)
- 快速入门
- [开发准备](start-overview.md)
- [使用JS语言开发](start-with-js.md)
- [使用eTS语言开发](start-with-ets.md)
# 开发准备
## 任务说明
本文档适用于应用开发的初学者。通过构建一个简单的具有页面跳转功能的应用(如下图[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行效果所示),熟悉应用开发流程。
为确保运行效果,本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
![zh-cn_image_0000001089359413](figures/zh-cn_image_0000001089359413.png)
**表1** 方舟开发框架的对比
| 比较项 | 基于JS扩展的类Web开发范式 | 基于TS扩展的声明式开发范式 |
| -------- | -------- | -------- |
| 语言生态 | JS | eTS |
| 接口方式 | 类Web范式 | 声明式 |
| 执行方式 | 框架层处理,基于数据驱动的UI自动变更 | 框架层处理,基于数据驱动的UI自动变更 |
| 相对优势 | 轻量化,开发更简便 | 极简开发,内存占用更少、运行性能更高 |
接下来,分别使用JS语言、eTS语言实现上述两个页面跳转的功能。
## 开发准备
1. 开始前请参考[配置OpenHarmony SDK](../quick-start/configuring-openharmony-sdk.md),完成**DevEco Studio**的安装和开发环境配置。
2. 开发环境配置完成后,请参考[创建OpenHarmony工程](../quick-start/use-wizard-to-create-project.md)创建工程。
- 使用JS语言开发,模板选择Empty Ability,Language选择JS。
- 使用eTS语言开发,模板选择Empty Ability,Language选择eTS。
3. 工程创建完成后,使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行该工程。
完成上述操作后,请参考[使用JS语言开发](../quick-start/start-with-js.md)[使用eTS语言开发](../quick-start/start-with-ets.md)继续下一步的学习。
# 使用eTS语言开发
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 请使用DevEco Studio V3.0.0.601 Beta1及更高版本。本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
## 创建eTS工程
1. 打开DevEco Studio,创建一个新工程,选择模板,如Empty Ability:
![zh-cn_image_0000001238733799](figures/zh-cn_image_0000001238733799.png)
2. 进入配置工程界面,Project Type选择Application,Language选择eTS,其他参数根据实际需要设置即可。
![zh-cn_image_0000001238853759](figures/zh-cn_image_0000001238853759.png)
## 编写第一个页面
1. 工程创建完成后,在"Project"窗口,点击entry &gt; src &gt; main &gt; ets &gt; default &gt; pages,打开index.ets文件。
![zh-cn_image_0000001213883165](figures/zh-cn_image_0000001213883165.png)
2. 第一个页面由Flex容器组件、Text组件和Button组件构成。在index.ets中编写并设置页面组件的属性和样式,示例代码如下所示:
```
@Entry
@Component
struct Index {
build() {
//Flex容器组件
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
//Text组件
Text('Hello World')
.fontSize(60)
.fontWeight(500)
//Button组件
Button('Next')
.fontSize(40)
.fontWeight(500)
.width(280)
.height(60)
}
//容器整体宽高
.width('100%')
.height('100%')
}
}
```
3. 使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示:
![zh-cn_image_0000001168898456](figures/zh-cn_image_0000001168898456.png)
## 创建第二个页面
1. 在"Project"窗口,打开entry &gt; src &gt; main &gt; ets &gt; default,右键点击pages文件夹,选择NeweTS Page,命名为details,单击回车键。创建完成后,可以看到pages文件夹下的文件目录结构如下:
![zh-cn_image_0000001214043107](figures/zh-cn_image_0000001214043107.png)
2. 第二个页面由Flex容器组件、Text组件构成。在details.ets中编写并设置页面组件的属性和样式,示例代码如下所示:
```
@Entry
@Component
struct Details {
build() {
//Flex容器组件
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
//Text组件
Text('Hi there')
.fontSize(60)
.fontWeight(500)
}
//容器整体宽高
.width('100%')
.height('100%')
}
}
```
## 实现页面跳转
1. 打开第一个页面的index.ets文件,导入router模块,页面路由router根据页面的uri来找到目标页面,从而实现跳转。示例代码如下:
```
//导入router模块
import router from '@system.router';
@Entry
@Component
struct Index {
build() {
//Flex容器组件
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
//Text组件
Text('Hello World')
.fontSize(60)
.fontWeight(500)
//Button组件
Button('Next')
.fontSize(40)
.fontWeight(500)
.width(280)
.height(60)
//点击Button实现页面跳转
.onClick(() => { router.push({ uri: 'pages/details' }) })
}
//容器整体宽高
.width('100%')
.height('100%')
}
}
```
2. 再次使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示:
![zh-cn_image_0000001169221404](figures/zh-cn_image_0000001169221404.png)
恭喜你,至此已成功完成快速入门-使用eTS语言开发。
# 使用JS语言开发(传统代码方式)
为确保运行效果,本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。
## 编写第一个页面
1. 第一个页面内有一个文本和一个按钮,通过text和button组件来实现。
在"Project"窗口,选择entry &gt; src &gt; main &gt; js &gt; default &gt; pages &gt; index,打开index.hml文件,添加一个文本和一个按钮,示例代码如下:
```
<!-- index.hml -->
<div class="container">
<!-- 添加一个文本 -->
<text class="text">
Hello World
</text>
<!-- 添加一个按钮,按钮样式设置为胶囊型,文本显示为Next,绑定launch事件 -->
<button class="button" type="capsule" value="Next" onclick="launch"></button>
</div>
```
2. 打开index.css文件,设置文本和按钮的样式,示例代码如下:
```
/* index.css */
.container {
flex-direction: column; /* 设置容器内的项目纵向排列 */
justify-content: center; /* 设置项目位于容器主轴的中心 */
align-items: center; /* 项目在交叉轴居中 */
width:100%;
height:100%;
}
/* 对class="text"的组件设置样式 */
.text{
font-size: 42px;
}
/* 对class="button"的组件设置样式 */
.button {
width: 240px;
height: 60px;
background-color: #007dff;
font-size: 30px;
text-color: white;
margin-top: 20px;
}
```
3. 使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示:
![zh-cn_image_0000001167690688](figures/zh-cn_image_0000001167690688.png)
## 创建另一个页面
1. 在"Project"窗口,打开entry &gt; src &gt; main &gt; js &gt; default,右键点击pages文件夹,选择NewJS Page,命名为details,单击回车键。
创建完成后,可以看到pages文件夹下的文件目录结构如下:
![zh-cn_image_0000001167850660](figures/zh-cn_image_0000001167850660.png)
2. 打开details.hml文件,添加一个文本,示例代码如下:
```
<!-- details.hml -->
<div class="container">
<text class="text">
Hi there
</text>
</div>
```
3. 打开details.css文件,设置文本的样式,示例代码如下:
```
/* details.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width:100%;
height:100%;
}
.text {
font-size: 42px;
text-align: center;
}
```
## 实现页面跳转
1. 打开第一个页面的index.js文件,导入router模块,页面路由router根据页面的uri来找到目标页面,从而实现跳转。示例代码如下:
```
// index.js
import router from '@system.router';
export default {
launch() {
router.push ({
uri:'pages/details/details', // 指定要跳转的页面
})
}
}
```
2. 再次使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示:
![zh-cn_image_0000001213130527](figures/zh-cn_image_0000001213130527.png)
恭喜你,至此已成功完成快速入门-使用JS语言开发。
# 快速入门
- **[开发准备](start-overview.md)**
- **[使用JS语言开发](start-with-js.md)**
- **[使用eTS语言开发](start-with-ets.md)**
\ No newline at end of file
......@@ -216,4 +216,13 @@ let promise = AtManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSI
promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
```
\ No newline at end of file
```
### GrantStatus
表示授权状态的枚举。
| 名称 | 默认值 | 描述 |
| ----------------------------- | ---------------------- | ----------------------- |
| PERMISSION_DENIED | -1 | 表示未授权。 |
| PERMISSION_GRANTED | 0 | 表示已授权。 |
\ No newline at end of file
......@@ -55,15 +55,15 @@ add(element: T): boolean
**示例:**
```
let arrayList = new ArrayList();
arrayList.add("a");
arrayList.add(1);
let b = [1, 2, 3];
arrayList.add(b);
let c = {name: "lala", age: "13"};
arrayList.add(false);
```
```
let arrayList = new ArrayList();
let result = arrayList.add("a");
let result1 = arrayList.add(1);
let b = [1, 2, 3];
let result2 = arrayList.add(b);
let c = {name: "lala", age: "13"};
let result3 = arrayList.add(false);
```
### insert
......@@ -109,9 +109,9 @@ has(element: T): boolean
```
let arrayList = new ArrayList();
arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
let result = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
arrayList.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
let result1 = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
```
### getIndexOf
......@@ -143,7 +143,7 @@ arrayList.add(2);
arrayList.add(1);
arrayList.add(2);
arrayList.add(4);
arrayList.getIndexOf(2);
let result = arrayList.getIndexOf(2);
```
### getLastIndexOf
......@@ -175,7 +175,7 @@ arrayList.add(2);
arrayList.add(1);
arrayList.add(2);
arrayList.add(4);
arrayList.getLastIndexOf(2);
let result = arrayList.getLastIndexOf(2);
```
### removeByIndex
......@@ -205,7 +205,7 @@ arrayList.add(4);
arrayList.add(5);
arrayList.add(2);
arrayList.add(4);
arrayList.removeByIndex(2);
let result = arrayList.removeByIndex(2);
```
### remove
......@@ -234,7 +234,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.remove(2);
let result = arrayList.remove(2);
```
### removeByRange
......@@ -264,7 +264,7 @@ arrayList.removeByRange(2, 6);
```
### replaceAllElements
replaceAllElements(callbackfn: (value: T, index?: number, arraylist?: ArrayList&lt;T&gt;) => T,
replaceAllElements(callbackfn: (value: T, index?: number, arrlist?: ArrayList&lt;T&gt;) => T,
thisArg?: Object): void
用户操作ArrayList中的元素,用操作后的元素替换原元素并返回操作后的元素。
......@@ -280,9 +280,9 @@ callbackfn的参数说明:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| value | T | 是 | 当前遍历到的元素 |
| index | number | 否 | 当前遍历到的下标值 |
| arraylist | ArrayList&lt;T&gt; | 否 | 当前调用replaceAllElements方法的实例对象 |
| value | T | 是 | 当前遍历到的元素 |
| index | number | 否 | 当前遍历到的下标值 |
| arrlist | ArrayList&lt;T&gt; | 否 | 当前调用replaceAllElements方法的实例对象。 |
**示例:**
......@@ -301,7 +301,7 @@ arrayList.replaceAllElements((value, index) => {
```
### forEach
forEach(callbackfn: (value: T, index?: number, arraylist?: ArrayList&lt;T&gt;) => void,
forEach(callbackfn: (value: T, index?: number, arrlist?: ArrayList&lt;T&gt;) => void,
thisArg?: Object): void
通过回调函数来遍历ArrayList实例对象上的元素以及元素对应的下标。
......@@ -319,7 +319,7 @@ callbackfn的参数说明:
| -------- | -------- | -------- | -------- |
| value | T | 是 | 当前遍历到的元素。 |
| index | number | 否 | 当前遍历到的下标值。 |
| arraylist | ArrayList&lt;T&gt; | 否 | 当前调用forEach方法的实例对象。 |
| arrlist | ArrayList&lt;T&gt; | 否 | 当前调用forEach方法的实例对象。 |
**示例:**
......@@ -391,9 +391,9 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.subArrayList(2, 4);
arrayList.subArrayList(4, 3);
arrayList.subArrayList(2, 6);
let result1 = arrayList.subArrayList(2, 4);
let result2 = arrayList.subArrayList(4, 3);
let result3 = arrayList.subArrayList(2, 6);
```
### clear
......@@ -415,7 +415,8 @@ arrayList.clear();
### clone
clone(): ArrayList&lt;T&gt;
克隆一个与ArrayList一模一样的实例,并返回克隆后的实例,修改克隆后的实例并不会影响原实例。
克隆一个与ArrayList相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。
**返回值:**
......@@ -431,7 +432,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.clone();
let result = arrayList.clone();
```
### getCapacity
......@@ -453,7 +454,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.getCapacity();
let result = arrayList.getCapacity();
```
### convertToArray
......@@ -475,7 +476,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.convertToArray();
let result = arrayList.convertToArray();
```
### isEmpty
......@@ -497,7 +498,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.isEmpty();
let result = arrayList.isEmpty();
```
### increaseCapacityTo
......
......@@ -239,7 +239,7 @@ getRemoteDeviceClass(deviceId: string): DeviceClass
| 类型 | 说明 |
| -------- | -------- |
| [DeviceClass](#DeviceClass) | 远程设备的类别。 |
| [DeviceClass](#deviceclass) | 远程设备的类别。 |
**示例:**
......@@ -1982,7 +1982,7 @@ if (retWriteDesc) {
setBLEMtuSize(mtu: number): boolean
client协商远端蓝牙低功耗设备的最大传输单元(Maximum Transmission Unit, MTU),调用connect接口连接成功后才能使用。
client协商远端蓝牙低功耗设备的最大传输单元(Maximum Transmission Unit, MTU),调用[connect](#connect)接口连接成功后才能使用。
**参数:**
......@@ -2196,7 +2196,7 @@ let deviceName = gattClient.getDeviceName().then((data) => {
getRssiValue(callback: AsyncCallback&lt;number&gt;): void
client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect-boolean)接口连接成功后才能使用。
client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。
**参数:**
......@@ -2225,7 +2225,7 @@ let rssi = gattClient.getRssiValue((err, data)=> {
getRssiValue(): Promise&lt;number&gt;
client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect-boolean)接口连接成功后才能使用。
client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。
**返回值:**
......@@ -2277,7 +2277,7 @@ let rssi = gattClient.getRssiValue().then((data) => {
| -------- | -------- | -------- | -------- | -------- |
| uuid | string | 是 | 是 | spp单据的uuid。 |
| isPrimary | boolean | 是 | 是 | 是否是安全通道。 |
| type | [SppType](#SppType) | 是 | 是 | Spp链路类型。 |
| type | [SppType](#spptype) | 是 | 是 | Spp链路类型。 |
## SppType
......@@ -2297,8 +2297,8 @@ let rssi = gattClient.getRssiValue().then((data) => {
| -------- | -------- | -------- | -------- | -------- |
| serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
| isPrimary | boolean | 是 | 是 | 如果是主服务设置为true,否则设置为false。 |
| characteristics | Array&lt;[BLECharacteristic](#BLECharacteristic)&gt; | 是 | 是 | 当前服务包含的特征列表。 |
| includeServices | Array&lt;[GattService](#GattService)&gt; | 是 | 是 | 当前服务依赖的其它服务。 |
| characteristics | Array&lt;[BLECharacteristic](#blecharacteristic)&gt; | 是 | 是 | 当前服务包含的特征列表。 |
| includeServices | Array&lt;[GattService](#gattservice)&gt; | 是 | 是 | 当前服务依赖的其它服务。 |
## BLECharacteristic
......@@ -2310,7 +2310,7 @@ let rssi = gattClient.getRssiValue().then((data) => {
| serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
| characteristicUuid | string | 是 | 是 | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
| characteristicValue | ArrayBuffer | 是 | 是 | 特征对应的二进制值。 |
| descriptors | Array&lt;[BLEDescriptor](#BLEDescriptor)&gt; | 是 | 是 | 特定特征的描述符列表。 |
| descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | 是 | 是 | 特定特征的描述符列表。 |
## BLEDescriptor
......@@ -2415,7 +2415,7 @@ let rssi = gattClient.getRssiValue().then((data) => {
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| deviceId | string | 是 | 否 | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
| state | [ProfileConnectionState](#ProfileConnectionState) | 是 | 是 | 表示BLE连接状态的枚举。 |
| state | [ProfileConnectionState](#profileconnectionState) | 是 | 是 | 表示BLE连接状态的枚举。 |
## ProfileConnectionState
......@@ -2448,8 +2448,8 @@ let rssi = gattClient.getRssiValue().then((data) => {
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| interval | number | 是 | 是 | 表示扫描结果上报延迟时间,默认值为0。 |
| dutyMode | [ScanDuty](#ScanDuty) | 是 | 是 | 表示扫描模式,默认值为SCAN_MODE_LOW_POWER。 |
| matchMode | [MatchMode](#MatchMode) | 是 | 是 | 表示硬件的过滤匹配模式,默认值为MATCH_MODE_AGGRESSIVE。 |
| dutyMode | [ScanDuty](#scanduty) | 是 | 是 | 表示扫描模式,默认值为SCAN_MODE_LOW_POWER。 |
| matchMode | [MatchMode](#matchmode) | 是 | 是 | 表示硬件的过滤匹配模式,默认值为MATCH_MODE_AGGRESSIVE。 |
## ScanDuty
......@@ -2517,8 +2517,8 @@ let rssi = gattClient.getRssiValue().then((data) => {
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| serviceUuids | Array&lt;string&gt; | 是 | 是 | 表示要广播的服务&nbsp;UUID&nbsp;列表。 |
| manufactureData | Array&lt;[ManufactureData](#ManufactureData)&gt; | 是 | 是 | 表示要广播的广播的制造商信息列表。 |
| serviceData | Array&lt;[ServiceData](#ServiceData)&gt; | 是 | 是 | 表示要广播的服务数据列表。 |
| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | 是 | 是 | 表示要广播的广播的制造商信息列表。 |
| serviceData | Array&lt;[ServiceData](#servicedata)&gt; | 是 | 是 | 表示要广播的服务数据列表。 |
## ManufactureData
......@@ -2557,8 +2557,8 @@ let rssi = gattClient.getRssiValue().then((data) => {
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| majorClass | [MajorClass](#MajorClass) | 是 | 否 | 表示蓝牙设备主要类别的枚举。 |
| majorMinorClass | [MajorMinorClass](#MajorMinorClass) | 是 | 否 | 表示主要次要蓝牙设备类别的枚举。 |
| majorClass | [MajorClass](#majorclass) | 是 | 否 | 表示蓝牙设备主要类别的枚举。 |
| majorMinorClass | [MajorMinorClass](#majorminorclass) | 是 | 否 | 表示主要次要蓝牙设备类别的枚举。 |
| classOfDevice | number | 是 | 否 | 表示设备类别。 |
......
......@@ -4,7 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
......@@ -23,13 +23,13 @@ import data_Preferences from '@ohos.data.preferences'
## data_Preferences.getPreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void
读取指定文件,将数据加载到Preferences实例,用于数据操作,使用callback形式返回结果。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -55,13 +55,13 @@ getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Prefer
## data_Preferences.getPreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
读取指定文件,将数据加载到Preferences实例,用于数据操作,使用Promise方式作为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -90,13 +90,13 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
## data_Preferences.deletePreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;void&gt;)
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -120,13 +120,13 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;voi
## data_Preferences.deletePreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
deletePreferences(context: Context, name: string): Promise&lt;void&gt;
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -153,15 +153,15 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
## data_Preferences.removePreferencesFromCache
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -185,14 +185,15 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
## data_Preferences.removePreferencesFromCache
### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -224,14 +225,15 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
### get
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
获取键对应的值,如果值为null或者非默认值类型,返回默认数据。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -253,14 +255,15 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;):
### get
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
获取键对应的值,如果值为null或者非默认值类型,返默认数据。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -285,14 +288,15 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
### put
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
首先获取指定文件对应的Preferences实例,然后借助Preferences API将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -314,14 +318,15 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
### put
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
put(key: string, value: ValueType): Promise&lt;void&gt;
首先获取指定文件对应的Preferences实例,然后借助Preferences API将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -346,14 +351,15 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
### has
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
检查存储对象是否包含名为给定key的存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -381,14 +387,15 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
### has
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
has(key: string): Promise&lt;boolean&gt;
检查存储对象是否包含名为给定key的存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -414,14 +421,15 @@ has(key: string): Promise&lt;boolean&gt;
### delete
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
delete(key: string, callback: AsyncCallback&lt;void&gt;): void
从存储对象中删除名为给定key的存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -442,14 +450,15 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
### delete
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
delete(key: string): Promise&lt;void&gt;
从存储对象删除名为给定key的存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -473,14 +482,15 @@ delete(key: string): Promise&lt;void&gt;
### flush
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
flush(callback: AsyncCallback&lt;void&gt;): void
将当前preferences对象中的修改保存到当前的preferences,并异步存储到文件中。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -500,14 +510,15 @@ flush(callback: AsyncCallback&lt;void&gt;): void
### flush
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
flush(): Promise&lt;void&gt;
将当前preferences对象中的修改保存到当前的preferences,并异步存储到文件中。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
......@@ -526,14 +537,15 @@ flush(): Promise&lt;void&gt;
### clear
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
clear(callback: AsyncCallback&lt;void&gt;): void
清除此存储对象中的所有存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......@@ -553,14 +565,15 @@ clear(callback: AsyncCallback&lt;void&gt;): void
### clear
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
clear(): Promise&lt;void&gt;
清除此存储对象中的所有存储。
此方法为异步方法。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
......@@ -579,12 +592,13 @@ clear(): Promise&lt;void&gt;
### on('change')
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
订阅数据变更者类,订阅的key的值发生变更后,在执行flush方法后,callback方法会被回调。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
......@@ -604,12 +618,13 @@ on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
### off('change')
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
off(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
当不再进行订阅数据变更时,使用此接口取消订阅。
### 系统能力###
SystemCapability.DistributedDataManager.Preferences.Core
- 参数:
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
......
......@@ -4,7 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 从API Version 8开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
> 从API Version 9开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
## 导入模块
......
......@@ -287,7 +287,7 @@
<td class="cellrowborder" valign="top" width="13.66%" headers="mcps1.1.5.1.3 "><p><a href="#table154011838131719">ScrollOffset</a></p>
</td>
<td class="cellrowborder" valign="top" width="57.43000000000001%" headers="mcps1.1.5.1.4 "><p>获取元素内容的滚动偏移。</p>
<div class="note"><span class="notetitle"> 说明: </span><div class="notebody"><ul><li>需要设置overflow样式为scroll。</li></ul>
<div class="note"><span class="notetitle"> 说明: </span><div class="notebody"><ul><li>需要设置overflow样式为scroll,默认滚动方向与容器方向一致</li></ul>
</div></div>
</td>
</tr>
......
......@@ -10,3 +10,7 @@
- Hap包签名工具
- [Hap包签名工具开发指导](hapsigntool-guidelines.md)
- 访问控制
- [访问控制开发概述](accesstoken-overview.md)
- [访问控制开发指导](accesstoken-guidelines.md)
此差异已折叠。
此差异已折叠。
# Bundle开发指南
- [开发规范](oem_bundle_standard_des.md)
- [开发规范](bundles-standard-rules.md )
- [开发指南](bundles-guide.md)
- [概述](bundles-guide-overview.md)
- [安装hpm命令行工具](bundles-guide-prepare.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册