提交 01d35a8d 编写于 作者: S shawn_he 提交者: Gitee

Merge branch 'OpenHarmony-3.1-Release' of gitee.com:openharmony/docs into 5150-a

...@@ -20,23 +20,22 @@ ...@@ -20,23 +20,22 @@
- Development - Development
- [Ability Development](ability/Readme-EN.md) - [Ability Development](ability/Readme-EN.md)
- [UI Development](ui/Readme-EN.md) - [UI Development](ui/Readme-EN.md)
- Basic Feature Development - [Common Event and Notification](notification/Readme-EN.md)
- [Common Event and Notification](notification/Readme-EN.md) - [Window Manager](windowmanager/Readme-EN.md)
- [Window Manager](windowmanager/Readme-EN.md) - [WebGL](webgl/Readme-EN.md)
- [WebGL](webgl/Readme-EN.md) - [Media](media/Readme-EN.md)
- [Media](media/Readme-EN.md) - [Security](security/Readme-EN.md)
- [Security](security/Readme-EN.md) - [Connectivity](connectivity/Readme-EN.md)
- [Connectivity](connectivity/Readme-EN.md) - [Data Management](database/Readme-EN.md)
- [Data Management](database/Readme-EN.md) - [Telephony](telephony/Readme-EN.md)
- [Telephony](telephony/Readme-EN.md) - [Agent-Powered Scheduled Reminders](background-agent-scheduled-reminder/Readme-EN.md)
- [Agent-Powered Scheduled Reminders](background-agent-scheduled-reminder/Readme-EN.md) - [Background Task Management](background-task-management/Readme-EN.md)
- [Background Task Management](background-task-management/Readme-EN.md) - [Work Scheduler](work-scheduler/Readme-EN.md)
- [Work Scheduler](work-scheduler/Readme-EN.md) - [Device Management](device/Readme-EN.md)
- [Device Management](device/Readme-EN.md) - [Device Usage Statistics](device-usage-statistics/Readme-EN.md)
- [Device Usage Statistics](device-usage-statistics/Readme-EN.md) - [DFX](dfx/Readme-EN.md)
- [DFX](dfx/Readme-EN.md) - [Internationalization](internationalization/Readme-EN.md)
- [Internationalization](internationalization/Readme-EN.md) - [Native APIs](napi/Readme-EN.md)
- [Native APIs](napi/Readme-EN.md)
- Tools - Tools
- [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md) - [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- Hands-On Tutorials - Hands-On Tutorials
......
...@@ -8,21 +8,27 @@ The following figure shows the ability call process. ...@@ -8,21 +8,27 @@ The following figure shows the ability call process.
![stage-call](figures/stage-call.png) ![stage-call](figures/stage-call.png)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The startup mode of the callee must be **singleton**.
> Currently, only system applications and Service Extension abilities can use the **Call** APIs to access the callee.
## Available APIs ## Available APIs
The table below describes the ability call APIs. For details, see [Ability](../reference/apis/js-apis-application-ability.md#caller). The table below describes the ability call APIs. For details, see [Ability](../reference/apis/js-apis-application-ability.md#caller).
**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 started, 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.
...@@ -51,7 +57,7 @@ import Ability from '@ohos.application.Ability' ...@@ -51,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
...@@ -77,7 +83,7 @@ export default class MySequenceable { ...@@ -77,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 them. 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'
...@@ -121,7 +127,7 @@ import Ability from '@ohos.application.Ability' ...@@ -121,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 {
...@@ -142,7 +148,7 @@ async onButtonGetCaller() { ...@@ -142,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
...@@ -166,7 +172,7 @@ context.startAbilityByCall({ ...@@ -166,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;
...@@ -184,7 +190,7 @@ function getRemoteDeviceId() { ...@@ -184,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']
...@@ -196,7 +202,7 @@ context.requestPermissionsFromUser(permissions).then((data) => { ...@@ -196,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 in either of the following ways: without a return value or obtaining data returned by the callee. 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() {
...@@ -209,7 +215,7 @@ async onButtonCall() { ...@@ -209,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 = ''
...@@ -231,7 +237,7 @@ async onButtonCallWithResult(originMsg, backMsg) { ...@@ -231,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()
...@@ -242,9 +248,6 @@ try { ...@@ -242,9 +248,6 @@ try {
} }
``` ```
## Development Example ## 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 Call Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
[StageCallAbility](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
In this sample, the **AbilityStage** APIs are implemented in the **AbilityStage.ts** file in the **Application** directory, the **Ability** APIs are implemented in the **MainAbility** directory, and **pages/index** is the pages of the ability. Another ability and callee are implemented in the **CalleeAbility** directory, and its pages are the content configured in **pages/second**. The **MainAbility** functions as the caller, and the **CalleeAbility** functions as the callee. After starting the **CalleeAbility**, the **MainAbility** obtains the caller interface, processes the string entered by the user, and transfers the processed string to the **CalleeAbility**. The **CalleeAbility** refreshes the page based on the received data and returns the result to the **MainAbility**.
...@@ -54,7 +54,7 @@ They are organized as follows: ...@@ -54,7 +54,7 @@ They are organized as follows:
- [Component Reference (JavaScript-based Web-like Development Paradigm)](reference/arkui-js/Readme-EN.md) - [Component Reference (JavaScript-based Web-like Development Paradigm)](reference/arkui-js/Readme-EN.md)
- [Component Reference (TypeScript-based Declarative Development Paradigm)](reference/arkui-ts/Readme-EN.md) - [Component Reference (TypeScript-based Declarative Development Paradigm)](reference/arkui-ts/Readme-EN.md)
- APIs - APIs
- [JS and TS APIs](reference/apis/Readme-CN.md) - [JS and TS APIs](reference/apis/Readme-EN.md)
- Native APIs - Native APIs
- [Standard Libraries](reference/native-lib/third_party_libc/musl.md) - [Standard Libraries](reference/native-lib/third_party_libc/musl.md)
- [Node_API](reference/native-lib/third_party_napi/napi.md) - [Node_API](reference/native-lib/third_party_napi/napi.md)
......
...@@ -8,7 +8,7 @@ In Host mode, you can obtain the list of connected devices, enable or disable th ...@@ -8,7 +8,7 @@ In Host mode, you can obtain the list of connected devices, enable or disable th
The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management. The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md). The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md).
**Table 1** Open USB APIs **Table 1** Open USB APIs
......
# Context Module # Context
## Modules to Import ## Modules to Import
...@@ -925,9 +925,9 @@ Describes the HAP module information. ...@@ -925,9 +925,9 @@ Describes the HAP module information.
| iconId | number | Yes | No | Module icon ID. | | iconId | number | Yes | No | Module icon ID. |
| backgroundImg | string | Yes | No | Module background image. | | backgroundImg | string | Yes | No | Module background image. |
| supportedModes | number | Yes | No | Modes supported by the module. | | supportedModes | number | Yes | No | Modes supported by the module. |
| reqCapabilities | Array<string> | Yes | No | Capabilities required for module running.| | reqCapabilities | Array\<string> | Yes | No | Capabilities required for module running.|
| deviceTypes | Array<string> | Yes | No | An array of supported device types.| | deviceTypes | Array\<string> | Yes | No | An array of supported device types.|
| abilityInfo | Array\<AbilityInfo> | Yes | No | Ability information. | | abilityInfo | Array\\<AbilityInfo> | Yes | No | Ability information. |
| moduleName | string | Yes | No | Module name. | | moduleName | string | Yes | No | Module name. |
| mainAbilityName | string | Yes | No | Name of the entrance ability. | | mainAbilityName | string | Yes | No | Name of the entrance ability. |
| installationFree | boolean | Yes | No | When installation-free is supported. | | installationFree | boolean | Yes | No | When installation-free is supported. |
......
# AbilityManager # AbilityManager
> **NOTE**<br/> > **NOTE**
> >
> 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.
> >
...@@ -18,13 +18,13 @@ Enumerates the ability states. ...@@ -18,13 +18,13 @@ Enumerates the ability states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.| | INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state. | | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. | | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state. | | FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state. | | BACKGROUNDING | 12 | The ability is in the backgrounding state. |
## updateConfiguration ## updateConfiguration
......
# AbilityStageContext # AbilityStageContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the context of an ability stage. This module is inherited from [Context](js-apis-application-context.md). Implements the context of an ability stage. This module is inherited from [Context](js-apis-application-context.md).
## Modules to Import
```js
import AbilityStage from '@ohos.application.AbilityStage';
```
## Usage ## Usage
The ability stage context is obtained through an **AbilityStage** instance. The ability stage context is obtained through an **AbilityStage** instance.
```js ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
...@@ -28,7 +32,7 @@ class MyAbilityStage extends AbilityStage { ...@@ -28,7 +32,7 @@ class MyAbilityStage extends AbilityStage {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.| | currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.| | config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.|
# AbilityRunningInfo # AbilityRunningInfo
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> 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.
Provides ability running information. Provides ability running information.
## Modules to Import
```js
import abilitymanager from '@ohos.application.abilityManager';
```
## Usage ## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**. The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**.
```js ```js
import abilitymanager from '@ohos.application.abilityManager'; import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => { abilitymanager.getAbilityRunningInfos((err,data) => {
...@@ -27,12 +31,12 @@ abilitymanager.getAbilityRunningInfos((err,data) => { ...@@ -27,12 +31,12 @@ abilitymanager.getAbilityRunningInfos((err,data) => {
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes| No| Information that matches an ability. | | ability | ElementName | Yes| No| Information that matches an ability. |
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID. | | uid | number | Yes| No| User ID. |
| processName | string | Yes| No| Process name. | | processName | string | Yes| No| Process name. |
| startTime | number | Yes| No| Ability start time. | | startTime | number | Yes| No| Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanagerabilitystate) | Yes| No| Ability state. | | abilityState | [abilityManager.AbilityState](#abilitymanagerabilitystate) | Yes| No| Ability state. |
## abilityManager.AbilityState ## abilityManager.AbilityState
...@@ -41,10 +45,10 @@ Enumerates the ability states. ...@@ -41,10 +45,10 @@ Enumerates the ability states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.| | INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state. | | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. | | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state. | | FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state. | | BACKGROUNDING | 12 | The ability is in the backgrounding state. |
# App Account Management # App Account Management
> ![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.
...@@ -26,7 +26,7 @@ Creates an **AppAccountManager** instance. ...@@ -26,7 +26,7 @@ Creates an **AppAccountManager** instance.
**Example** **Example**
```js ```js
var appAccountManager = account.createAppAccountManager(); const appAccountManager = account_appAccount.createAppAccountManager();
``` ```
## AppAccountManager ## AppAccountManager
...@@ -387,7 +387,7 @@ Checks whether an app account allows application data synchronization. This meth ...@@ -387,7 +387,7 @@ Checks whether an app account allows application data synchronization. This meth
### setAccountCredential ### setAccountCredential
setAccountCredential(name: string, credentialType: string, credential: string, callback: AsyncCallback&lt;void&gt;): void setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void
Sets a credential for an app account. This method uses an asynchronous callback to return the result. Sets a credential for an app account. This method uses an asynchronous callback to return the result.
......
# MissionInfo # MissionInfo
> **NOTE**<br> > **NOTE**
>
> 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.
## Modules to Import ## Modules to Import
......
# appManager # appManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **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.
...@@ -25,9 +26,9 @@ Checks whether this application is undergoing a stability test. This API uses an ...@@ -25,9 +26,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -49,9 +50,9 @@ Checks whether this application is undergoing a stability test. This API uses a ...@@ -49,9 +50,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -75,9 +76,9 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -75,9 +76,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -99,9 +100,9 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -99,9 +100,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -122,9 +123,9 @@ Obtains the memory size of this application. This API uses a promise to return t ...@@ -122,9 +123,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.| | Promise&lt;number&gt; | Size of the application memory.|
**Example** **Example**
...@@ -146,9 +147,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -146,9 +147,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.| | callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example** **Example**
...@@ -160,7 +161,7 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -160,7 +161,7 @@ Obtains the memory size of this application. This API uses an asynchronous callb
``` ```
## appManager.getProcessRunningInfos<sup>8+</sup> ## appManager.getProcessRunningInfos<sup>8+</sup>
getProcessRunningInfos(): Promise<Array\<ProcessRunningInfo>>; getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
Obtains information about the running processes. This API uses a promise to return the result. Obtains information about the running processes. This API uses a promise to return the result.
...@@ -168,9 +169,9 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -168,9 +169,9 @@ Obtains information about the running processes. This API uses a promise to retu
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<Array\<ProcessRunningInfo>> | Promise used to return the process information.| | Promise\<Array\<ProcessRunningInfo>> | Promise used to return the process information.|
**Example** **Example**
...@@ -184,7 +185,7 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -184,7 +185,7 @@ Obtains information about the running processes. This API uses a promise to retu
## appManager.getProcessRunningInfos<sup>8+</sup> ## appManager.getProcessRunningInfos<sup>8+</sup>
getProcessRunningInfos(callback: AsyncCallback<Array\<ProcessRunningInfo>>): void; getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void;
Obtains information about the running processes. This API uses an asynchronous callback to return the result. Obtains information about the running processes. This API uses an asynchronous callback to return the result.
...@@ -192,9 +193,9 @@ Obtains information about the running processes. This API uses an asynchronous c ...@@ -192,9 +193,9 @@ Obtains information about the running processes. This API uses an asynchronous c
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array\<ProcessRunningInfo>> | No| Callback used to return the process information.| | callback | AsyncCallback\<Array\<ProcessRunningInfo>> | No| Callback used to return the process information.|
**Example** **Example**
......
# Audio Management # Audio Management
> **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.
> >
> API version 9 is a canary release for trial use. The APIs of this version may be unstable. > API version 9 is a canary release for trial use. The APIs of this version may be unstable.
......
# 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
...@@ -223,7 +223,7 @@ Obtains the connection status of a profile. ...@@ -223,7 +223,7 @@ Obtains the connection status of a profile.
**Example** **Example**
```js ```js
let result = bluetooth.getProfileConnState(PROFILE_A2DP_SOURCE); let result = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
``` ```
...@@ -364,7 +364,7 @@ Sets the Bluetooth scan mode so that the device can be discovered by a remote de ...@@ -364,7 +364,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);
``` ```
...@@ -456,7 +456,7 @@ Sets the device pairing confirmation. ...@@ -456,7 +456,7 @@ Sets the device pairing confirmation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- | | ------ | ------- | ---- | -------------------------------- |
| device | string | Yes | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.| | device | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| accept | boolean | Yes | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite. | | accept | boolean | Yes | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite. |
**Return value** **Return value**
...@@ -729,7 +729,7 @@ bluetooth.off('stateChange', onReceiveEvent); ...@@ -729,7 +729,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
...@@ -782,6 +782,14 @@ Listens for a connection to be made to this socket from the client and accepts i ...@@ -782,6 +782,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);
...@@ -847,6 +855,14 @@ Closes the listening socket of the server. ...@@ -847,6 +855,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);
``` ```
...@@ -869,6 +885,15 @@ Closes the client socket. ...@@ -869,6 +885,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);
``` ```
...@@ -897,6 +922,15 @@ Writes data to the remote device through the socket. ...@@ -897,6 +922,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;
...@@ -932,6 +966,15 @@ No value is returned. ...@@ -932,6 +966,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]);
...@@ -963,6 +1006,15 @@ No value is returned. ...@@ -963,6 +1006,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);
``` ```
...@@ -1218,7 +1270,7 @@ No value is returned. ...@@ -1218,7 +1270,7 @@ No value is returned.
| | | | | |
| ------------------- | ------------- | | ------------------- | ------------- |
| Type | Description | | Type | Description |
| Array&lt;string&gt; | List of addresses of the connected devices. | | Array&lt;string&gt; | Addresses of the connected devices. |
### getDeviceState<sup>8+</sup><a name="getDeviceState"></a> ### getDeviceState<sup>8+</sup><a name="getDeviceState"></a>
...@@ -1236,14 +1288,12 @@ Obtains the connection status of the profile. ...@@ -1236,14 +1288,12 @@ Obtains the connection status of the profile.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.| | device | string | Yes | Address of the target device.|
|
**Return value** **Return value**
| | | | | |
| ------------------------------------------------- | ----------------------- | | ------------------------------------------------- | ----------------------- |
| Type | Description | | Type | Description |
| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained. | | [ProfileConnectionState](#profileconnectionState) | Profile connection state obtained. |
## A2dpSourceProfile ## A2dpSourceProfile
...@@ -1251,7 +1301,7 @@ Obtains the connection status of the profile. ...@@ -1251,7 +1301,7 @@ Obtains the connection status of the profile.
Before using a method of **A2dpSourceProfile**, you need to create an instance of this class by using the **getProfile()** method. Before using a method of **A2dpSourceProfile**, you need to create an instance of this class by using the **getProfile()** method.
### connect<sup>8+</sup><a name="connect"></a> ### connect<sup>8+</sup><a name="a2dp-connect"></a>
connect(device: string): boolean connect(device: string): boolean
...@@ -1278,12 +1328,12 @@ Sets up an Advanced Audio Distribution Profile (A2DP) connection. ...@@ -1278,12 +1328,12 @@ 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');
``` ```
### disconnect<sup>8+</sup><a name="disconnect"></a> ### disconnect<sup>8+</sup><a name="a2dp-disconnect"></a>
disconnect(device: string): boolean disconnect(device: string): boolean
...@@ -1310,7 +1360,7 @@ Disconnects an A2DP connection. ...@@ -1310,7 +1360,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');
``` ```
...@@ -1397,7 +1447,7 @@ Obtains the playing status of a device. ...@@ -1397,7 +1447,7 @@ Obtains the playing status 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');
``` ```
...@@ -1407,7 +1457,7 @@ let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); ...@@ -1407,7 +1457,7 @@ let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
Before using a method of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using the **getProfile()** method. Before using a method of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using the **getProfile()** method.
### connect<sup>8+</sup><a name="connect"></a> ### connect<sup>8+</sup><a name="hfp-connect"></a>
connect(device: string): boolean connect(device: string): boolean
...@@ -1434,12 +1484,12 @@ Sets up a Hands-free Profile (HFP) connection of a device. ...@@ -1434,12 +1484,12 @@ 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');
``` ```
### disconnect<sup>8+</sup><a name="disconnect"></a> ### disconnect<sup>8+</sup><a name="hfp-disconnect"></a>
disconnect(device: string): boolean disconnect(device: string): boolean
...@@ -1465,7 +1515,7 @@ Disconnects the HFP connection of a device. ...@@ -1465,7 +1515,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');
``` ```
...@@ -1665,7 +1715,7 @@ cccV[0] = 1; ...@@ -1665,7 +1715,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.
...@@ -1757,8 +1807,11 @@ Notifies the connected client device when a characteristic value changes. ...@@ -1757,8 +1807,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);
``` ```
...@@ -1984,7 +2037,7 @@ Subscribes to the descriptor read request events. ...@@ -1984,7 +2037,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**
...@@ -2334,7 +2387,7 @@ Obtains all services of the remote BLE device. This method uses a promise to ret ...@@ -2334,7 +2387,7 @@ Obtains all services of the remote BLE device. This method uses a promise to ret
// 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++) {
...@@ -2672,8 +2725,11 @@ Sets the function of notifying the GATT client when the characteristic value of ...@@ -2672,8 +2725,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);
``` ```
......
# DataAbilityPredicates # DataAbilityPredicates
> **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.
...@@ -17,7 +18,7 @@ import dataAbility from '@ohos.data.dataAbility'; ...@@ -17,7 +18,7 @@ import dataAbility from '@ohos.data.dataAbility';
createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates
Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object. Creates an **RdbPredicates** object from a **DataAbilityPredicates** object.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
...@@ -69,8 +70,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -69,8 +70,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "lisi")
predicates.equalTo("NAME", "lisi")
``` ```
...@@ -97,8 +97,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -97,8 +97,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.notEqualTo("NAME", "lisi")
predicates.notEqualTo("NAME", "lisi")
``` ```
...@@ -119,8 +118,7 @@ Adds a left parenthesis to this **DataAbilityPredicates**. ...@@ -119,8 +118,7 @@ Adds a left parenthesis to this **DataAbilityPredicates**.
**Example** **Example**
```js ```js
let predicates = new dataAbilitylity.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "lisi")
predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
...@@ -146,8 +144,7 @@ Adds a right parenthesis to this **DataAbilityPredicates**. ...@@ -146,8 +144,7 @@ Adds a right parenthesis to this **DataAbilityPredicates**.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "lisi")
predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
...@@ -173,8 +170,7 @@ Adds the OR condition to this **DataAbilityPredicates**. ...@@ -173,8 +170,7 @@ Adds the OR condition to this **DataAbilityPredicates**.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "Lisa")
predicates.equalTo("NAME", "Lisa")
.or() .or()
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
``` ```
...@@ -197,8 +193,7 @@ Adds the AND condition to this **DataAbilityPredicates**. ...@@ -197,8 +193,7 @@ Adds the AND condition to this **DataAbilityPredicates**.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "Lisa")
predicates.equalTo("NAME", "Lisa")
.and() .and()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
``` ```
...@@ -227,8 +222,7 @@ Sets a **DataAbilityPredicates** object to match a string containing the specifi ...@@ -227,8 +222,7 @@ Sets a **DataAbilityPredicates** object to match a string containing the specifi
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.contains("NAME", "os")
predicates.contains("NAME", "os")
``` ```
...@@ -255,8 +249,7 @@ Sets a **DataAbilityPredicates** object to match a string that starts with the s ...@@ -255,8 +249,7 @@ Sets a **DataAbilityPredicates** object to match a string that starts with the s
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.beginsWith("NAME", "os")
predicates.beginsWith("NAME", "os")
``` ```
...@@ -283,8 +276,7 @@ Sets a **DataAbilityPredicates** object to match a string that ends with the spe ...@@ -283,8 +276,7 @@ Sets a **DataAbilityPredicates** object to match a string that ends with the spe
**Example** **Example**
``` ```
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.endsWith("NAME", "se")
predicates.endsWith("NAME", "se")
``` ```
...@@ -310,8 +302,7 @@ Sets a **DataAbilityPredicates** object to match the field whose value is null. ...@@ -310,8 +302,7 @@ Sets a **DataAbilityPredicates** object to match the field whose value is null.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.isNull("NAME")
predicates.isNull("NAME")
``` ```
...@@ -337,8 +328,7 @@ Sets a **DataAbilityPredicates** object to match the field whose value is not nu ...@@ -337,8 +328,7 @@ Sets a **DataAbilityPredicates** object to match the field whose value is not nu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.isNotNull("NAME")
predicates.isNotNull("NAME")
``` ```
...@@ -365,8 +355,7 @@ Sets a **DataAbilityPredicates** object to match a string that is similar to the ...@@ -365,8 +355,7 @@ Sets a **DataAbilityPredicates** object to match a string that is similar to the
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.like("NAME", "%os%")
predicates.like("NAME", "%os%")
``` ```
...@@ -393,8 +382,7 @@ Sets a **DataAbilityPredicates** object to match the specified string. ...@@ -393,8 +382,7 @@ Sets a **DataAbilityPredicates** object to match the specified string.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.glob("NAME", "?h*g")
predicates.glob("NAME", "?h*g")
``` ```
...@@ -422,8 +410,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -422,8 +410,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.between("AGE", 10, 50)
predicates.between("AGE", 10, 50)
``` ```
...@@ -451,8 +438,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -451,8 +438,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.notBetween("AGE", 10, 50)
predicates.notBetween("AGE", 10, 50)
``` ```
...@@ -479,8 +465,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -479,8 +465,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.greaterThan("AGE", 18)
predicates.greaterThan("AGE", 18)
``` ```
...@@ -507,8 +492,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -507,8 +492,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.lessThan("AGE", 20)
predicates.lessThan("AGE", 20)
``` ```
...@@ -535,8 +519,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -535,8 +519,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.greaterThanOrEqualTo("AGE", 18)
predicates.greaterThanOrEqualTo("AGE", 18)
``` ```
...@@ -563,8 +546,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu ...@@ -563,8 +546,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.lessThanOrEqualTo("AGE", 20)
predicates.lessThanOrEqualTo("AGE", 20)
``` ```
...@@ -590,8 +572,7 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i ...@@ -590,8 +572,7 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.orderByAsc("NAME")
predicates.orderByAsc("NAME")
``` ```
...@@ -617,8 +598,7 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i ...@@ -617,8 +598,7 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.orderByDesc("AGE")
predicates.orderByDesc("AGE")
``` ```
...@@ -639,14 +619,7 @@ Sets a **DataAbilityPredicates** object to filter out duplicate records. ...@@ -639,14 +619,7 @@ Sets a **DataAbilityPredicates** object to filter out duplicate records.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "Rose").distinct()
predicates.equalTo("NAME", "Rose").distinct("NAME")
let promiseDistinct = rdbStore.query(predicates, ["NAME"])
promiseDistinct.then((resultSet) => {
console.log("distinct")
}).catch((err) => {
expect(null).assertFail();
})
``` ```
...@@ -672,8 +645,7 @@ Set a **DataAbilityPredicates** object to specify the maximum number of records. ...@@ -672,8 +645,7 @@ Set a **DataAbilityPredicates** object to specify the maximum number of records.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "Rose").limitAs(3)
predicates.equalTo("NAME", "Rose").limitAs(3)
``` ```
...@@ -699,8 +671,7 @@ Sets a **DataAbilityPredicates** object to specify the start position of the ret ...@@ -699,8 +671,7 @@ Sets a **DataAbilityPredicates** object to specify the start position of the ret
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.equalTo("NAME", "Rose").offsetAs(3)
predicates.equalTo("NAME", "Rose").offsetAs(3)
``` ```
...@@ -726,8 +697,7 @@ Sets a **DataAbilityPredicates** object to group rows that have the same value i ...@@ -726,8 +697,7 @@ Sets a **DataAbilityPredicates** object to group rows that have the same value i
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.groupBy(["AGE", "NAME"])
predicates.groupBy(["AGE", "NAME"])
``` ```
### indexedBy ### indexedBy
...@@ -751,8 +721,7 @@ Sets a **DataAbilityPredicates** object to specify the index column. ...@@ -751,8 +721,7 @@ Sets a **DataAbilityPredicates** object to specify the index column.
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.indexedBy("SALARY_INDEX")
predicates.indexedBy("SALARY_INDEX")
``` ```
...@@ -762,7 +731,7 @@ Sets a **DataAbilityPredicates** object to specify the index column. ...@@ -762,7 +731,7 @@ Sets a **DataAbilityPredicates** object to specify the index column.
in(field: string, value: Array&lt;ValueType&gt;): DataAbilityPredicates in(field: string, value: Array&lt;ValueType&gt;): DataAbilityPredicates
Sets a **DataAbilityPredicates** object to match the field with data type Array\<ValueType> and value within the specified range. Sets a **DataAbilityPredicates** object to match the field with data type Array<ValueType> and value within the specified range.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
...@@ -780,8 +749,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\ ...@@ -780,8 +749,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.in("AGE", [18, 20])
predicates.in("AGE", [18, 20])
``` ```
...@@ -791,7 +759,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\ ...@@ -791,7 +759,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\
notIn(field: string, value: Array&lt;ValueType&gt;): DataAbilityPredicates notIn(field: string, value: Array&lt;ValueType&gt;): DataAbilityPredicates
Sets a **DataAbilityPredicates** object to match the field with data type Array\<ValueType> and value out of the specified range. Sets a **DataAbilityPredicates** object to match the field with data type Array<ValueType> and value out of the specified range.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
...@@ -809,8 +777,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\ ...@@ -809,8 +777,7 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array\
**Example** **Example**
```js ```js
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") dataAbilityPredicates.notIn("NAME", ["Lisa", "Rose"])
predicates.notIn("NAME", ["Lisa", "Rose"])
``` ```
## ValueType ## ValueType
......
# Distributed Data Object # Distributed Data Object
Provides basic data object management, including creating, querying, deleting, modifying, and subscribing to data objects, and distributed data object collaboration for the same application among multiple devices.
> **NOTE**<br/> > **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.
...@@ -31,14 +34,14 @@ Creates a distributed data object. ...@@ -31,14 +34,14 @@ Creates a distributed data object.
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
// Create a distributed data object, which contains attributes of four types, namely, string, number, boolean, and object. // Create a distributed data object, which contains attributes of four types, namely, string, number, boolean, and object.
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,
parent:{mother:"jack mom",father:"jack Dad"}}); parent:{mother:"jack mom",father:"jack Dad"}});
``` ```
## distributedObject.genSessionId() ## distributedObject.genSessionId
genSessionId(): string genSessionId(): string
...@@ -53,7 +56,7 @@ Creates a random session ID. ...@@ -53,7 +56,7 @@ Creates a random session ID.
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
var sessionId = distributedObject.genSessionId(); var sessionId = distributedObject.genSessionId();
``` ```
...@@ -85,7 +88,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo ...@@ -85,7 +88,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,
parent:{mother:"jack mom",father:"jack Dad"}}); parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network. // Add g_object to the distributed network.
...@@ -110,19 +113,19 @@ Subscribes to the changes of this distributed data object. ...@@ -110,19 +113,19 @@ Subscribes to the changes of this distributed data object.
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback used to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.| | callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback used to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
parent:{mother:"jack mom",father:"jack Dad"}}); globalThis.changeCallback = (sessionId, changeData) => {
g_object.on("change", function (sessionId, changeData) { console.info("change" + sessionId);
console.info("change" + sessionId); if (changeData != null && changeData != undefined) {
if (changeData != null && changeData != undefined) { changeData.forEach(element => {
changeData.forEach(element => { console.info("changed !" + element + " " + g_object[element]);
console.info("changed !" + element + " " + g_object[element]); });
}); }
} }
}); g_object.on("change", globalThis.changeCallback);
``` ```
### off('change') ### off('change')
...@@ -136,24 +139,18 @@ Unsubscribes from the changes of this distributed data object. ...@@ -136,24 +139,18 @@ Unsubscribes from the changes of this distributed data object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| | type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback used to return the changes of the distributed data object. If this parameter is not specified, this API unsubscribes from all callbacks for data changes of this distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.| | callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback to be unregistered. If this parameter is not specified, all data change callbacks of the object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
parent:{mother:"jack mom",father:"jack Dad"}}); // Unregister the specified data change callback.
g_object.on("change", function (sessionId, changeData) { g_object.off("change", globalThis.changeCallback);
console.info("change" + sessionId); // Unregister all data change callbacks.
}); g_object.off("change");
// Unsubscribe from the specified data change callback for the distributed data object. ```
g_object.off("change", function (sessionId, changeData) {
console.info("change" + sessionId);
});
// Unsubscribe from all data change callbacks for the distributed data object.
g_object.off("change");
```
### on('status') ### on('status')
...@@ -170,14 +167,14 @@ Subscribes to the status change (online or offline) of this distributed data obj ...@@ -170,14 +167,14 @@ Subscribes to the status change (online or offline) of this distributed data obj
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the network ID of the device.<br>**status** indicates the status, which can be online or offline.| | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the network ID of the device.<br>**status** indicates the status, which can be online or offline.|
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, globalThis.statusCallback = (sessionId, networkId, status) => {
parent:{mother:"jack mom",father:"jack Dad"}}); globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
g_object.on("status", function (sessionId, networkid, status) { }
this.response += "status changed " + sessionId + " " + status + " " + networkId; var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
}); g_object.on("status", globalThis.statusCallback);
``` ```
### off('status') ### off('status')
...@@ -196,15 +193,14 @@ Unsubscribes from the status change (online or offline) of this distributed data ...@@ -196,15 +193,14 @@ Unsubscribes from the status change (online or offline) of this distributed data
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject' import distributedObject from '@ohos.data.distributedDataObject';
g_object.on("status", function (sessionId, networkId, status) { var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
this.response += "status changed " + sessionId + " " + status + " " + networkId; globalThis.statusCallback = (sessionId, networkId, status) => {
}); globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
// Unsubscribe from the specified status change callback for the distributed data object. }
g_object.off("status", function (sessionId, networkId, status) { // Unsubscribe from the specified status change callback for the distributed data object.
this.response += "status changed " + sessionId + " " + status + " " + networkId; g_object.off("status",globalThis.statusCallback);
}); // Unsubscribe from all status change callbacks for the distributed data object.
// Unsubscribe from all status change callbacks for the distributed data object. g_object.off("status");
g_object.off("status"); ```
```
...@@ -6,14 +6,12 @@ Lightweight storage provides applications with data processing capability and al ...@@ -6,14 +6,12 @@ Lightweight storage provides applications with data processing capability and al
> **NOTE**<br/> > **NOTE**<br/>
> >
> The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import ## Modules to Import
```js ```js
import dataStorage from '@ohos.data.storage'; import data_storage from '@ohos.data.storage';
``` ```
## Constants ## Constants
...@@ -26,7 +24,7 @@ import dataStorage from '@ohos.data.storage'; ...@@ -26,7 +24,7 @@ import dataStorage from '@ohos.data.storage';
| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It must be less than 8192 bytes.| | MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It must be less than 8192 bytes.|
## dataStorage.getStorageSync ## data_storage.getStorageSync
getStorageSync(path: string): Storage getStorageSync(path: string): Storage
...@@ -46,24 +44,17 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -46,24 +44,17 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Example** **Example**
```js ```js
import dataStorage from '@ohos.data.storage' import data_storage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var path = '/data/storage/el2/database/test_storage'
let storage = data_storage.getStorageSync(path + '/mystore')
storage.putSync('startup', 'auto')
storage.flushSync()
var context = featureAbility.getContext()
context.getFilesDir((err, path) => {
if (err) {
console.error('getFilesDir failed. err: ' + JSON.stringify(err));
return;
}
console.info('getFilesDir successful. path:' + JSON.stringify(path));
let storage = dataStorage.getStorageSync(path + '/mystore')
storage.putSync('startup', 'auto')
storage.flushSync()
});
``` ```
## dataStorage.getStorage ## data_storage.getStorage
getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
...@@ -79,29 +70,21 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -79,29 +70,21 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Example** **Example**
```js ```js
import dataStorage from '@ohos.data.storage' import data_storage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext() var path = '/data/storage/el2/database/test_storage'
context.getFilesDir((err, path) => { data_storage.getStorage(path + '/mystore', function (err, storage) {
if (err) { if (err) {
console.error('getFilesDir failed. err: ' + JSON.stringify(err)); console.info("Get the storage failed, path: " + path + '/mystore')
return; return;
} }
console.info('getFilesDir successful. path:' + JSON.stringify(path)); storage.putSync('startup', 'auto')
dataStorage.getStorage(path + '/mystore', function (err, storage) { storage.flushSync()
if (err) { })
console.info("Get the storage failed, path: " + path + '/mystore')
return;
}
storage.putSync('startup', 'auto')
storage.flushSync()
})
});
``` ```
## dataStorage.getStorage ## data_storage.getStorage
getStorage(path: string): Promise&lt;Storage&gt; getStorage(path: string): Promise&lt;Storage&gt;
...@@ -121,28 +104,21 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -121,28 +104,21 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Example** **Example**
```js ```js
import dataStorage from '@ohos.data.storage' import data_storage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext() var path = '/data/storage/el2/database/test_storage'
context.getFilesDir((err, path) => {
if (err) { let getPromise = data_storage.getStorage(path + '/mystore')
console.info("Get the storage failed, path: " + path + '/mystore') getPromise.then((storage) => {
return; storage.putSync('startup', 'auto')
} storage.flushSync()
console.info('getFilesDir successful. path:' + JSON.stringify(path)); }).catch((err) => {
let promisegetSt = dataStorage.getStorage(path + '/mystore') console.info("Get the storage failed, path: " + path + '/mystore')
promisegetSt.then((storage) => { })
storage.putSync('startup', 'auto')
storage.flushSync()
}).catch((err) => {
console.info("Get the storage failed, path: " + path + '/mystore')
})
});
``` ```
## dataStorage.deleteStorageSync ## data_storage.deleteStorageSync
deleteStorageSync(path: string): void deleteStorageSync(path: string): void
...@@ -157,11 +133,11 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -157,11 +133,11 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Example** **Example**
```js ```js
dataStorage.deleteStorageSync(path + '/mystore') data_storage.deleteStorageSync(path + '/mystore')
``` ```
## dataStorage.deleteStorage ## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -177,7 +153,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -177,7 +153,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Example** **Example**
```js ```js
dataStorage.deleteStorage(path + '/mystore', function (err) { data_storage.deleteStorage(path + '/mystore', function (err) {
if (err) { if (err) {
console.info("Deleted failed with err: " + err) console.info("Deleted failed with err: " + err)
return return
...@@ -187,7 +163,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -187,7 +163,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
``` ```
## dataStorage.deleteStorage ## data_storage.deleteStorage
deleteStorage(path: string): Promise&lt;void&gt; deleteStorage(path: string): Promise&lt;void&gt;
...@@ -207,7 +183,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -207,7 +183,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Example** **Example**
```js ```js
let promisedelSt = dataStorage.deleteStorage(path + '/mystore') let promisedelSt = data_storage.deleteStorage(path + '/mystore')
promisedelSt.then(() => { promisedelSt.then(() => {
console.info("Deleted successfully.") console.info("Deleted successfully.")
}).catch((err) => { }).catch((err) => {
...@@ -216,7 +192,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -216,7 +192,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
``` ```
## dataStorage.removeStorageFromCacheSync ## data_storage.removeStorageFromCacheSync
removeStorageFromCacheSync(path: string): void removeStorageFromCacheSync(path: string): void
...@@ -231,11 +207,11 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -231,11 +207,11 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Example** **Example**
```js ```js
dataStorage.removeStorageFromCacheSync(path + '/mystore') data_storage.removeStorageFromCacheSync(path + '/mystore')
``` ```
## dataStorage.removeStorageFromCache ## data_storage.removeStorageFromCache
removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -251,7 +227,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -251,7 +227,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Example** **Example**
```js ```js
dataStorage.removeStorageFromCache(path + '/mystore', function (err) { data_storage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) { if (err) {
console.info("Removed storage from cache failed with err: " + err) console.info("Removed storage from cache failed with err: " + err)
return return
...@@ -261,7 +237,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -261,7 +237,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
``` ```
## dataStorage.removeStorageFromCache ## data_storage.removeStorageFromCache
removeStorageFromCache(path: string): Promise&lt;void&gt; removeStorageFromCache(path: string): Promise&lt;void&gt;
...@@ -281,7 +257,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -281,7 +257,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Example** **Example**
```js ```js
let promiserevSt = dataStorage.removeStorageFromCache(path + '/mystore') let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => { promiserevSt.then(() => {
console.info("Removed storage from cache successfully.") console.info("Removed storage from cache successfully.")
}).catch((err) => { }).catch((err) => {
......
# DataAbilityHelper Module (JavaScript SDK APIs) # DataAbilityHelper
> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE** > **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
...@@ -553,7 +554,7 @@ DAHelper.insert( ...@@ -553,7 +554,7 @@ DAHelper.insert(
## DataAbilityHelper.batchInsert ## DataAbilityHelper.batchInsert
batchInsert(uri: string, valuesBuckets: Array\<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void
Inserts multiple data records into the database. This API uses an asynchronous callback to return the result. Inserts multiple data records into the database. This API uses an asynchronous callback to return the result.
...@@ -881,7 +882,7 @@ Calls the extended API of the Data ability. This API uses a promise to return th ...@@ -881,7 +882,7 @@ Calls the extended API of the Data ability. This API uses a promise to return th
| Type| Description| | Type| Description|
|------ | ------- | |------ | ------- |
|Promise<[PacMap](#pacmap)> | Promise used to return the result.| |Promise\<[PacMap](#pacmap)> | Promise used to return the result.|
**Example** **Example**
......
# EventHub # EventHub
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements event subscription, unsubscription, and triggering. Implements event subscription, unsubscription, and triggering.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Usage ## Usage
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance. Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
```js ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -34,10 +38,10 @@ Subscribes to an event. ...@@ -34,10 +38,10 @@ Subscribes to an event.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| callback | Function | Yes| Callback invoked when the event is triggered.| | callback | Function | Yes| Callback invoked when the event is triggered.|
**Example** **Example**
...@@ -72,10 +76,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes ...@@ -72,10 +76,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.| | callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.|
**Example** **Example**
...@@ -110,10 +114,10 @@ Triggers an event. ...@@ -110,10 +114,10 @@ Triggers an event.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.| | ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
**Example** **Example**
......
# ExtensionAbilityInfo # ExtensionAbilityInfo
> **NOTE**<br/> > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. API version 9 is a canary version for trial use. The APIs of this version may be unstable. > The initial APIs of this module are supported since API version 9. API version 9 is a canary version for trial use. The APIs of this version may be unstable.
## Modules to Import
```js
import bundle from "@ohos.bundle";
```
## AbilityInfo ## AbilityInfo
Provides the ability information. Provides the ability information.
......
# ExtensionRunningInfo # ExtensionRunningInfo
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> 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.
Provides extension running information. Provides extension running information.
## Modules to Import
```js
import abilitymanager from '@ohos.application.abilityManager';
```
## Usage ## Usage
The extension running information is obtained through an **abilityManager** instance. The extension running information is obtained through an **abilityManager** instance.
```js
```
import abilitymanager from '@ohos.application.abilityManager'; import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => { abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data)); console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
...@@ -43,15 +47,15 @@ Enumerates extension types. ...@@ -43,15 +47,15 @@ Enumerates extension types.
**System capability**: SystemCapability.BundleManager.BundleFramework **System capability**: SystemCapability.BundleManager.BundleFramework
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| FORM | 0 | Extension information of the form type.< | | FORM | 0 | Extension information of the form type.< |
| WORK_SCHEDULER | 1 | Extension information of the work scheduler type.< | | WORK_SCHEDULER | 1 | Extension information of the work scheduler type.< |
| INPUT_METHOD | 2 | Extension information of the input method type.< | | INPUT_METHOD | 2 | Extension information of the input method type.< |
| SERVICE | 3 | Extension information of the service type.< | | SERVICE | 3 | Extension information of the service type.< |
| ACCESSIBILITY | 4 | Extension information of the accessibility type.< | | ACCESSIBILITY | 4 | Extension information of the accessibility type.< |
| DATA_SHARE | 5 | Extension information of the data share type.< | | DATA_SHARE | 5 | Extension information of the data share type.< |
| FILE_SHARE | 6 | Extension information of the file share type.< | | FILE_SHARE | 6 | Extension information of the file share type.< |
| STATIC_SUBSCRIBER | 7 | Extension information of the static subscriber type.< | | STATIC_SUBSCRIBER | 7 | Extension information of the static subscriber type.< |
| WALLPAPER | 8 | Extension information of the wallpaper type.< | | WALLPAPER | 8 | Extension information of the wallpaper type.< |
| UNSPECIFIED | 9 | Extension information of the unspecified type.< | | UNSPECIFIED | 9 | Extension information of the unspecified type.< |
...@@ -63,13 +63,19 @@ Obtains information about the root album or directory in asynchronous mode. This ...@@ -63,13 +63,19 @@ Obtains information about the root album or directory in asynchronous mode. This
- Example - Example
```js ```js
filemanager.getRoot((err, fileInfo) => { let option = {
"dev":{
name:"",
}
};
filemanager.getRoot(option,(err, fileInfo)=>{
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) { for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo)); console.log("file:"+JSON.stringify(fileInfo));
} }
} }
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
...@@ -105,7 +111,7 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -105,7 +111,7 @@ Obtains information about the second-level album or files in asynchronous mode.
```js ```js
// Obtain all files in the directory. // Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri let media_path = file.path
filemanager.listFile(media_path, "file") filemanager.listFile(media_path, "file")
.then((fileInfo) => { .then((fileInfo) => {
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
...@@ -114,10 +120,13 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -114,10 +120,13 @@ Obtains information about the second-level album or files in asynchronous mode.
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err)
}); console.log(err)
});
``` ```
## filemanager.listFile ## filemanager.listFile
listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback&lt;FileInfo[]&gt;) : void listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback&lt;FileInfo[]&gt;) : void
...@@ -130,8 +139,8 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -130,8 +139,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. | | path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error - Error
...@@ -145,14 +154,30 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -145,14 +154,30 @@ Obtains information about the second-level album or files in asynchronous mode.
- Example - Example
```js ```js
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file path.
let media_path = file.uri let fileInfos = await filemanager.getRoot();
filemanager.listFile(media_path, "file", (err, fileInfo) => { let media_path = "";
if(Array.isArray(fileInfo)) { for (let i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { if (fileInfos[i].name == "image_album") {
console.log("file:"+JSON.stringify(fileInfo)); media_path = fileInfos[i].path;
} } else if (fileInfos[i].name == "audio_album") {
} media_path = fileInfos[i].path;
} else if (fileInfos[i].name == "video_album") {
media_path = fileInfos[i].path;
} else if (fileInfos[i].name == "file_folder") {
media_path = fileInfos[i].path;
}
}
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
}).catch((err) => {
console.log(err)
}); });
``` ```
...@@ -211,8 +236,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb ...@@ -211,8 +236,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. | | filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. | | path | string | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
...@@ -230,7 +255,7 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb ...@@ -230,7 +255,7 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
```js ```js
// Create a file. // Create a file.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri let media_path = file.path
// File to be saved. // File to be saved.
let name = "xxx.jpg" let name = "xxx.jpg"
filemanager.createFile(media_path, name, (err, uri) => { filemanager.createFile(media_path, name, (err, uri) => {
......
# FormExtensionContext # FormExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> 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.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**. Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
## Modules to Import
```js
import FormExtension from "@ohos.application.FormExtension";
```
## FormExtensionContext.updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
......
# FormHost # FormHost
> **NOTE**<br/> > **NOTE**
>
> 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.
Provides APIs related to the widget host. Provides APIs related to the widget host.
......
# FormProvider # FormProvider
> **NOTE**<br> > **NOTE**
>
> 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.
Provides APIs related to the widget provider. Provides APIs related to the widget provider.
...@@ -27,11 +28,11 @@ SystemCapability.Ability.Form ...@@ -27,11 +28,11 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------- | | ------ | ------ | ---- | ------------------------------------- |
| formId | string | Yes | ID of a widget. | | formId | string | Yes | ID of a widget. |
| minute | number | Yes | Refresh interval, in minutes. The value must be greater than or equal to 5. | | minute | number | Yes | Refresh interval, in minutes. The value must be greater than or equal to 5. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -56,16 +57,16 @@ SystemCapability.Ability.Form ...@@ -56,16 +57,16 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------- | | ------ | ------ | ---- | ------------------------------------- |
| formId | string | Yes | ID of a widget. | | formId | string | Yes | ID of a widget. |
| minute | number | Yes | Refresh interval, in minutes. The value must be greater than or equal to 5. | | minute | number | Yes | Refresh interval, in minutes. The value must be greater than or equal to 5. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------------------------------- | | ------------- | ---------------------------------- |
| Promise\<void> |Promise used to return the result. | | Promise\<void> |Promise used to return the result. |
**Example** **Example**
...@@ -80,7 +81,7 @@ SystemCapability.Ability.Form ...@@ -80,7 +81,7 @@ SystemCapability.Ability.Form
## updateForm ## updateForm
updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback&lt;void&gt;): void; updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback&lt;void&gt;): void;
Updates a widget. This API uses an asynchronous callback to return the result. Updates a widget. This API uses an asynchronous callback to return the result.
...@@ -90,11 +91,11 @@ SystemCapability.Ability.Form ...@@ -90,11 +91,11 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- | | ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string | Yes | ID of the widget to update.| | formId | string | Yes | ID of the widget to update.|
| formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | Data to be used for the update. | | formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | Data to be used for the update. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -111,7 +112,7 @@ SystemCapability.Ability.Form ...@@ -111,7 +112,7 @@ SystemCapability.Ability.Form
## updateForm ## updateForm
updateForm(formId: string, formBindingData: FormBindingData): Promise&lt;void&gt;; updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise&lt;void&gt;;
Updates a widget. This API uses a promise to return the result. Updates a widget. This API uses a promise to return the result.
...@@ -121,10 +122,10 @@ SystemCapability.Ability.Form ...@@ -121,10 +122,10 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- | | ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string | Yes | ID of the widget to update.| | formId | string | Yes | ID of the widget to update.|
| formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | Data to be used for the update. | | formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | Data to be used for the update. |
**Return value** **Return value**
......
# HiLog # HiLog
The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs. The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs.
This document describes only API functions. For details about log printing requirements, see [Logging Guide](../../../contribute/OpenHarmony-Log-guide.md).
> **NOTE**<br> > **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.
...@@ -42,7 +41,7 @@ hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO); ...@@ -42,7 +41,7 @@ hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO);
## LogLevel ## LogLevel
Log level. Enumerates the log levels.
**System capability**: SystemCapability.HiviewDFX.HiLog **System capability**: SystemCapability.HiviewDFX.HiLog
...@@ -70,7 +69,7 @@ DEBUG logs are not recorded in official versions by default. They are available ...@@ -70,7 +69,7 @@ DEBUG logs are not recorded in official versions by default. They are available
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -101,7 +100,7 @@ Prints INFO logs. ...@@ -101,7 +100,7 @@ Prints INFO logs.
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -132,7 +131,7 @@ Prints WARN logs. ...@@ -132,7 +131,7 @@ Prints WARN logs.
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -163,7 +162,7 @@ Prints ERROR logs. ...@@ -163,7 +162,7 @@ Prints ERROR logs.
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -194,7 +193,7 @@ Prints FATAL logs. ...@@ -194,7 +193,7 @@ Prints FATAL logs.
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by \<private>.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
......
...@@ -34,19 +34,9 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to ...@@ -34,19 +34,9 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to
**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
...@@ -61,22 +51,14 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu ...@@ -61,22 +51,14 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
| Parameter | Description | | Parameter | Description |
| ---------------------- | ------------------ | | ---------------------- | ------------------ |
| Promise<Array\<number>> | Promise used to return the result.| | Promise\<Array\<number>> | 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));
});
}
}
``` ```
...@@ -101,23 +83,10 @@ Obtains the information about an input device. This API uses an asynchronous cal ...@@ -101,23 +83,10 @@ Obtains the information about an input device. This API uses an asynchronous cal
**Example** **Example**
```js ```js
export default { // This example obtains the information about the device whose ID is 1.
InputDeviceData: { inputDevice.getDevice(1, (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.getDevice
...@@ -137,24 +106,10 @@ Obtains the information about an input device. This API uses a promise to return ...@@ -137,24 +106,10 @@ Obtains the information about an input device. This API uses a promise to return
**Example** **Example**
```js ```js
export default { // This example obtains the information about 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,
},
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));
});
}
}
``` ```
...@@ -191,7 +146,7 @@ Defines the axis information of an input device. ...@@ -191,7 +146,7 @@ Defines the axis information of an input device.
| 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 reported by the axis. |
| min | number | Minimum value reported by the axis. | | min | number | Minimum value reported by the axis. |
......
# Input Method Framework # Input Method Framework
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> >
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
import inputMethod from '@ohos.inputMethod'; import inputMethod from '@ohos.inputMethod';
``` ```
## inputMethod<sup>8+</sup> ## inputMethod<sup>6+</sup>
Provides the constants. Provides the constants.
...@@ -21,7 +21,7 @@ Provides the constants. ...@@ -21,7 +21,7 @@ Provides the constants.
| MAX_TYPE_NUM | number | Yes| No| Maximum number of supported input methods.| | MAX_TYPE_NUM | number | Yes| No| Maximum number of supported input methods.|
## InputMethodProperty<sup>8+</sup><a name="InputMethodProperty"></a> ## InputMethodProperty<sup>6+</sup><a name="InputMethodProperty"></a>
Describes the input method application attributes. Describes the input method application attributes.
...@@ -48,11 +48,11 @@ Obtains an [InputMethodController](#InputMethodController) instance. ...@@ -48,11 +48,11 @@ Obtains an [InputMethodController](#InputMethodController) instance.
**Example** **Example**
``` ```js
var InputMethodController = inputMethod.getInputMethodController(); var InputMethodController = inputMethod.getInputMethodController();
``` ```
## inputMethod.getInputMethodSetting<sup>8+</sup><a name="getInputMethodSetting"></a> ## inputMethod.getInputMethodSetting<sup>6+</sup><a name="getInputMethodSetting"></a>
getInputMethodSetting(): InputMethodSetting getInputMethodSetting(): InputMethodSetting
...@@ -120,7 +120,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -120,7 +120,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
console.info('stopInput isSuccess = ' + isSuccess); console.info('stopInput isSuccess = ' + isSuccess);
``` ```
## InputMethodSetting<sup>8+</sup><a name="InputMethodSetting"></a> ## InputMethodSetting<sup>6+</sup><a name="InputMethodSetting"></a>
In the following API examples, you must first use [getInputMethodSetting](#getInputMethodSetting) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use [getInputMethodSetting](#getInputMethodSetting) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance.
...@@ -140,14 +140,14 @@ Obtains the list of installed input methods. This API uses an asynchronous callb ...@@ -140,14 +140,14 @@ Obtains the list of installed input methods. This API uses an asynchronous callb
**Example** **Example**
```js ```js
InputMethodSetting.listInputMethod((properties)=>{ InputMethodSetting.listInputMethod((properties)=>{
for (var i = 0;i < properties.length; i++) { for (var i = 0;i < properties.length; i++) {
var property = properties[i]; var property = properties[i];
console.info(property.packageName + "/" + property.methodId); console.info(property.packageName + "/" + property.methodId);
} }
}); });
``` ```
### listInputMethod ### listInputMethod
......
...@@ -120,7 +120,7 @@ Creates an **AudioRecorder** instance to control audio recording. ...@@ -120,7 +120,7 @@ Creates an **AudioRecorder** instance to control audio recording.
**Example** **Example**
```js ```js
let audiorecorder = media.createAudioRecorder(); let audioRecorder = media.createAudioRecorder();
``` ```
## media.createVideoRecorder<sup>9+</sup> ## media.createVideoRecorder<sup>9+</sup>
......
# Media Library Management # MediaLibrary
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
......
# 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.
## Modules to Import ## Modules to Import
``` ```js
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
``` ```
...@@ -22,19 +23,19 @@ matchMediaSync(condition: string): MediaQueryListener ...@@ -22,19 +23,19 @@ 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 **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | --------- | ------ | ---- | ---------- |
| condition | string | Yes| Matching condition of a media event.| | condition | string | Yes | Matching condition of a media event.|
- Return value **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------ | ---------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.| | MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.|
- Example **Example**
``` ```js
listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
``` ```
...@@ -45,10 +46,10 @@ Media query handle, including the first query result when the handle is applied ...@@ -45,10 +46,10 @@ Media query handle, including the first query result when the handle is applied
### 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 +58,13 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void ...@@ -57,13 +58,13 @@ 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 **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------------------------------- | ---- | ---------------- |
| type | string | Yes| Must enter the string **change**.| | type | string | Yes | Must enter the string **change**.|
| callback | Callback&lt;MediaQueryResult&gt; | Yes| Callback registered with media query.| | 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).
...@@ -72,14 +73,14 @@ Registers a callback with the corresponding query condition by using the handle. ...@@ -72,14 +73,14 @@ 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. Unregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------------------------------- | ---- | ----------------------------- |
| type | boolean | Yes| Must enter the string **change**.| | type | boolean | Yes | Must enter the string **change**. |
| callback | Callback&lt;MediaQueryResult&gt; | No| Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.| | callback | Callback&lt;MediaQueryResult&gt; | No | Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.|
- Example **Example**
``` ```js
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
...@@ -90,8 +91,8 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -90,8 +91,8 @@ Unregisters a callback with the corresponding query condition by using the handl
// do something here // do something here
} }
} }
this.listener.on('change', this.onPortrait) // Registration callback. listener.on('change', onPortrait) // Register a callback.
this.listener.off('change', this.onPortrait) // Deregistration callback. listener.off('change', onPortrait) // Unregister a callback.
``` ```
...@@ -100,15 +101,15 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -100,15 +101,15 @@ 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
``` ```js
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
let portraitFunc = null let portraitFunc = null
......
# missionManager # missionManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> 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.
...@@ -26,15 +27,15 @@ Registers a listener to observe the mission status. ...@@ -26,15 +27,15 @@ Registers a listener to observe the mission status.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| listener | MissionListener | Yes| Listener to register.| | listener | MissionListener | Yes| Listener to register.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Returns the index of the listener, which is created by the system and allocated when the mission status listener is registered. Each listener has a unique index.| | number | Returns the unique index of the mission status listener, which is created by the system and allocated when the listener is registered.|
**Example** **Example**
...@@ -55,16 +56,16 @@ Registers a listener to observe the mission status. ...@@ -55,16 +56,16 @@ Registers a listener to observe the mission status.
unregisterMissionListener(listenerId: number, callback: AsyncCallback&lt;void&gt;): void; unregisterMissionListener(listenerId: number, callback: AsyncCallback&lt;void&gt;): void;
Unregisters a mission status listener. This API uses an asynchronous callback to return the result. Deregisters a mission status listener. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| listenerId | number | Yes| Index of the mission status listener to unregister. Each listener has a unique index, which is returned by **registerMissionListener**.| | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -88,21 +89,21 @@ Unregisters a mission status listener. This API uses an asynchronous callback to ...@@ -88,21 +89,21 @@ Unregisters a mission status listener. This API uses an asynchronous callback to
unregisterMissionListener(listenerId: number): Promise&lt;void&gt;; unregisterMissionListener(listenerId: number): Promise&lt;void&gt;;
Unregisters a mission status listener. This API uses a promise to return the result. Deregisters a mission status listener. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| listenerId | number | Yes| Index of the mission status listener to unregister. Each listener has a unique index, which is returned by **registerMissionListener**.| | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -126,17 +127,17 @@ Unregisters a mission status listener. This API uses a promise to return the res ...@@ -126,17 +127,17 @@ Unregisters a mission status listener. This API uses a promise to return the res
getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;MissionInfo&gt;): void; getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;MissionInfo&gt;): void;
Obtains the information of a given mission. This API uses an asynchronous callback to return the result. Obtains the information about a given mission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;[MissionInfo](#missioninfo)&gt; | Yes| Callback used to return the mission information obtained.| | callback | AsyncCallback&lt;[MissionInfo](#missioninfo)&gt; | Yes| Callback used to return the mission information obtained.|
**Example** **Example**
...@@ -159,22 +160,22 @@ Obtains the information of a given mission. This API uses an asynchronous callba ...@@ -159,22 +160,22 @@ Obtains the information of a given mission. This API uses an asynchronous callba
getMissionInfo(deviceId: string, missionId: number): Promise&lt;MissionInfo&gt;; getMissionInfo(deviceId: string, missionId: number): Promise&lt;MissionInfo&gt;;
Obtains the information of a given mission. This API uses a promise to return the result. Obtains the information about a given mission. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[MissionInfo](#missioninfo)&gt; | Promise used to return the mission information obtained.| | Promise&lt;[MissionInfo](#missioninfo)&gt; | Promise used to return the mission information obtained.|
**Example** **Example**
...@@ -191,17 +192,17 @@ Obtains the information of a given mission. This API uses a promise to return th ...@@ -191,17 +192,17 @@ Obtains the information of a given mission. This API uses a promise to return th
getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback&lt;Array&lt;MissionInfo&gt;&gt;): void; getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback&lt;Array&lt;MissionInfo&gt;&gt;): void;
Obtains information of all missions. This API uses an asynchronous callback to return the result. Obtains information about all missions. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| numMax | number | Yes| Maximum number of missions whose information can be obtained.| | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
| callback | AsyncCallback&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Yes| Callback used to return the array of mission information obtained.| | callback | AsyncCallback&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Yes| Callback used to return the array of mission information obtained.|
**Example** **Example**
...@@ -220,22 +221,22 @@ Obtains information of all missions. This API uses an asynchronous callback to r ...@@ -220,22 +221,22 @@ Obtains information of all missions. This API uses an asynchronous callback to r
getMissionInfos(deviceId: string, numMax: number): Promise&lt;Array&lt;MissionInfo&gt;&gt;; getMissionInfos(deviceId: string, numMax: number): Promise&lt;Array&lt;MissionInfo&gt;&gt;;
Obtains information of all missions. This API uses a promise to return the result. Obtains information about all missions. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| numMax | number | Yes| Maximum number of missions whose information can be obtained.| | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Promise used to return the array of mission information obtained.| | Promise&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Promise used to return the array of mission information obtained.|
**Example** **Example**
...@@ -258,11 +259,11 @@ Obtains the snapshot of a given mission. This API uses an asynchronous callback ...@@ -258,11 +259,11 @@ Obtains the snapshot of a given mission. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.| | callback | AsyncCallback&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|
**Example** **Example**
...@@ -293,16 +294,16 @@ Obtains the snapshot of a given mission. This API uses a promise to return the r ...@@ -293,16 +294,16 @@ Obtains the snapshot of a given mission. This API uses a promise to return the r
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.| | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.| | Promise&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|
**Example** **Example**
...@@ -331,10 +332,10 @@ Locks a given mission. This API uses an asynchronous callback to return the resu ...@@ -331,10 +332,10 @@ Locks a given mission. This API uses an asynchronous callback to return the resu
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -364,15 +365,15 @@ Locks a given mission. This API uses a promise to return the result. ...@@ -364,15 +365,15 @@ Locks a given mission. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -435,15 +436,15 @@ Unlocks a given mission. This API uses a promise to return the result. ...@@ -435,15 +436,15 @@ Unlocks a given mission. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -476,10 +477,10 @@ Clears a given mission, regardless of whether it is locked. This API uses an asy ...@@ -476,10 +477,10 @@ Clears a given mission, regardless of whether it is locked. This API uses an asy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -509,15 +510,15 @@ Clears a given mission, regardless of whether it is locked. This API uses a prom ...@@ -509,15 +510,15 @@ Clears a given mission, regardless of whether it is locked. This API uses a prom
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -566,9 +567,9 @@ Clears all unlocked missions. This API uses a promise to return the result. ...@@ -566,9 +567,9 @@ Clears all unlocked missions. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -590,10 +591,10 @@ Switches a given mission to the foreground. This API uses an asynchronous callba ...@@ -590,10 +591,10 @@ Switches a given mission to the foreground. This API uses an asynchronous callba
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -623,11 +624,11 @@ Switches a given mission to the foreground, with the startup parameters for the ...@@ -623,11 +624,11 @@ Switches a given mission to the foreground, with the startup parameters for the
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| options | StartOptions | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| | options | StartOptions | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -657,16 +658,16 @@ Switches a given mission to the foreground, with the startup parameters for the ...@@ -657,16 +658,16 @@ Switches a given mission to the foreground, with the startup parameters for the
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.| | missionId | number | Yes| Mission ID.|
| options | StartOptions | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| | options | StartOptions | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -684,20 +685,3 @@ Switches a given mission to the foreground, with the startup parameters for the ...@@ -684,20 +685,3 @@ Switches a given mission to the foreground, with the startup parameters for the
console.log(err); console.log(err);
}); });
``` ```
## MissionInfo
Describes the mission information.
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Yes| Mission ID.|
| runningState | number | Yes| Yes| Running state of the mission.|
| lockedState | boolean | Yes| Yes| Locked state of the mission.|
| timestamp | string | Yes| Yes| Latest time when the mission was created or updated.|
| want | [Want](js-apis-featureAbility.md#want) | Yes| Yes| **Want** information of the mission.|
| label | string | Yes| Yes| Label of the mission.|
| iconPath | string | Yes| Yes| Path of the mission icon.|
| continuable | boolean | Yes| Yes| Whether the mission is continuable.|
# PermissionRequestResult # PermissionRequestResult
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the permission request result. Provides the permission request result.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.| | permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. | | authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. |
# ProcessRunningInfo # ProcessRunningInfo
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> 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.
Provides process running information. Provides process running information.
## Modules to Import
```js
import appManager from '@ohos.application.appManager'
```
## Usage ## Usage
The process running information is obtained through an **appManager** instance. The process running information is obtained through an **appManager** instance.
```js ```js
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInfos((error,data) => { appManager.getProcessRunningInfos((error,data) => {
...@@ -26,9 +30,9 @@ appManager.getProcessRunningInfos((error,data) => { ...@@ -26,9 +30,9 @@ appManager.getProcessRunningInfos((error,data) => {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.| | bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.|
# Prompt # Prompt
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> 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.
## Modules to Import ## Modules to Import
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## Modules to Import ## Modules to Import
``` ```js
import radio from '@ohos.telephony.radio' import radio from '@ohos.telephony.radio'
``` ```
...@@ -30,7 +30,7 @@ Obtains the radio access technology (RAT) used by the CS and PS domains. This AP ...@@ -30,7 +30,7 @@ Obtains the radio access technology (RAT) used by the CS and PS domains. This AP
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getRadioTech(slotId, (err, data) =>{ radio.getRadioTech(slotId, (err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -62,7 +62,7 @@ Obtains the RAT used by the CS and PS domains. This API uses a promise to return ...@@ -62,7 +62,7 @@ Obtains the RAT used by the CS and PS domains. This API uses a promise to return
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getRadioTech(slotId); let promise = radio.getRadioTech(slotId);
promise.then(data => { promise.then(data => {
...@@ -91,7 +91,7 @@ Obtains the network status. This API uses an asynchronous callback to return the ...@@ -91,7 +91,7 @@ Obtains the network status. This API uses an asynchronous callback to return the
**Example** **Example**
``` ```js
radio.getNetworkState((err, data) =>{ radio.getNetworkState((err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
...@@ -117,7 +117,7 @@ Obtains the network status. This API uses an asynchronous callback to return the ...@@ -117,7 +117,7 @@ Obtains the network status. This API uses an asynchronous callback to return the
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getNetworkState(slotId, (err, data) => { radio.getNetworkState(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -149,7 +149,7 @@ Obtains the network status of the SIM card in the specified slot. This API uses ...@@ -149,7 +149,7 @@ Obtains the network status of the SIM card in the specified slot. This API uses
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getNetworkState(slotId); let promise = radio.getNetworkState(slotId);
promise.then(data => { promise.then(data => {
...@@ -177,7 +177,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A ...@@ -177,7 +177,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getNetworkSelectionMode(slotId, (err, data) => { radio.getNetworkSelectionMode(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -207,7 +207,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A ...@@ -207,7 +207,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getNetworkSelectionMode(slotId); let promise = radio.getNetworkSelectionMode(slotId);
promise.then(data => { promise.then(data => {
...@@ -235,7 +235,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci ...@@ -235,7 +235,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getISOCountryCodeForNetwork(slotId, (err, data) => { radio.getISOCountryCodeForNetwork(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -265,7 +265,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci ...@@ -265,7 +265,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getISOCountryCodeForNetwork(slotId); let promise = radio.getISOCountryCodeForNetwork(slotId);
promise.then(data => { promise.then(data => {
...@@ -292,7 +292,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a ...@@ -292,7 +292,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a
**Example** **Example**
``` ```js
radio.getPrimarySlotId((err, data) => { radio.getPrimarySlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
...@@ -315,7 +315,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a ...@@ -315,7 +315,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a
**Example** **Example**
``` ```js
let promise = radio.getPrimarySlotId(); let promise = radio.getPrimarySlotId();
promise.then(data => { promise.then(data => {
console.log(`getPrimarySlotId success, promise: data->${JSON.stringify(data)}`); console.log(`getPrimarySlotId success, promise: data->${JSON.stringify(data)}`);
...@@ -342,7 +342,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the ...@@ -342,7 +342,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getSignalInformation(slotId, (err, data) => { radio.getSignalInformation(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -372,7 +372,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the ...@@ -372,7 +372,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getSignalInformation(slotId); let promise = radio.getSignalInformation(slotId);
promise.then(data => { promise.then(data => {
...@@ -405,10 +405,10 @@ Checks whether the current device supports 5G \(NR\). ...@@ -405,10 +405,10 @@ Checks whether the current device supports 5G \(NR\).
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let result = radio.isNrSupported(slotId); let result = radio.isNrSupported(slotId);
console.log(result); console.log("Result: "+ result);
``` ```
...@@ -430,7 +430,7 @@ Checks whether the radio service is enabled on the primary SIM card. This API us ...@@ -430,7 +430,7 @@ Checks whether the radio service is enabled on the primary SIM card. This API us
**Example** **Example**
``` ```js
radio.isRadioOn((err, data) => { radio.isRadioOn((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
...@@ -456,7 +456,7 @@ Checks whether the radio service is enabled on the SIM card in the specified slo ...@@ -456,7 +456,7 @@ Checks whether the radio service is enabled on the SIM card in the specified slo
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.isRadioOn(slotId, (err, data) => { radio.isRadioOn(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -488,7 +488,7 @@ Checks whether the radio service is enabled. This API uses a promise to return t ...@@ -488,7 +488,7 @@ Checks whether the radio service is enabled. This API uses a promise to return t
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.isRadioOn(slotId); let promise = radio.isRadioOn(slotId);
promise.then(data => { promise.then(data => {
...@@ -516,7 +516,7 @@ Obtains the carrier name. This API uses an asynchronous callback to return the r ...@@ -516,7 +516,7 @@ Obtains the carrier name. This API uses an asynchronous callback to return the r
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
radio.getOperatorName(slotId, (err, data) => { radio.getOperatorName(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
...@@ -546,7 +546,7 @@ Obtains the carrier name. This API uses a promise to return the result. ...@@ -546,7 +546,7 @@ Obtains the carrier name. This API uses a promise to return the result.
**Example** **Example**
``` ```js
let slotId = 0; let slotId = 0;
let promise = radio.getOperatorName(slotId); let promise = radio.getOperatorName(slotId);
promise.then(data => { promise.then(data => {
......
...@@ -335,10 +335,10 @@ Removes this upload task. This API uses an asynchronous callback to return the r ...@@ -335,10 +335,10 @@ Removes this upload task. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| url | string | Yes | Resource URL. | | url | string | Yes | Resource URL. |
| header | object | No | HTTP or HTTPS header added to an upload request. | | header | object | Yes | HTTP or HTTPS header added to an upload request. |
| method | string | No | Request methods available: **POST** and **PUT**. The default value is **POST**. | | method | string | Yes | Request methods available: **POST** and **PUT**. The default value is **POST**. |
| files | Array&lt;[File](#file)&gt; | Yes | List of files to upload, which is submitted through **multipart/form-data**. | | files | Array&lt;[File](#file)&gt; | Yes | List of files to upload, which is submitted through **multipart/form-data**. |
| data | Array&lt;[RequestData](#requestdata)&gt; | No | Form data in the request body. | | data | Array&lt;[RequestData](#requestdata)&gt; | Yes | Form data in the request body. |
## File ## File
...@@ -349,7 +349,7 @@ Removes this upload task. This API uses an asynchronous callback to return the r ...@@ -349,7 +349,7 @@ Removes this upload task. This API uses an asynchronous callback to return the r
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| filename | string | No | File name in the header when **multipart** is used. | | filename | string | No | File name in the header when **multipart** is used. |
| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. | | name | string | No | Name of a form item when **multipart** is used. The default value is **file**. |
| uri | string | Yes | Local path for storing files.<br/>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. The following is an example:<br/>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br/>internal://cache/path/to/file.txt | | uri | string | Yes | Local path for storing files.<br/>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. Below are examples:<br>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br>internal://cache/path/to/file.txt |
| type | string | No | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. | | type | string | No | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. |
......
# statfs # statfs
> **NOTE**<br> > **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.
This module provides information related to the file system. It provides JS APIs to obtain the total number of bytes and the number of idle bytes of the file system. Obtains file system information, including the total number of bytes and the number of idle bytes of the file system.
## Modules to Import ## Modules to Import
```js ```js
import statfs from '@ohos.statfs'; import statfs from '@ohos.statfs';
``` ```
## Guidelines
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "xxx.txt";
```
## statfs.getFreeBytes ## statfs.getFreeBytes
getFreeBytes(path:string):Promise&lt;number&gt; getFreeBytes(path:string):Promise&lt;number&gt;
...@@ -72,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -72,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
- Example - Example
```js ```js
statfs.getFreeBytes(path, function(err, number){ import featureAbility from '@ohos.ability.featureAbility';
console.info("getFreeBytes callback successfully:"+ number); let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getFreeBytes(path, function(err, number){
console.info("getFreeBytes callback successfully:"+ number);
});
}); });
``` ```
...@@ -126,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -126,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m
- Example - Example
```js ```js
statfs.getTotalBytes(path, function(err, number){ import featureAbility from '@ohos.ability.featureAbility';
console.info("getTotalBytes callback successfully:"+ number); let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getTotalBytes(path, function(err, number){
console.info("getTotalBytes callback successfully:"+ number);
});
}); });
``` ```
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
An entrance piece that can contain images and text. It is usually used to display receivers, for example, email recipients or message recipients. An entrance piece that can contain images and text. It is usually used to display receivers, for example, email recipients or message recipients.
## Child Component ## Child Components
None None
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册