提交 dd1eccbc 编写于 作者: L LiAn 提交者: Gitee

Merge branch 'OpenHarmony-3.2-Beta1' of gitee.com:openharmony/docs into OpenHarmony-3.2-Beta1

...@@ -18,15 +18,17 @@ The table below describes the ability call APIs. For details, see [Ability](../r ...@@ -18,15 +18,17 @@ The table below describes the ability call APIs. For details, see [Ability](../r
**Table 1** Ability call APIs **Table 1** Ability call APIs
|API|Description| |API|Description|
|:------|:------| |:------|:------|
|Promise<Caller> startAbilityByCall(want: Want)|Obtains the caller interface of the specified ability and, if the specified ability is not running, starts the ability in the background.| |startAbilityByCall(want: Want): Promise\<Caller>|Obtains the caller interface of the specified ability and, if the specified ability is not running, starts the ability in the background.|
|void on(method: string, callback: CalleeCallBack)|Callee.on: callback invoked when the callee registers a method.| |on(method: string, callback: CaleeCallBack): void|Callback invoked when the callee registers a method.|
|void off(method: string)|Callee.off: callback invoked when the callee deregisters a method.| |off(method: string): void|Callback invoked when the callee deregisters a method.|
|Promise<void> call(method: string, data: rpc.Sequenceable)|Caller.call: sends agreed sequenceable data to the callee.| |call(method: string, data: rpc.Sequenceable): Promise\<void>|Sends agreed sequenceable data to the callee.|
|Promise<rpc.MessageParcel> callWithResult(method: string, data: rpc.Sequenceable)|Caller.callWithResult: sends agreed sequenceable data to the callee and returns the agreed sequenceable data.| |callWithResult(method: string, data: rpc.Sequenceable): Promise\<rpc.MessageParcel>|Sends agreed sequenceable data to the callee and returns the agreed sequenceable data.|
|void release()|Caller.release: releases the caller interface.| |release(): void|Releases the caller interface.|
|void onRelease(callback: OnReleaseCallBack)|Caller.onRelease: registers a callback that is invoked when the caller is disconnected.| |onRelease(callback: OnReleaseCallBack): void|Registers a callback that is invoked when the caller is disconnected.|
## How to Develop ## How to Develop
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The sample code snippets provided in the **How to Develop** section are used to show specific development steps. They may not be able to run independently. For details about the complete project code, see [Samples](#samples).
### Creating a Callee ### Creating a Callee
For the callee, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use the **on** API to register a listener. When data does not need to be received, use the **off** API to deregister the listener. For the callee, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use the **on** API to register a listener. When data does not need to be received, use the **off** API to deregister the listener.
1. Configure the ability startup mode. 1. Configure the ability startup mode.
...@@ -55,7 +57,7 @@ import Ability from '@ohos.application.Ability' ...@@ -55,7 +57,7 @@ import Ability from '@ohos.application.Ability'
``` ```
3. Define the agreed sequenceable data. 3. Define the agreed sequenceable data.
The data formats sent and received by the caller and callee must be consistent. In the following example, the data consists of numbers and strings. The sample code is as follows: The data formats sent and received by the caller and callee must be consistent. In the following example, the data consists of numbers and strings. The sample code snippet is as follows:
```ts ```ts
export default class MySequenceable { export default class MySequenceable {
num: number = 0 num: number = 0
...@@ -81,7 +83,7 @@ export default class MySequenceable { ...@@ -81,7 +83,7 @@ export default class MySequenceable {
``` ```
4. Implement **Callee.on** and **Callee.off**. 4. Implement **Callee.on** and **Callee.off**.
The time to register a listener for the callee depends on your application. The data sent and received before the listener is registered and that after the listener is deregistered are not processed. In the following example, the **CalleeSortMethod** listener is registered in **onCreate** of the ability and deregistered in **onDestroy**. After receiving sequenceable data, the application processes the data and returns the data result. You need to implement processing based on service requirements. The sample code is as follows: The time to register a listener for the callee depends on your application. The data sent and received before the listener is registered and that after the listener is deregistered are not processed. In the following example, the **MSG_SEND_METHOD** listener is registered in **onCreate** of the ability and deregistered in **onDestroy**. After receiving sequenceable data, the application processes the data and returns the data result. You need to implement processing based on service requirements. The sample code snippet is as follows:
```ts ```ts
const TAG: string = '[CalleeAbility]' const TAG: string = '[CalleeAbility]'
const MSG_SEND_METHOD: string = 'CallSendMsg' const MSG_SEND_METHOD: string = 'CallSendMsg'
...@@ -125,7 +127,7 @@ import Ability from '@ohos.application.Ability' ...@@ -125,7 +127,7 @@ import Ability from '@ohos.application.Ability'
``` ```
2. Obtain the caller interface. 2. Obtain the caller interface.
The **context** attribute of the ability implements **startAbilityByCall** to obtain the caller interface of the ability. The following example uses **this.context** to obtain the **context** attribute of the **Ability** instance, uses **startAbilityByCall** to start the callee, obtain the caller interface, and register the **onRelease** listener of the caller. You need to implement processing based on service requirements. The sample code is as follows: The **context** attribute of the ability implements **startAbilityByCall** to obtain the caller interface of the ability. The following example uses **this.context** to obtain the **context** attribute of the **Ability** instance, uses **startAbilityByCall** to start the callee, obtain the caller interface, and register the **onRelease** listener of the caller. You need to implement processing based on service requirements. The sample code snippet is as follows:
```ts ```ts
async onButtonGetCaller() { async onButtonGetCaller() {
try { try {
...@@ -146,7 +148,7 @@ async onButtonGetCaller() { ...@@ -146,7 +148,7 @@ async onButtonGetCaller() {
console.error(TAG + 'get caller failed with ' + error) console.error(TAG + 'get caller failed with ' + error)
}) })
``` ```
In the cross-device scenario, you need to specify the ID of the peer device. The sample code is as follows: In the cross-device scenario, you need to specify the ID of the peer device. The sample code snippet is as follows:
```ts ```ts
let TAG = '[MainAbility] ' let TAG = '[MainAbility] '
var caller = undefined var caller = undefined
...@@ -170,7 +172,7 @@ context.startAbilityByCall({ ...@@ -170,7 +172,7 @@ context.startAbilityByCall({
console.error(TAG + 'get remote caller failed with ' + error) console.error(TAG + 'get remote caller failed with ' + error)
}) })
``` ```
Obtain the ID of the peer device from **DeviceManager**. Note that the **getTrustedDeviceListSync** API is open only to system applications. The sample code is as follows: Obtain the ID of the peer device from **DeviceManager**. Note that the **getTrustedDeviceListSync** API is open only to system applications. The sample code snippet is as follows:
```ts ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
var dmClass; var dmClass;
...@@ -188,7 +190,7 @@ function getRemoteDeviceId() { ...@@ -188,7 +190,7 @@ function getRemoteDeviceId() {
} }
} }
``` ```
In the cross-device scenario, the application must also apply for the data synchronization permission from end users. The sample code is as follows: In the cross-device scenario, the application must also apply for the data synchronization permission from end users. The sample code snippet is as follows:
```ts ```ts
let context = this.context let context = this.context
let permissions: Array<string> = ['ohos.permission.DISTRIBUTED_DATASYNC'] let permissions: Array<string> = ['ohos.permission.DISTRIBUTED_DATASYNC']
...@@ -200,7 +202,7 @@ context.requestPermissionsFromUser(permissions).then((data) => { ...@@ -200,7 +202,7 @@ context.requestPermissionsFromUser(permissions).then((data) => {
``` ```
3. Send agreed sequenceable data. 3. Send agreed sequenceable data.
The sequenceable data can be sent to the callee with or without a return value. The method and sequenceable data must be consistent with those of the callee. The following example describes how to invoke the **Call** API to send data to the callee. The sample code is as follows: The sequenceable data can be sent to the callee with or without a return value. The method and sequenceable data must be consistent with those of the callee. The following example describes how to invoke the **Call** API to send data to the callee. The sample code snippet is as follows:
```ts ```ts
const MSG_SEND_METHOD: string = 'CallSendMsg' const MSG_SEND_METHOD: string = 'CallSendMsg'
async onButtonCall() { async onButtonCall() {
...@@ -213,7 +215,7 @@ async onButtonCall() { ...@@ -213,7 +215,7 @@ async onButtonCall() {
} }
``` ```
In the following, **CallWithResult** is used to send data **originMsg** to the callee and assign the data processed by the **CallSendMsg** method to **backMsg**. The sample code is as follows: In the following, **CallWithResult** is used to send data **originMsg** to the callee and assign the data processed by the **CallSendMsg** method to **backMsg**. The sample code snippet is as follows:
```ts ```ts
const MSG_SEND_METHOD: string = 'CallSendMsg' const MSG_SEND_METHOD: string = 'CallSendMsg'
originMsg: string = '' originMsg: string = ''
...@@ -235,7 +237,7 @@ async onButtonCallWithResult(originMsg, backMsg) { ...@@ -235,7 +237,7 @@ async onButtonCallWithResult(originMsg, backMsg) {
``` ```
4. Release the caller interface. 4. Release the caller interface.
When the caller interface is no longer required, call the **release** API to release it. The sample code is as follows: When the caller interface is no longer required, call the **release** API to release it. The sample code snippet is as follows:
```ts ```ts
try { try {
this.caller.release() this.caller.release()
...@@ -248,4 +250,4 @@ try { ...@@ -248,4 +250,4 @@ try {
## Samples ## Samples
The following sample is provided to help you better understand how to develop an ability call in the stage model: The following sample is provided to help you better understand how to develop an ability call in the stage model:
- [`StageCallAbility`: Stage Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility) - [`StageCallAbility`: Stage Call Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
...@@ -204,7 +204,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -204,7 +204,7 @@ You can obtain the distributed table name for a remote device based on the local
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",} const STORE_CONFIG = {name: "rdbstore.db",}
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE) rdbStore.executeSql(CREATE_TABLE_TEST)
console.info('create table done.') console.info('create table done.')
}) })
``` ```
......
...@@ -15,7 +15,7 @@ You can develop applications or services in the low-code approach using either o ...@@ -15,7 +15,7 @@ You can develop applications or services in the low-code approach using either o
- Create a project that supports low-code development. This method is used as an example in this topic. - Create a project that supports low-code development. This method is used as an example in this topic.
- In an existing project, create a .visual file for development. - In an existing project, create a .visual file for development. For details, see [Creating a .visual File That Supports Low-Code Development](#building-the-second-page).
## Creating a Project That Supports Low-Code Development ## Creating a Project That Supports Low-Code Development
...@@ -52,7 +52,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column ...@@ -52,7 +52,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column
Open the **index.visual** file, right-click the existing template components on the canvas, and choose **Delete** from the shortcut menu to delete them. Below is an illustration of the operations. Open the **index.visual** file, right-click the existing template components on the canvas, and choose **Delete** from the shortcut menu to delete them. Below is an illustration of the operations.
![en-us_image_0000001233208980](figures/en-us_image_0000001233208980.gif) ![en-us_image_0000001233208980](figures/en-us_image_0000001233208980.gif)
2. Add a **Column** component and set its styles and attributes.<a name="add_container"></a> 2. Add a **Column** component and set its styles and attributes.<a name="add_container"></a>
...@@ -70,7 +70,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column ...@@ -70,7 +70,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column
Drag the **Button** component from the **UI Control** area to the canvas and then to a position under the **Text** component. In the **Attributes &amp; Styles** area on the right, click ![en-us_image_0000001277728577](figures/en-us_image_0000001277728577.png)**General** and set **Height** of the **Button** component to **40vp**. Click ![en-us_image_0000001277809337](figures/en-us_image_0000001277809337.png)**Feature** and set **Label** to **Next** and **FontSize** to **25fp**. Below is an illustration of the operations. Drag the **Button** component from the **UI Control** area to the canvas and then to a position under the **Text** component. In the **Attributes &amp; Styles** area on the right, click ![en-us_image_0000001277728577](figures/en-us_image_0000001277728577.png)**General** and set **Height** of the **Button** component to **40vp**. Click ![en-us_image_0000001277809337](figures/en-us_image_0000001277809337.png)**Feature** and set **Label** to **Next** and **FontSize** to **25fp**. Below is an illustration of the operations.
![en-us_image_0000001235732402](figures/en-us_image_0000001235732402.gif) ![en-us_image_0000001235732402](figures/en-us_image_0000001235732402.gif)
5. On the toolbar in the upper right corner of the editing window, click **Previewer** to open the Previewer. 5. On the toolbar in the upper right corner of the editing window, click **Previewer** to open the Previewer.
...@@ -85,7 +85,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column ...@@ -85,7 +85,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column
In the **Project** window, choose **entry** &gt; **src** &gt; **main** &gt; **ets** &gt; **MainAbility**, right-click the **pages** folder, choose **New** &gt; **Visual**, name the page **second**, and click **Finish**. Below, you can see the structure of the **pages** folder. In the **Project** window, choose **entry** &gt; **src** &gt; **main** &gt; **ets** &gt; **MainAbility**, right-click the **pages** folder, choose **New** &gt; **Visual**, name the page **second**, and click **Finish**. Below, you can see the structure of the **pages** folder.
![en-us_image_0000001233368868](figures/en-us_image_0000001233368868.png) ![en-us_image_0000001233368868](figures/en-us_image_0000001233368868.png)
2. [Delete the existing template components from the canvas.](#delete_origin_content) 2. [Delete the existing template components from the canvas.](#delete_origin_content)
......
...@@ -13,7 +13,7 @@ You can develop applications or services in the low-code approach using either o ...@@ -13,7 +13,7 @@ You can develop applications or services in the low-code approach using either o
- Create a project that supports low-code development. This method is used as an example in this topic. - Create a project that supports low-code development. This method is used as an example in this topic.
- In an existing project, create a Visual file for development. - In an existing project, create a Visual file for development. For details, see [Creating a .visual File That Supports Low-Code Development](#building-the-second-page).
## Creating a Project That Supports Low-Code Development ## Creating a Project That Supports Low-Code Development
...@@ -53,15 +53,15 @@ Add **Div**, **Text**, and **Button** components to the first page. ...@@ -53,15 +53,15 @@ Add **Div**, **Text**, and **Button** components to the first page.
1. Delete the existing template components from the canvas.<a name= delete_origin_content></a> 1. Delete the existing template components from the canvas.<a name= delete_origin_content></a>
Open the index.visual file, right-click the existing template components on the canvas, and choose **Delete** from the shortcut menu to delete them. Below is an illustration of the operations. Open the index.visual file, right-click the existing template components on the canvas, and choose **Delete** from the shortcut menu to delete them. Below is an illustration of the operations.
![en-us_image_0000001216600980](figures/en-us_image_0000001216600980.gif) ![en-us_image_0000001216600980](figures/en-us_image_0000001216600980.gif)
2. Add a **Div** component and set its styles and attributes.<a name = add_container></a> 2. Add a **Div** component and set its styles and attributes.<a name = add_container></a>
Drag the **Div** component from the **UI Control** area to the canvas. In the **Attributes &amp; Styles** area on the right, click ![en-us_image_0000001260226691](figures/en-us_image_0000001260226691.png)**General** and set **Height** to **100%** so that the component fills the entire screen. Click ![en-us_image_0000001215226858](figures/en-us_image_0000001215226858.png)**Flex**, set **FlexDirection** to **column** so that the main axis of the component is vertical, and set both **JustifyContent** and **AlignItems** to **center** so that the child components of the **Div** component are centered along the main axis and cross axis. Below is an illustration of the operations. Drag the **Div** component from the **UI Control** area to the canvas. In the **Attributes &amp; Styles** area on the right, click ![en-us_image_0000001260226691](figures/en-us_image_0000001260226691.png)**General** and set **Height** to **100%** so that the component fills the entire screen. Click ![en-us_image_0000001215226858](figures/en-us_image_0000001215226858.png)**Flex**, set **FlexDirection** to **column** so that the main axis of the component is vertical, and set both **JustifyContent** and **AlignItems** to **center** so that the child components of the **Div** component are centered along the main axis and cross axis. Below is an illustration of the operations.
![en-us_image_0000001216448880](figures/en-us_image_0000001216448880.gif) ![en-us_image_0000001216448880](figures/en-us_image_0000001216448880.gif)
3. Add a **Text** component. 3. Add a **Text** component.
...@@ -88,7 +88,7 @@ Open the index.visual file, right-click the existing template components on the ...@@ -88,7 +88,7 @@ Open the index.visual file, right-click the existing template components on the
In the **Project** window, choose **entry** &gt; **src** &gt; **main** &gt; **js** &gt; **MainAbility**, right-click the **pages** folder, choose **New** &gt; **Visual**, name the page **second**, and click **Finish**. Below, you can see the structure of the **pages** folder. In the **Project** window, choose **entry** &gt; **src** &gt; **main** &gt; **js** &gt; **MainAbility**, right-click the **pages** folder, choose **New** &gt; **Visual**, name the page **second**, and click **Finish**. Below, you can see the structure of the **pages** folder.
![en-us_image_0000001223882030](figures/en-us_image_0000001223882030.png) ![en-us_image_0000001223882030](figures/en-us_image_0000001223882030.png)
2. [Delete the existing template components from the canvas.](#delete_origin_content) 2. [Delete the existing template components from the canvas.](#delete_origin_content)
......
...@@ -320,10 +320,10 @@ arrayList.add(2); ...@@ -320,10 +320,10 @@ arrayList.add(2);
arrayList.add(4); arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.replaceAllElements((value, index) => { arrayList.replaceAllElements((value: number, index: number)=> {
return value = 2 * value; return value = 2 * value;
}); });
arrayList.replaceAllElements((value, index) => { arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
``` ```
...@@ -394,8 +394,8 @@ arrayList.add(2); ...@@ -394,8 +394,8 @@ arrayList.add(2);
arrayList.add(4); arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.sort((a, b) => a - b); arrayList.sort((a: number, b: number) => a - b);
arrayList.sort((a, b) => b - a); arrayList.sort((a: number, b: number) => b - a);
arrayList.sort(); arrayList.sort();
``` ```
......
...@@ -1322,7 +1322,7 @@ Sets a device to the active state. This API uses an asynchronous callback to ret ...@@ -1322,7 +1322,7 @@ Sets a device to the active state. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
if (err) { if (err) {
console.error('Failed to set the active status of the device. ${err.message}'); console.error('Failed to set the active status of the device. ${err.message}');
return; return;
...@@ -1356,7 +1356,7 @@ Sets a device to the active state. This API uses a promise to return the result. ...@@ -1356,7 +1356,7 @@ Sets a device to the active state. This API uses a promise to return the result.
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
console.log('Promise returned to indicate that the device is set to the active status.'); console.log('Promise returned to indicate that the device is set to the active status.');
}); });
``` ```
...@@ -1379,7 +1379,7 @@ Checks whether a device is active. This API uses an asynchronous callback to ret ...@@ -1379,7 +1379,7 @@ Checks whether a device is active. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the active status of the device. ${err.message}'); console.error('Failed to obtain the active status of the device. ${err.message}');
return; return;
...@@ -1412,7 +1412,7 @@ Checks whether a device is active. This API uses a promise to return the result. ...@@ -1412,7 +1412,7 @@ Checks whether a device is active. This API uses a promise to return the result.
**Example** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
console.log('Promise returned to indicate that the active status of the device is obtained.' + value); console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
}); });
``` ```
...@@ -1646,7 +1646,7 @@ var interAudioInterrupt = { ...@@ -1646,7 +1646,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to gain the audio focus starts."); console.log("An event to gain the audio focus starts.");
console.log("Focus gain event:" + JSON.stringify(InterruptAction)); console.log("Focus gain event:" + JSON.stringify(InterruptAction));
...@@ -1682,7 +1682,7 @@ var interAudioInterrupt = { ...@@ -1682,7 +1682,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to release the audio focus starts."); console.log("An event to release the audio focus starts.");
console.log("Focus release event:" + JSON.stringify(InterruptAction)); console.log("Focus release event:" + JSON.stringify(InterruptAction));
...@@ -1744,7 +1744,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -1744,7 +1744,7 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
``` ```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
console.log('Promise returned to indicate a successful setting of the audio scene mode.'); console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => { }).catch ((err) => {
console.log('Failed to set the audio scene mode'); console.log('Failed to set the audio scene mode');
...@@ -1903,6 +1903,7 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us ...@@ -1903,6 +1903,7 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
**Example** **Example**
``` ```
var resultFlag = true;
audioRenderer.getRendererInfo().then((rendererInfo) => { audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('Renderer GetRendererInfo:'); console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content); console.log('Renderer content:' + rendererInfo.content);
...@@ -2349,13 +2350,11 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -2349,13 +2350,11 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Example** **Example**
``` ```
audioRenderer.getBufferSize((err, bufferSize) => { var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
if (err) { if (err) {
console.error('getBufferSize error'); console.error('getBufferSize error');
} }
}); });
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
...@@ -2375,11 +2374,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -2375,11 +2374,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Example** **Example**
``` ```
audioRenderer.getBufferSize().then((bufferSize) => { var bufferSize;
let buf = new ArrayBuffer(bufferSize); await audioRenderer.getBufferSize().then(async function (data) => {
ss.readSync(buf); console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
bufferSize=data;
}).catch((err) => { }).catch((err) => {
console.log('ERROR: '+err.message); console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
}); });
``` ```
...@@ -2504,7 +2504,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru ...@@ -2504,7 +2504,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru
**Example** **Example**
``` ```
audioRenderer.on('interrupt', (interruptEvent) => { var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
...@@ -2520,11 +2522,30 @@ audioRenderer.on('interrupt', (interruptEvent) => { ...@@ -2520,11 +2522,30 @@ audioRenderer.on('interrupt', (interruptEvent) => {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME: case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore'); console.log('Resume force paused renderer or ignore');
startRenderer(); await audioRenderer.start().then(async function () {
console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
started = true;
}).catch((err) => {
console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
started = false;
});
if (started) {
isPlay = true;
console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
} else {
console.error('AudioInterruptMusic Renderer start failed');
}
break; break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore'); console.log('Choose to pause or ignore');
pauseRenderer(); if (isPlay == true) {
isPlay == false;
console.info('AudioInterruptMusic: Media PAUSE : TRUE');
}
else {
isPlay = true;
console.info('AudioInterruptMusic: Media PLAY : TRUE');
}
break; break;
} }
} }
...@@ -2985,7 +3006,7 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ...@@ -2985,7 +3006,7 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
if (!err) { if (!err) {
console.log("Success in reading the buffer data"); console.log("Success in reading the buffer data");
} }
}; });
``` ```
......
...@@ -128,6 +128,7 @@ Cancels the suspension delay. ...@@ -128,6 +128,7 @@ Cancels the suspension delay.
**Example** **Example**
```js ```js
let id = 1;
backgroundTaskManager.cancelSuspendDelay(id); backgroundTaskManager.cancelSuspendDelay(id);
``` ```
...@@ -314,13 +315,13 @@ Provides the information about the suspension delay. ...@@ -314,13 +315,13 @@ Provides the information about the suspension delay.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
| Name | Value| Description | | Name | Value| Description |
| ----------------------- | ------ | ---------------------------- | | ----------------------- | ------ | ------------------------------------------------------------ |
| DATA_TRANSFER | 1 | Data transfer. | | DATA_TRANSFER | 1 | Data transfer. |
| AUDIO_PLAYBACK | 2 | Audio playback. | | AUDIO_PLAYBACK | 2 | Audio playback. |
| AUDIO_RECORDING | 3 | Audio recording. | | AUDIO_RECORDING | 3 | Audio recording. |
| LOCATION | 4 | Positioning and navigation. | | LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. | | BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. | | MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related (reserved). | | WIFI_INTERACTION | 7 | WLAN-related.<br>This is a system API and cannot be called by third-party applications.|
| VOIP | 8 | Voice and video call (reserved). | | VOIP | 8 | Audio and video calls.<br>This is a system API and cannot be called by third-party applications.|
| TASK_KEEPING | 9 | Computing task (effective only for specific devices).| | TASK_KEEPING | 9 | Computing task (effective only for specific devices). |
# Bluetooth # Bluetooth
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The Bluetooth module provides Classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising. Provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
## Modules to Import ## Modules to Import
...@@ -201,7 +201,7 @@ Obtains the connection state of a profile. ...@@ -201,7 +201,7 @@ Obtains the connection state of a profile.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- | | --------- | --------- | ---- | ------------------------------------- |
| ProfileId | profileId | Yes | ID of the target profile, for example, **PROFILE_A2DP_SOURCE**.| | ProfileId | profileId | Yes | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
**Return value** **Return value**
...@@ -212,7 +212,7 @@ Obtains the connection state of a profile. ...@@ -212,7 +212,7 @@ Obtains the connection state of a profile.
**Example** **Example**
```js ```js
let result = bluetooth.getProfileConnState(PROFILE_A2DP_SOURCE); let result = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
``` ```
...@@ -355,7 +355,7 @@ Sets the Bluetooth scan mode so that the device can be discovered by a remote de ...@@ -355,7 +355,7 @@ Sets the Bluetooth scan mode so that the device can be discovered by a remote de
```js ```js
// The device can be discovered and connected only when the discoverable and connectable mode is used. // The device can be discovered and connected only when the discoverable and connectable mode is used.
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
``` ```
...@@ -720,7 +720,7 @@ bluetooth.off('stateChange', onReceiveEvent); ...@@ -720,7 +720,7 @@ bluetooth.off('stateChange', onReceiveEvent);
``` ```
## bluetooth.sppListen<sup>8+</sup><a name="sppListen<"></a> ## bluetooth.sppListen<sup>8+</sup><a name="sppListen"></a>
sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
...@@ -773,6 +773,14 @@ Listens for a connection to be made to this socket from the client and accepts i ...@@ -773,6 +773,14 @@ Listens for a connection to be made to this socket from the client and accepts i
**Example** **Example**
```js ```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let clientNumber = -1; let clientNumber = -1;
function acceptClientSocket(code, number) { function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code); console.log('bluetooth error code: ' + code.code);
...@@ -807,6 +815,7 @@ Initiates an SPP connection to a remote device from the client. ...@@ -807,6 +815,7 @@ Initiates an SPP connection to a remote device from the client.
**Example** **Example**
```js ```js
let clientNumber = -1; let clientNumber = -1;
function clientSocket(code, number) { function clientSocket(code, number) {
if (code.code != 0) { if (code.code != 0) {
...@@ -838,6 +847,14 @@ Closes the listening socket of the server. ...@@ -838,6 +847,14 @@ Closes the listening socket of the server.
**Example** **Example**
```js ```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
bluetooth.sppCloseServerSocket(serverNumber); bluetooth.sppCloseServerSocket(serverNumber);
``` ```
...@@ -860,6 +877,15 @@ Closes the client socket. ...@@ -860,6 +877,15 @@ Closes the client socket.
**Example** **Example**
```js ```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
bluetooth.sppCloseClientSocket(clientNumber); bluetooth.sppCloseClientSocket(clientNumber);
``` ```
...@@ -888,6 +914,15 @@ Writes data to the remote device through the socket. ...@@ -888,6 +914,15 @@ Writes data to the remote device through the socket.
**Example** **Example**
```js ```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
let arrayBuffer = new ArrayBuffer(8); let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer); let data = new Uint8Array(arrayBuffer);
data[0] = 123; data[0] = 123;
...@@ -923,6 +958,15 @@ No value is returned. ...@@ -923,6 +958,15 @@ No value is returned.
**Example** **Example**
```js ```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
function dataRead(dataBuffer) { function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer); let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]); console.log('bluetooth data is: ' + data[0]);
...@@ -954,6 +998,15 @@ No value is returned. ...@@ -954,6 +998,15 @@ No value is returned.
**Example** **Example**
```js ```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
bluetooth.off('sppRead', clientNumber); bluetooth.off('sppRead', clientNumber);
``` ```
...@@ -981,14 +1034,14 @@ Obtains a profile object. ...@@ -981,14 +1034,14 @@ Obtains a profile object.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
``` ```
## bluetooth.getProfile<sup>9+</sup><a name="getProfile"></a> ## bluetooth.getProfile<sup>9+</sup><a name="getProfile"></a>
getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile
Obtains the profile object instance based on **ProfileId**. API version 9 is added with **HidHostProfile**. Obtains a profile instance. **HidHostProfile** is added in API version 9.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -996,7 +1049,7 @@ Obtains the profile object instance based on **ProfileId**. API version 9 is add ...@@ -996,7 +1049,7 @@ Obtains the profile object instance based on **ProfileId**. API version 9 is add
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- | | --------- | --------- | ---- | ------------------------------------- |
| profileId | [ProfileId](#ProfileId) | Yes | ID of the target profile, for example, **PROFILE_A2DP_SOURCE**.| | profileId | [ProfileId](#ProfileId) | Yes | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
**Return value** **Return value**
...@@ -1007,7 +1060,7 @@ Obtains the profile object instance based on **ProfileId**. API version 9 is add ...@@ -1007,7 +1060,7 @@ Obtains the profile object instance based on **ProfileId**. API version 9 is add
**Example** **Example**
```js ```js
let hidHost = bluetooth.getProfile(PROFILE_HID_HOST); let hidHost = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST);
``` ```
...@@ -1239,7 +1292,7 @@ No value is returned. ...@@ -1239,7 +1292,7 @@ No value is returned.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE)
let retArray = a2dpSrc.getConnectionDevices(); let retArray = a2dpSrc.getConnectionDevices();
``` ```
...@@ -1257,7 +1310,7 @@ Obtains the connection state of the profile. ...@@ -1257,7 +1310,7 @@ Obtains the connection state of the profile.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1268,7 +1321,7 @@ Obtains the connection state of the profile. ...@@ -1268,7 +1321,7 @@ Obtains the connection state of the profile.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE)
let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1302,7 +1355,7 @@ Sets up an Advanced Audio Distribution Profile (A2DP) connection. ...@@ -1302,7 +1355,7 @@ Sets up an Advanced Audio Distribution Profile (A2DP) connection.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE)
let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1332,7 +1385,7 @@ Disconnects an A2DP connection. ...@@ -1332,7 +1385,7 @@ Disconnects an A2DP connection.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1362,7 +1415,7 @@ No value is returned. ...@@ -1362,7 +1415,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data)); console.info('a2dp state = '+ JSON.stringify(data));
} }
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
a2dpSrc.on('connectionStateChange', onReceiveEvent); a2dpSrc.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1392,7 +1445,7 @@ No value is returned. ...@@ -1392,7 +1445,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data)); console.info('a2dp state = '+ JSON.stringify(data));
} }
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
a2dpSrc.on('connectionStateChange', onReceiveEvent); a2dpSrc.on('connectionStateChange', onReceiveEvent);
a2dpSrc.off('connectionStateChange', onReceiveEvent); a2dpSrc.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1410,7 +1463,7 @@ Obtains the playing state of a device. ...@@ -1410,7 +1463,7 @@ Obtains the playing state of a device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1421,7 +1474,7 @@ Obtains the playing state of a device. ...@@ -1421,7 +1474,7 @@ Obtains the playing state of a device.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1445,7 +1498,7 @@ Sets up a Hands-free Profile (HFP) connection of a device. ...@@ -1445,7 +1498,7 @@ Sets up a Hands-free Profile (HFP) connection of a device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1456,7 +1509,7 @@ Sets up a Hands-free Profile (HFP) connection of a device. ...@@ -1456,7 +1509,7 @@ Sets up a Hands-free Profile (HFP) connection of a device.
**Example** **Example**
```js ```js
let hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX'); let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1475,7 +1528,7 @@ Disconnects the HFP connection of a device. ...@@ -1475,7 +1528,7 @@ Disconnects the HFP connection of a device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1486,7 +1539,7 @@ Disconnects the HFP connection of a device. ...@@ -1486,7 +1539,7 @@ Disconnects the HFP connection of a device.
**Example** **Example**
```js ```js
let hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX'); let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1516,7 +1569,7 @@ No value is returned. ...@@ -1516,7 +1569,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data)); console.info('hfp state = '+ JSON.stringify(data));
} }
let hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpAg.on('connectionStateChange', onReceiveEvent); hfpAg.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1546,7 +1599,7 @@ No value is returned. ...@@ -1546,7 +1599,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data)); console.info('hfp state = '+ JSON.stringify(data));
} }
let hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpAg.on('connectionStateChange', onReceiveEvent); hfpAg.on('connectionStateChange', onReceiveEvent);
hfpAg.off('connectionStateChange', onReceiveEvent); hfpAg.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1573,7 +1626,7 @@ Connects to the HidHost service of a device. ...@@ -1573,7 +1626,7 @@ Connects to the HidHost service of a device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1584,7 +1637,7 @@ Connects to the HidHost service of a device. ...@@ -1584,7 +1637,7 @@ Connects to the HidHost service of a device.
**Example** **Example**
```js ```js
let hidHostProfile = bluetooth.getProfile(PROFILE_HID_HOST); let hidHostProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST);
let ret = hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); let ret = hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1605,7 +1658,7 @@ Disconnects from the HidHost service of a device. ...@@ -1605,7 +1658,7 @@ Disconnects from the HidHost service of a device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.| | device | string | Yes | Address of the target device.|
**Return value** **Return value**
...@@ -1616,7 +1669,7 @@ Disconnects from the HidHost service of a device. ...@@ -1616,7 +1669,7 @@ Disconnects from the HidHost service of a device.
**Example** **Example**
```js ```js
let hidHostProfile = bluetooth.getProfile(PROFILE_HID_HOST); let hidHostProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST);
let ret = hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); let ret = hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1646,7 +1699,7 @@ No value is returned. ...@@ -1646,7 +1699,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetooth.getProfile(PROFILE_HID_HOST); let hidHost = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST);
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1676,7 +1729,7 @@ No value is returned. ...@@ -1676,7 +1729,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetooth.getProfile(PROFILE_HID_HOST); let hidHost = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST);
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent); hidHost.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1819,7 +1872,7 @@ cccV[0] = 1; ...@@ -1819,7 +1872,7 @@ cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptorsN}; characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic; characteristics[0] = characteristic;
// Create a gattService instance. // Create a gattService instance.
...@@ -1911,8 +1964,11 @@ Notifies the connected client device when a characteristic value changes. ...@@ -1911,8 +1964,11 @@ Notifies the connected client device when a characteristic value changes.
**Example** **Example**
```js ```js
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: notifyCcc.characteristicValue, confirm: false}; characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
let server = bluetooth.BLE.createGattServer(); let server = bluetooth.BLE.createGattServer();
server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic); server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
``` ```
...@@ -2138,7 +2194,7 @@ Subscribes to the descriptor read request events. ...@@ -2138,7 +2194,7 @@ Subscribes to the descriptor read request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------------- |
| type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event.| | type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event.|
| callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | Yes | Callback invoked to return a descriptor read request from the GATT client. | | callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | Yes | Callback invoked to return a descriptor read request event from the GATT client. |
**Return value** **Return value**
...@@ -2279,7 +2335,6 @@ let gattServer = bluetooth.BLE.createGattServer(); ...@@ -2279,7 +2335,6 @@ let gattServer = bluetooth.BLE.createGattServer();
gattServer.off("descriptorWrite"); gattServer.off("descriptorWrite");
``` ```
### on('connectStateChange') ### on('connectStateChange')
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
...@@ -2488,7 +2543,7 @@ Obtains all services of the remote BLE device. This API uses a promise to return ...@@ -2488,7 +2543,7 @@ Obtains all services of the remote BLE device. This API uses a promise to return
// Promise // Promise
let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect(); device.connect();
let services = device.getServices(); var services = device.getServices();
console.log("bluetooth services size is ", services.length); console.log("bluetooth services size is ", services.length);
for (let i = 0; i < services.length; i++) { for (let i = 0; i < services.length; i++) {
...@@ -2826,8 +2881,11 @@ Sets the function of notifying the GATT client when the characteristic value of ...@@ -2826,8 +2881,11 @@ Sets the function of notifying the GATT client when the characteristic value of
**Example** **Example**
```js ```js
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setNotifyCharacteristicChanged(notifyCcc, false); device.setNotifyCharacteristicChanged(characteristic, false);
``` ```
...@@ -3296,11 +3354,11 @@ Defines the scan filter parameters. ...@@ -3296,11 +3354,11 @@ Defines the scan filter parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| ----------- | ------ | ---- | ---- | ---------------------------------------- | | ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
| deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. | | deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. |
| name | string | Yes | Yes | Name of the BLE device to filter. | | name | string | Yes | Yes | Name of the BLE device to filter. |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | Yes | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## ScanOptions ## ScanOptions
......
# Display # Display
Provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays.
> **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -139,7 +141,7 @@ Obtains all the display objects. ...@@ -139,7 +141,7 @@ Obtains all the display objects.
| Type | Description | | Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- | | ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return an array containing all the display objects.| | Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.|
**Example** **Example**
...@@ -163,7 +165,7 @@ Enables listening. ...@@ -163,7 +165,7 @@ Enables listening.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed| | type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.| | callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.|
**Example** **Example**
...@@ -186,7 +188,7 @@ Disables listening. ...@@ -186,7 +188,7 @@ Disables listening.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed| | type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.| | callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.|
**Example** **Example**
......
...@@ -575,13 +575,12 @@ Provides KV store configuration. ...@@ -575,13 +575,12 @@ Provides KV store configuration.
Defines the KV store types. Defines the KV store types.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| DEVICE_COLLABORATION | 0 | Device KV store. | | DEVICE_COLLABORATION | 0 | Device KV store. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
| SINGLE_VERSION | 1 | Single KV store. | | SINGLE_VERSION | 1 | Single KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. | | MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## SecurityLevel ## SecurityLevel
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
## Modules to Import ## Modules to Import
``` ```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'; import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager';
``` ```
...@@ -36,7 +36,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -36,7 +36,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
...@@ -50,7 +50,7 @@ enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDevice ...@@ -50,7 +50,7 @@ enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDevice
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
} }
console.log(result); console.log("result is " + result);
}); });
``` ```
...@@ -84,7 +84,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -84,7 +84,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
...@@ -95,7 +95,7 @@ let enterpriseInfo = { ...@@ -95,7 +95,7 @@ let enterpriseInfo = {
} }
enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL) enterpriseDeviceManager.activateAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL)
.then((result) => { .then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -124,17 +124,17 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -124,17 +124,17 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: elementName.bundleName, bundleName: "bundleName",
abilityName: elementName.abilityName, abilityName: "abilityName",
}; };
enterpriseDeviceManager.deactivateAdmin(wantTemp, (error, result) => { enterpriseDeviceManager.deactivateAdmin(wantTemp, (error, result) => {
if (error != null) { if (error != null) {
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
} }
console.log(result); console.log("result is " + result);
}); });
``` ```
...@@ -168,13 +168,13 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -168,13 +168,13 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: "bundleName",
abilityName: "abilityName", abilityName: "abilityName",
}; };
enterpriseDeviceManager.deactivateAdmin(wantTemp).then((result) => { enterpriseDeviceManager.deactivateAdmin(wantTemp).then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -199,14 +199,14 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -199,14 +199,14 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let bundleName = "com.example.myapplication"; let bundleName = "com.example.myapplication";
enterpriseDeviceManager.deactivateSuperAdmin(bundleName, (error, result) => { enterpriseDeviceManager.deactivateSuperAdmin(bundleName, (error, result) => {
if (error != null) { if (error != null) {
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
} }
console.log(result); console.log("result is " + result);
}); });
``` ```
...@@ -234,10 +234,10 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -234,10 +234,10 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let bundleName = "com.example.myapplication"; let bundleName = "com.example.myapplication";
enterpriseDeviceManager.deactivateSuperAdmin(bundleName).then((result) => { enterpriseDeviceManager.deactivateSuperAdmin(bundleName).then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -262,17 +262,17 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -262,17 +262,17 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: elementName.bundleName, bundleName: "bundleName",
abilityName: elementName.abilityName, abilityName: "abilityName",
}; };
enterpriseDeviceManager.isAdminAppActive(wantTemp, (error, result) => { enterpriseDeviceManager.isAdminAppActive(wantTemp, (error, result) => {
if (error != null) { if (error != null) {
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
} }
console.log(result); console.log("result is " + result);
}); });
``` ```
...@@ -302,13 +302,13 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -302,13 +302,13 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: "bundleName",
abilityName: "abilityName", abilityName: "abilityName",
}; };
enterpriseDeviceManager.isAdminAppActive(wantTemp).then((result) => { enterpriseDeviceManager.isAdminAppActive(wantTemp).then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -333,14 +333,14 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -333,14 +333,14 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let bundleName = "com.example.myapplication"; let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName, (error, result) => { enterpriseDeviceManager.isSuperAdmin(bundleName, (error, result) => {
if (error != null) { if (error != null) {
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
} }
console.log(result); console.log("result is " + result);
}); });
``` ```
...@@ -370,10 +370,10 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -370,10 +370,10 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let bundleName = "com.example.myapplication"; let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName).then((result) => { enterpriseDeviceManager.isSuperAdmin(bundleName).then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -397,7 +397,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -397,7 +397,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: "bundleName",
abilityName: "abilityName", abilityName: "abilityName",
...@@ -436,7 +436,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -436,7 +436,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "bundleName", bundleName: "bundleName",
abilityName: "abilityName", abilityName: "abilityName",
...@@ -472,7 +472,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -472,7 +472,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
...@@ -483,7 +483,7 @@ let enterpriseInfo = { ...@@ -483,7 +483,7 @@ let enterpriseInfo = {
} }
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo) enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => { .then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -515,7 +515,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -515,7 +515,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
...@@ -526,7 +526,7 @@ let enterpriseInfo = { ...@@ -526,7 +526,7 @@ let enterpriseInfo = {
} }
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo) enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => { .then((result) => {
console.log(result); console.log("result is " + result);
}).catch(error => { }).catch(error => {
console.log("error occurs" + error); console.log("error occurs" + error);
}); });
...@@ -551,7 +551,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -551,7 +551,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
...@@ -591,7 +591,7 @@ SystemCapability.Customation.EnterpriseDeviceManager ...@@ -591,7 +591,7 @@ SystemCapability.Customation.EnterpriseDeviceManager
**Example** **Example**
``` ```js
let wantTemp = { let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility", abilityName: "com.example.myapplication.MainAbility",
......
# HiAppEvent # HiAppEvent
This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# Distributed Call Chain Tracing # Distributed Call Chain Tracing
This module implements call chain tracing throughout a service process. It provides functions such as starting and stopping call chain tracing and configuring trace points.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# Performance Tracing # Performance Tracing
This module provides the functions of tracing service processes and monitoring the system performance. It provides the data needed for hiTraceMeter to carry out performance analysis.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
...@@ -15,6 +15,70 @@ The input device management module is used to listen for the connection, disconn ...@@ -15,6 +15,70 @@ The input device management module is used to listen for the connection, disconn
import inputDevice from '@ohos.multimodalInput.inputDevice'; import inputDevice from '@ohos.multimodalInput.inputDevice';
``` ```
## inputDevice.on<sup>9+</sup>
on(type: "change", listener: Callback&lt;DeviceListener&gt;): void
Enables listening for hot swap events of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | Yes | Event type of the input device. |
| listener | Callback&lt;[DeviceListener](#devicelistener<sup>9+</sup>)&gt; | Yes | Listener for events of the input device.|
**Example**
```js
let isPhysicalKeyboardExist = true;
inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
console.log("The keyboard type of the device is: " + ret);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected.
isPhysicalKeyboardExist = false;
}
});
});
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
```
## inputDevice.off<sup>9+</sup>
off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void
Disables listening for hot swap events of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | Yes | Event type of the input device. |
| listener | Callback&lt;[DeviceListener](#devicelistener<sup>9+</sup>)&gt; | No | Listener for events of the input device.|
**Example**
```js
function listener(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}
// Disable this listener.
inputDevice.off("change", listener);
// Disable all listeners.
inputDevice.off("change");
// By default, the soft keyboard is closed when listening is disabled.
```
## inputDevice.getDeviceIds ## inputDevice.getDeviceIds
...@@ -30,28 +94,17 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to ...@@ -30,28 +94,17 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to
| -------- | ---------------------------------------- | ---- | ----- | | -------- | ---------------------------------------- | ---- | ----- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
export default { inputDevice.getDeviceIds((ids)=>{
data: { console.log("The device ID list is: " + ids);
deviceIds: Array, });
},
callback: function(ids) {
this.deviceIds = ids;
},
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
inputDevice.getDeviceIds(this.callback);
console.info("InputDeviceJsTest---end---testGetDeviceIds");
}
}
``` ```
## inputDevice.getDeviceIds ## inputDevice.getDeviceIds
function getDeviceIds(): Promise<Array\<number>> getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
Obtains the IDs of all input devices. This API uses a promise to return the result. Obtains the IDs of all input devices. This API uses a promise to return the result.
...@@ -60,104 +113,182 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu ...@@ -60,104 +113,182 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value** **Return value**
| Parameter | Description | | Parameter | Description |
| ---------------------- | ------------------ | | ---------------------------------- | ------------------- |
| Promise<Array\<number>> | Promise used to return the result.| | Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
export default { inputDevice.getDeviceIds().then((ids)=>{
testGetDeviceIds: function () { console.log("The device ID list is: " + ids);
console.info("InputDeviceJsTest---start---testGetDeviceIds"); });
let promise = inputDevice.getDeviceIds();
promise.then((data)=> {
console.info('GetDeviceIds successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceIds. Cause: ' + JSON.stringify(err));
});
}
}
``` ```
## inputDevice.getDevice
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
Obtains information about an input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- |
| deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Example**
```js
// Obtain the name of the device whose ID is 1.
inputDevice.getDevice(1, (inputDevice)=>{
console.log("The device name is: " + inputDevice.name);
});
```
## inputDevice.getDevice ## inputDevice.getDevice
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
Obtains the information about an input device. This API uses an asynchronous callback to return the result. Obtains information about an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | ------ | ---- | ------------ |
| deviceId | number | Yes | ID of the input device whose information is to be obtained. | | deviceId | number | Yes | ID of the input device.|
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the **InputDeviceData** object.|
**Return value**
| Parameter | Description |
| ---------------------------------------- | ------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
export default { // Obtain the name of the device whose ID is 1.
InputDeviceData: { inputDevice.getDevice(1).then((inputDevice)=>{
deviceId : 0, console.log("The device name is: " + inputDevice.name);
name : "NA", });
sources : Array,
axisRanges : Array,
},
callback: function(deviceData) {
this.InputDeviceData = deviceData;
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
inputDevice.getDevice(1, this.callback);
console.info("InputDeviceJsTest---end---testGetDevice");
}
}
``` ```
## inputDevice.getDevice ## inputDevice.supportKeys<sup>9+</sup>
function getDevice(deviceId: number): Promise\<InputDeviceData> supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;Array&lt;boolean&gt;&gt;): void;
Obtains the information about an input device. This API uses a promise to return the result. Obtains the key codes supported by the input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------ | ---- | --------------------------------- |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
| callback | Callback&lt;Array&lt;boolean&gt;&gt; | Yes | Callback used to return the result. |
**Example**
```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
inputDevice.supportKeys(1, [17, 22, 2055], (ret)=>{
console.log("The query result is as follows: " + ret);
});
```
## inputDevice.supportKeys<sup>9+</sup>
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;boolean&gt;&gt;;
Obtains the key codes supported by the input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | --------------------------------- |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
**Return value** **Return value**
| Parameter | Description | | Parameter | Description |
| ------------------------ | ------------------ | | ----------------------------------- | ------------------- |
| Promise\<InputDeviceData> | Promise used to return the result.| | Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
export default { // Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
InputDeviceData: { inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)=>{
deviceId : 0, console.log("The query result is as follows: " + ret);
name : "NA", })
sources : Array,
axisRanges : Array,
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
let promise = inputDevice.getDevice(1);
promise.then((data)=> {
console.info('GetDeviceId successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceId. Cause: ' + JSON.stringify(err));
});
}
}
``` ```
## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): void;
Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| callback | AsyncCallback&lt;[KeyboardType](#keyboardtype)&gt; | Yes | Callback used to return the result. |
**Example**
```js
// Query the keyboard type of the input device whose ID is 1.
inputDevice.getKeyboardType(1, (ret)=>{
console.log("The keyboard type of the device is: " + ret);
});
```
## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt;;
Obtains the keyboard type of an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Parameter | Description |
| ---------------------------------------- | ------------------- |
| Promise&lt;[KeyboardType](#keyboardtype)&gt; | Promise used to return the result.|
**Example**
```js
// Query the keyboard type of the input device whose ID is 1.
inputDevice.getKeyboardType(1).then((ret)=>{
console.log("The keyboard type of the device is: " + ret);
})
```
## DeviceListener<sup>9+</sup>
Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| -------- | ------------------------- | --------------------------------- |
| type | [ChangeType](#changetype) | Device change type, which indicates whether an input device is inserted or removed. |
| deviceId | number | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
## InputDeviceData ## InputDeviceData
...@@ -166,36 +297,51 @@ Defines the information about an input device. ...@@ -166,36 +297,51 @@ Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description | | Name | Type | Description |
| ---------- | -------------------------- | ---------------------------------------------------- | | -------------------- | -------------------------------------- | ---------------------------------------- |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. | | id | number | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. | | name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad. | | sources | Array&lt;[SourceType](#sourcetype)&gt; | Source type of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | Axis information of the input device. | | axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | Axis information of the input device. |
| bus | number | Bus type of the input device. | | bus<sup>9+</sup> | number | Bus type of the input device. |
| product | number | Product information of the input device. | | product<sup>9+</sup> | number | Product information of the input device. |
| vendor | number | Vendor information of the input device. | | vendor<sup>9+</sup> | number | Vendor information of the input device. |
| version | number | Version information of the input device. | | version<sup>9+</sup> | number | Version information of the input device. |
| phys | string | Physical address of the input device. | | phys<sup>9+</sup> | string | Physical address of the input device. |
| uniq | string | Unique ID of the input device. | | uniq<sup>9+</sup> | string | Unique ID of the input device. |
## AxisType<sup>9+</sup>
## AxisType Defines the axis type of an input device.
Defines the axis type of an input device, which is **NULL**. **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| ----------- | ------ | --------------- |
| touchMajor | string | touchMajor axis. |
| touchMinor | string | touchMinor axis. |
| toolMinor | string | toolMinor axis. |
| toolMajor | string | toolMajor axis. |
| orientation | string | Orientation axis.|
| pressure | string | Pressure axis. |
| x | string | X axis. |
| y | string | Y axis. |
| NULL | string | None. |
## AxisRange ## AxisRange
Defines the axis information of an input device. Defines the axis range of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description | | Name | Type | Description |
| ------ | ------------------------- | -------- | | ----------------------- | ------------------------- | -------- |
| source | [SourceType](#sourcetype) | Input source type of the axis.| | source | [SourceType](#sourcetype) | Input source type of the axis.|
| axis | [AxisType](axistype) | Axis type. | | axis | [AxisType](#axistype) | Axis type. |
| max | number | Maximum value reported by the axis. | | max | number | Maximum value of the axis. |
| min | number | Minimum value reported by the axis. | | min | number | Minimum value of the axis. |
| fuzz<sup>9+</sup> | number | Fuzzy value of the axis. |
| flat<sup>9+</sup> | number | Benchmark value of the axis. |
| resolution<sup>9+</sup> | number | Resolution of the axis. |
## SourceType ## SourceType
...@@ -211,3 +357,29 @@ Enumerates the input source types. For example, if a mouse reports an x-axis eve ...@@ -211,3 +357,29 @@ Enumerates the input source types. For example, if a mouse reports an x-axis eve
| trackball | string | The input device is a trackball.| | trackball | string | The input device is a trackball.|
| touchpad | string | The input device is a touchpad.| | touchpad | string | The input device is a touchpad.|
| joystick | string | The input device is a joystick.| | joystick | string | The input device is a joystick.|
## ChangeType
Defines the change type for the hot swap event of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| ------ | ------ | --------- |
| add | string | An input device is inserted.|
| remove | string | An input device is removed.|
## KeyboardType<sup>9+</sup>
Enumerates the keyboard types.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Value | Description |
| ------------------- | ------ | ---- | --------- |
| NONE | number | 0 | Keyboard without keys. |
| UNKNOWN | number | 1 | Keyboard with unknown keys.|
| ALPHABETIC_KEYBOARD | number | 2 | Full keyboard. |
| DIGITAL_KEYBOARD | number | 3 | Keypad. |
| HANDWRITING_PEN | number | 4 | Stylus. |
| REMOTE_CONTROL | number | 5 | Remote control. |
...@@ -364,10 +364,10 @@ list.add(2); ...@@ -364,10 +364,10 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.replaceAllElements((value, index) => { list.replaceAllElements((value: number, index: number) => {
return value = 2 * value; return value = 2 * value;
}); });
list.replaceAllElements((value, index) => { list.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
``` ```
...@@ -439,8 +439,8 @@ list.add(2); ...@@ -439,8 +439,8 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.sort((a, b) => a - b); list.sort((a: number, b: number) => a - b);
list.sort((a, b) => b - a); list.sort((a: number, b: number) => b - a);
``` ```
### getSubList ### getSubList
...@@ -472,9 +472,9 @@ list.add(2); ...@@ -472,9 +472,9 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.subList(2, 4); let result = list.getSubList(2, 4);
let result1 = list.subList(4, 3); let result1 = list.getSubList(4, 3);
let result2 = list.subList(2, 6); let result2 = list.getSubList(2, 6);
``` ```
### clear ### clear
......
# Media Query # Media Query
> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE** > **NOTE**
>
> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -22,19 +23,21 @@ matchMediaSync(condition: string): MediaQueryListener ...@@ -22,19 +23,21 @@ matchMediaSync(condition: string): MediaQueryListener
Sets the media query criteria and returns the corresponding listening handle. Sets the media query criteria and returns the corresponding listening handle.
- Parameters **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| condition | string | Yes| Matching condition of a media event.|
- Return value **Parameters**
| Type| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | | --------- | ------ | ---- | ---------------------------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.| | condition | string | Yes | Matching condition of a media event. For details, see [Syntax of Media Query Conditions](../../ui/ui-ts-layout-mediaquery.md#syntax-of-media-query-conditions).|
- Example **Return value**
| Type | Description |
| ------------------ | ---------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.|
**Example**
```js ```js
let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
``` ```
...@@ -42,13 +45,14 @@ let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen ...@@ -42,13 +45,14 @@ let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen
Media query handle, including the first query result when the handle is applied for. Media query handle, including the first query result when the handle is applied for.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
### Attributes ### Attributes
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ------- | ------- | ---- | ---- | ---------- |
| matches | boolean | Yes| No| Whether the match condition is met.| | matches | boolean | Yes | No | Whether the match condition is met. |
| media | string | Yes| No| Matching condition of a media event.| | media | string | Yes | No | Matching condition of a media event.|
### on ### on
...@@ -57,13 +61,15 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void ...@@ -57,13 +61,15 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void
Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change. Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change.
- Parameters **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | **Parameters**
| type | string | Yes| Must enter the string **change**.| | Name | Type | Mandatory | Description |
| callback | Callback&lt;MediaQueryResult&gt; | Yes| Callback registered with media query.| | -------- | -------------------------------- | ---- | ---------------- |
| type | string | Yes | Must enter the string **change**.|
| callback | Callback&lt;MediaQueryResult&gt; | Yes | Callback registered with media query. |
- Example **Example**
For details, see [off Example](#off). For details, see [off Example](#off).
...@@ -71,18 +77,21 @@ Registers a callback with the corresponding query condition by using the handle. ...@@ -71,18 +77,21 @@ Registers a callback with the corresponding query condition by using the handle.
off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void
Unregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change. Deregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change.
- Parameters
| Name| Type| Mandatory| Description| **System capability**: SystemCapability.ArkUI.ArkUI.Full
| -------- | -------- | -------- | -------- |
| type | boolean | Yes| Must enter the string **change**.| **Parameters**
| callback | Callback&lt;MediaQueryResult&gt; | No| Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.| | Name | Type | Mandatory | Description |
| -------- | -------------------------------- | ---- | ----------------------------- |
| type | boolean | Yes | Must enter the string **change**. |
| callback | Callback&lt;MediaQueryResult&gt; | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.|
- Example **Example**
```js ```js
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
function onPortrait(mediaQueryResult) { function onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) { if (mediaQueryResult.matches) {
// do something here // do something here
...@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl
} }
} }
listener.on('change', onPortrait) // Register a callback. listener.on('change', onPortrait) // Register a callback.
listener.off('change', onPortrait) // Unregister a callback. listener.off('change', onPortrait) // Deregister a callback.
``` ```
...@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl
### Attributes ### Attributes
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ------- | ------- | ---- | ---- | ---------- |
| matches | boolean | Yes| No| Whether the match condition is met.| | matches | boolean | Yes | No | Whether the match condition is met. |
| media | string | Yes| No| Matching condition of a media event.| | media | string | Yes | No | Matching condition of a media event.|
### Example ### Example
......
# Setting the System Time # Setting the System Time
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. This module is used to set and obtain the current system date, time, and time zone.
> > **NOTE**<br>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -189,7 +189,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This ...@@ -189,7 +189,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
**Example** **Example**
```js ```js
systemTime.getCurrentTime().then((data) => { systemTime.getRealActiveTime().then((data) => {
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data)); console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getRealActiveTime because ` + JSON.stringify(error)); console.error(`failed to systemTime.getRealActiveTime because ` + JSON.stringify(error));
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册