提交 d7492510 编写于 作者: S shawn_he 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into 7791-a

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
......@@ -85,6 +85,7 @@ zh-cn/device-dev/subsystems/subsys-security-sigverify.md @duangavin123_admin
zh-cn/device-dev/subsystems/subsys-security-rightmanagement.md @duangavin123_admin
zh-cn/device-dev/subsystems/subsys-security-communicationverify.md @duangavin123_admin
zh-cn/device-dev/subsystems/subsys-security-devicesecuritylevel.md @duangavin123_admin
zh-cn/device-dev/subsystems/subsys-security-huks-guide.md @Austin23
zh-cn/device-dev/subsystems/subsys-boot-appspawn.md @Austin23
zh-cn/device-dev/subsystems/subsys-boot-bootstrap.md @Austin23
zh-cn/device-dev/subsystems/subsys-boot-faqs.md @Austin23
......@@ -348,4 +349,6 @@ zh-cn/application-dev/napi/napi-guidelines.md @RayShih
zh-cn/application-dev/napi/drawing-guidelines.md @ge-yafang
zh-cn/application-dev/napi/rawfile-guidelines.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-buffer.md @zengyawen
zh-cn/application-dev/reference/js-service-widget-ui @HelloCrease
\ No newline at end of file
zh-cn/application-dev/reference/js-service-widget-ui @HelloCrease
zh-cn/application-dev/website.md @zengyawen
zh-cn/application-dev/faqs/ @zengyawen
\ No newline at end of file
......@@ -19,7 +19,7 @@ The table below describes the ability call APIs. For details, see [Ability](../r
|API|Description|
|:------|:------|
|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.|
|on(method: string, callback: CaleeCallBack): void|Callback invoked when the callee registers a method.|
|on(method: string, callback: CalleeCallBack): void|Callback invoked when the callee registers a method.|
|off(method: string): void|Callback invoked when the callee deregisters a method.|
|call(method: string, data: rpc.Sequenceable): Promise\<void>|Sends agreed sequenceable data to the callee.|
|callWithResult(method: string, data: rpc.Sequenceable): Promise\<rpc.MessageParcel>|Sends agreed sequenceable data to the callee and returns the agreed sequenceable data.|
......@@ -28,7 +28,7 @@ The table below describes the ability call APIs. For details, see [Ability](../r
## 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).
> 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.
### 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.
1. Configure the ability startup mode.
......
......@@ -17,7 +17,7 @@ Call **createDistributedObject()** to create a distributed data object instance.
**Table 1** API for creating a distributed data object instance
| Package| API| Description|
| -------- | -------- | -------- |
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>- **source**: attributes of the **distributedObject** set.<br>- **DistributedObject**: returns the distributed object created.|
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>- **source**: attributes of the **distributedObject** set.<br>- **DistributedObject**: returns the distributed object created.|
### Generating a Session ID
......@@ -35,16 +35,16 @@ Call **setSessionId()** to set a session ID for a distributed data object. The s
**Table 3** API for setting a session ID
| Class| API| Description|
| -------- | -------- | -------- |
| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.<br> **sessionId**: session ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.<br>**sessionId**: session ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
### Observing Data Changes
Call **on()** to subscribe to data changes of a distributed data object. When the data changes, a callback will be invoked to return the data changes. You can use **off()** to unsubscribe from the data changes.
**Table 4** APIs for observing data changes of a distributed data object
| Class| API| Description|
| Class| API| Description|
| -------- | -------- | -------- |
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.|
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.|
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes. **Callback**: specifies callback used to return changes of the distributed data object. If this parameter is not specified, all callbacks related to data changes will be unregistered.|
### Observing Online or Offline Status
......@@ -85,7 +85,11 @@ The following example shows how to implement a distributed data object synchroni
```js
import distributedObject from '@ohos.data.distributedDataObject';
```
2. Request the permission. <br>Add the required permission in the **config.json** file. The sample code is as follows:
2. Request the permission.
Add the required permission in the **config.json** file. The sample code is as follows:
```
{
"module": {
......@@ -97,10 +101,11 @@ The following example shows how to implement a distributed data object synchroni
}
}
```
This permission must also be authorized by the user through a dialog box when the application is started for the first time. The sample code is as follows:
```js
This permission must also be authorized by the user through a dialog box when the application is started for the first time. The sample code is as follows:
```
import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() {
console.info('grantPermission');
let context = featureAbility.getContext();
......@@ -108,11 +113,13 @@ The following example shows how to implement a distributed data object synchroni
console.info(`result.requestCode=${result.requestCode}`)
})
console.info('end grantPermission');
console.info('end grantPermission');
}
grantPermission();
```
3. Obtain a distributed data object instance.
The sample code is as follows:
......@@ -130,7 +137,7 @@ The following example shows how to implement a distributed data object synchroni
```js
// Local object
var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true,
parent:{mother:"jack mom",father:"jack Dad"},list:[{mother:"jack mom"}, {father:"jack Dad"}]});
parent:{mother:"jack mom", father:"jack Dad"}, list:[{mother:"jack mom"}, {father:"jack Dad"}]});
local_object.setSessionId(sessionId);
// Remote object
......@@ -140,8 +147,10 @@ The following example shows how to implement a distributed data object synchroni
// After learning that the device goes online, the remote object synchronizes data. That is, name changes to jack and age to 18.
```
5. Observe the data changes of the distributed data object. <br>You can subscribe to data changes of the peer object. When the data in the peer object changes, a callback will be called to return the data changes.
5. Observe the data changes of the distributed data object.
You can subscribe to data changes of the peer object. When the data in the peer object changes, a callback will be called to return the data changes.
The sample code is as follows:
```js
......@@ -152,26 +161,32 @@ The following example shows how to implement a distributed data object synchroni
changeData.forEach(element => {
console.info("changed !" + element + " " + local_object[element]);
});
}
}
}
// To refresh the page in changeCallback, correctly bind (this) to the changeCallback.
local_object.on("change", this.changeCallback.bind(this));
```
6. Modify object attributes. <br>The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types).
6. Modify object attributes.
The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types).
The sample code is as follows:
```js
local_object.name = "jack";
local_object.age = 19;
local_object.isVis = false;
local_object.parent = {mother:"jack mom",father:"jack Dad"};
local_object.parent = {mother:"jack mom", father:"jack Dad"};
local_object.list = [{mother:"jack mom"}, {father:"jack Dad"}];
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. Example:
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>
> For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified.
Example:
```js
// Supported modification.
local_object.parent = {mother:"mom", father:"dad"};
......@@ -179,13 +194,18 @@ The following example shows how to implement a distributed data object synchroni
local_object.parent.mother = "mom";
```
7. Access the distributed data object. <br>Obtain the distributed data object attribute, which is the latest data on the network.
7. Access the distributed data object.
Obtain the distributed data object attribute, which is the latest data on the network.
The sample code is as follows:
```js
console.info("name " + local_object["name"]);
```
8. Unsubscribe from data changes. <br>You can specify the callback to unregister. If you do not specify the callback, all data change callbacks of the distributed data object will be unregistered.
8. Unsubscribe from data changes.
You can specify the callback to unregister. If you do not specify the callback, all data change callbacks of the distributed data object will be unregistered.
The sample code is as follows:
```js
......@@ -194,6 +214,7 @@ The following example shows how to implement a distributed data object synchroni
// Unregister all data change callbacks.
local_object.off("change");
```
9. Subscribe to the status (online/offline) changes of the distributed data object. A callback will be invoked to report the status change when the target distributed data object goes online or offline.
The sample code is as follows:
```js
......@@ -207,58 +228,62 @@ The following example shows how to implement a distributed data object synchroni
10. Save a distributed data object and revoke the data saving operation.
- Callback
```js
// Save a distributed data object.
local_object.save("local", (result, data)=>{
console.log("save callback");
console.info("save sessionId " + data.sessionId);
console.info("save version " + data.version);
console.info("save deviceId " + data.deviceId);
});
// Revoke the data saving operation.
local_object.revokeSave((result, data) =>{
console.log("revokeSave callback");
console.info("revokeSave sessionId " + data.sessionId);
});
```
- Promise
```js
// Save a distributed data object.
g_object.save("local").then((result)=>{
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, (result)=>{
console.info("save local failed.");
});
// Revoke the data saving operation.
g_object.revokeSave().then((result)=>{
console.info("revokeSave success.");
}, (result)=>{
console.info("revokeSave failed.");
});
```
11. Unsubscribe from the status changes of the distributed data object. <br>You can specify the callback to unregister. If you do not specify the callback, this API unregisters all callbacks of this distributed data object.
```
​```js
// Save a distributed data object.
local_object.save("local", (result, data) => {
console.log("save callback");
console.info("save sessionId " + data.sessionId);
console.info("save version " + data.version);
console.info("save deviceId " + data.deviceId);
});
// Revoke the data saving operation.
local_object.revokeSave((result, data) => {
console.log("revokeSave callback");
console.info("revokeSave sessionId " + data.sessionId);
});
​```
```
- Promise
```
​```js
// Save a distributed data object.
g_object.save("local").then((result) => {
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, (result)=>{
console.info("save local failed.");
});
// Revoke the data saving operation.
g_object.revokeSave().then((result) => {
console.info("revokeSave success.");
}, (result)=>{
console.info("revokeSave failed.");
});
​```
```
11. Unsubscribe from the status changes of the distributed data object.
You can specify the callback to unregister. If you do not specify the callback, this API unregisters all callbacks of this distributed data object.
The sample code is as follows:
```js
```js
// Unregister the specified status change callback.
local_object.off("status", this.statusCallback);
// Unregister all status change callbacks.
local_object.off("status");
```
```
12. Remove a distributed data object from the synchronization network. Data changes on the local object will not be synchronized to the removed distributed data object.
The sample code is as follows:
```js
local_object.setSessionId("");
```
## Development Example
The following example is provided for you to better understand the development of distributed data objects:
- [Distributed Notepad](https://gitee.com/openharmony/distributeddatamgr_objectstore/tree/master/samples/distributedNotepad)
When an event of the Notepad app occurs on a device, such as a note is added, the tile or content of a note is changed, or the event list is cleared, the change will be synchronized to other devices in the trusted network.
......@@ -6,22 +6,20 @@ The Distributed Data Service (DDS) implements synchronization of application dat
## Available APIs
For details about the APIs related to distributed data, see [Distributed Data Management](../reference/apis/js-apis-distributed-data.md).
The table below describes the APIs provided by the OpenHarmony DDS module.
**Table 1** APIs provided by the DDS
| Category | API | Description |
| ------------ | ------------- | ------------- |
| Creating a distributed database| createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KVManager** object for database management.|
| Obtaining a distributed KV store| getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Obtains the KV store with the specified **Options** and **storeId**.|
| Managing data in a distributed KV store| put(key: string, value: Uint8Array \| string \| number \| boolean, callback: AsyncCallback&lt;void&gt;): void<br>put(key: string, value: Uint8Array \| string \| number \| boolean): Promise&lt;void> | Inserts and updates data.|
| Managing data in a distributed KV store| delete(key: string, callback: AsyncCallback&lt;void&gt;): void<br>delete(key: string): Promise&lt;void> | Deletes data. |
| Managing data in a distributed KV store| get(key: string, callback: AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt;): void<br>get(key: string): Promise&lt;Uint8Array \| string \| boolean \| number> | Queries data. |
| Subscribing to changes in the distributed data| on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotification&gt;): void<br>on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void | Subscribes to data changes in the KV store.|
| Synchronizing data across devices| sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void | Triggers database synchronization in manual mode. |
| API | Description |
| ------------------------------------------------------------ | ----------------------------------------------- |
| createKVManager(config:KVManagerConfig,callback:AsyncCallback&lt;KVManager&gt;):void<br>createKVManager(config:KVManagerConfig):Promise&lt;KVManager> | Creates a **KVManager** object for database management.|
| getKVStore&lt;TextendsKVStore&gt;(storeId:string,options:Options,callback:AsyncCallback&lt;T&gt;):void<br>getKVStore&lt;TextendsKVStore&gt;(storeId:string,options:Options):Promise&lt;T&gt; | Obtains a KV store with the specified **Options** and **storeId**.|
| put(key:string,value:Uint8Array\|string\|number\|boolean,callback:AsyncCallback&lt;void&gt;):void<br>put(key:string,value:Uint8Array\|string\|number\|boolean):Promise&lt;void> | Inserts and updates data. |
| delete(key:string,callback:AsyncCallback&lt;void&gt;):void<br>delete(key:string):Promise&lt;void> | Deletes data. |
| get(key:string,callback:AsyncCallback&lt;Uint8Array\|string\|boolean\|number&gt;):void<br>get(key:string):Promise&lt;Uint8Array\|string\|boolean\|number> | Queries data. |
| on(event:'dataChange',type:SubscribeType,observer:Callback&lt;ChangeNotification&gt;):void<br>on(event:'syncComplete',syncCallback:Callback&lt;Array&lt;[string,number]&gt;&gt;):void | Subscribes to data changes in the KV store. |
| sync(deviceIdList:string[],mode:SyncMode,allowedDelayMs?:number):void | Triggers database synchronization in manual mode. |
......@@ -36,11 +34,14 @@ The following uses a single KV store as an example to describe the development p
```
2. Create a **KvManager** instance based on the specified **KvManagerConfig** object.
(1) Create a **KvManagerConfig** object based on the application context.
(2) Create a **KvManager** instance.
(2) Create a **KvManager** instance.
The sample code is as follows:
```js
```
let kvManager;
try {
const kvManagerConfig = {
......@@ -62,9 +63,12 @@ The following uses a single KV store as an example to describe the development p
console.log("An unexpected error occurred. Error:" + e);
}
```
3. Create and obtain a single KV store.
(1) Declare the ID of the single KV store to create.
(2) Create a single KV store. You are advised to disable automatic synchronization (**autoSync:false**) and call **sync** when a synchronization is required.
The sample code is as follows:
......@@ -92,8 +96,9 @@ The following uses a single KV store as an example to describe the development p
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> For data synchronization between networked devices, you are advised to open the distributed KV store during application startup to obtain the database handle. With this database handle (**kvStore** in this example), you can perform operations, such as inserting data into the KV store, without creating the KV store repeatedly during the lifecycle of the handle.
> **NOTE**
>
> For data synchronization between networked devices, you are advised to open the distributed KV store during application startup to obtain the database handle. With this database handle (`kvStore` in this example), you can perform operations, such as inserting data into the KV store, without creating the KV store repeatedly during the lifecycle of the handle.
4. Subscribe to changes in the distributed data.<br/>
The following is the sample code for subscribing to the data changes of a single KV store:
......@@ -104,7 +109,9 @@ The following uses a single KV store as an example to describe the development p
```
5. Write data to the single KV store.
(1) Construct the key and value to be written into the single KV store.
(2) Write key-value pairs into the single KV store.
The following is the sample code for writing key-value pairs of the string type into the single KV store:
......@@ -126,7 +133,9 @@ The following uses a single KV store as an example to describe the development p
```
6. Query data in the single KV store.
(1) Construct the key to be queried from the single KV store.
(2) Query data from the single KV store.
The following is the sample code for querying data of the string type from the single KV store:
......@@ -152,7 +161,11 @@ The following uses a single KV store as an example to describe the development p
7. Synchronize data to other devices.<br/>
Select the devices in the same network and the synchronization mode to synchronize data.
The following is the sample code for data synchronization in a single KV store. **deviceIds** can be obtained by deviceManager by calling **getTrustedDeviceListSync()**, and **1000** indicates that the maximum delay time is 1000 ms.
> **NOTE**
>
> The APIs of the `deviceManager` module are system interfaces.
The following is the sample code for synchronizing data in a single KV store:
```js
import deviceManager from '@ohos.distributedHardware.deviceManager';
......@@ -161,7 +174,7 @@ The following uses a single KV store as an example to describe the development p
deviceManager.createDeviceManager("bundleName", (err, value) => {
if (!err) {
devManager = value;
// Obtain deviceIds.
// deviceIds is obtained by deviceManager by calling getTrustedDeviceListSync().
let deviceIds = [];
if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync();
......@@ -170,6 +183,7 @@ The following uses a single KV store as an example to describe the development p
}
}
try{
// 1000 indicates that the maximum delay is 1000 ms.
kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000);
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
......@@ -177,7 +191,3 @@ The following uses a single KV store as an example to describe the development p
}
});
```
## Samples
The following samples are provided to help you better understand the distributed data development:
- [`KvStore`: Distributed Database (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore)
- [Distributed Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData)
......@@ -39,28 +39,28 @@ function printfDescription(obj) {
// Set the player callbacks.
function setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the `dataLoad` event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.play(); // The play() API can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is then triggered.
});
audioPlayer.on('play', () => { // Set the `play` event callback.
audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success');
audioPlayer.pause(); // Trigger the 'pause' event callback and pause the playback.
});
audioPlayer.on('pause', () => { // Set the `pause` event callback.
audioPlayer.on('pause', () => { // Set the 'pause' event callback.
console.info('audio pause success');
audioPlayer.seek(5000); // Trigger the 'timeUpdate' event callback, and seek to 5000 ms for playback.
});
audioPlayer.on('stop', () => { // Set the `stop` event callback.
audioPlayer.on('stop', () => { // Set the 'stop' event callback.
console.info('audio stop success');
audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
});
audioPlayer.on('reset', () => { // Set the `reset` event callback.
audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.info('audio reset success');
audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined;
});
audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the `timeUpdate` event callback.
audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == 'undefined') {
console.info('audio seek fail');
return;
......@@ -68,7 +68,7 @@ function setCallBack(audioPlayer) {
console.info('audio seek success, and seek time is ' + seekDoneTime);
audioPlayer.setVolume(0.5); // Trigger the 'volumeChange' event callback.
});
audioPlayer.on('volumeChange', () => { // Set the `volumeChange` event callback.
audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback.
console.info('audio volumeChange success');
audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode.
if (typeof (arrlist) != 'undefined') {
......@@ -107,7 +107,7 @@ async function audioPlayerDemo() {
}).catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; // Set the src attribute and trigger the `dataLoad` event callback.
audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
}
```
......@@ -119,11 +119,11 @@ import fileIO from '@ohos.fileio'
export class AudioDemo {
// Set the player callbacks.
setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the `dataLoad` event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play', () => { // Set the `play` event callback.
audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success');
});
audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
......@@ -147,7 +147,7 @@ export class AudioDemo {
}).catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; // Set the src attribute and trigger the `dataLoad` event callback.
audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
......@@ -161,15 +161,15 @@ export class AudioDemo {
// Set the player callbacks.
private isNextMusic = false;
setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the `dataLoad` event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play', () => { // Set the `play` event callback.
audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success');
audioPlayer.reset(); // Call the reset() API and trigger the 'reset' event callback.
});
audioPlayer.on('reset', () => { // Set the `reset` event callback.
audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.info('audio play success');
if (!this.isNextMusic) { // When isNextMusic is false, changing songs is implemented.
this.nextMusic(audioPlayer); // Changing songs is implemented.
......@@ -223,7 +223,7 @@ import fileIO from '@ohos.fileio'
export class AudioDemo {
// Set the player callbacks.
setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the `dataLoad` event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.loop = true; // Set the loop playback attribute.
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
......@@ -247,7 +247,7 @@ export class AudioDemo {
}).catch((err) => {
console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath; // Set the src attribute and trigger the `dataLoad` event callback.
audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
......@@ -19,6 +19,7 @@
- [@ohos.application.ServiceExtensionAbility](js-apis-service-extension-ability.md)
- [@ohos.application.StartOptions](js-apis-application-StartOptions.md)
- [@ohos.application.StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md)
- [@ohos.application.WindowExtensionAbility](js-apis-application-WindowExtensionAbility.md)
- application/[AbilityContext](js-apis-ability-context.md)
- application/[ApplicationContext](js-apis-application-applicationContext.md)
- application/[AbilityStageContext](js-apis-abilitystagecontext.md)
......@@ -68,18 +69,25 @@
- [@ohos.bundle](js-apis-Bundle.md)
- [@ohos.bundle.defaultAppManager](js-apis-bundle-defaultAppManager.md)
- [@ohos.bundle.innerBundleManager)](js-apis-Bundle-InnerBundleManager.md)
- [@ohos.bundleState](js-apis-deviceUsageStatistics.md)
- [@ohos.distributedBundle)](js-apis-Bundle-distributedBundle.md)
- [@ohos.zlib](js-apis-zlib.md)
- bundle/[AbilityInfo](js-apis-bundle-AbilityInfo.md)
- bundle/[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)
- bundle/[BundleInfo](js-apis-bundle-BundleInfo.md)
- bundle/[BundleInstaller](js-apis-bundle-BundleInstaller.md)
- bundle/[CustomizeData](js-apis-bundle-CustomizeData.md)
- bundle/[DispatchInfo](js-apis-dispatchInfo.md)
- bundle/[ElementName](js-apis-bundle-ElementName.md)
- bundle/[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)
- bundle/[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)
- bundle/[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)
- bundle/[Metadata](js-apis-bundle-Metadata.md)
- bundle/[ModuleInfo](js-apis-bundle-ModuleInfo.md)
- bundle/[PermissionDef](js-apis-bundle-PermissionDef.md)
- bundle/[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)
- bundle/[ShortcutInfo](js-apis-bundle-ShortcutInfo.md)
- UI Page
- [@ohos.animator](js-apis-animator.md)
......@@ -90,6 +98,7 @@
- Graphics
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.display ](js-apis-display.md)
- [@ohos.effectKit](js-apis-effectKit.md)
- [@ohos.screen](js-apis-screen.md)
......
# innerBundleManager
The **innerBundleManager** module manages internal bundles.
> **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.
## Modules to Import
```
import innerBundleManager from '@ohos.bundle.innerBundleManager';
```
## System Capability
SystemCapability.BundleManager.BundleFramework
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ---------------------------- |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications. |
| ohos.permission.LISTEN_BUNDLE_CHANGE | system_grant | Permission to listen for application changes.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## innerBundleManager.getLauncherAbilityInfos
getLauncherAbilityInfos(bundleName: string, userId: number, callback: AsyncCallback&lt;Array&lt;LauncherAbilityInfo&gt;&gt;) : void;
Obtains the launcher ability information based on a given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Yes | Callback used to return an array of the launcher ability information. |
## innerBundleManager.getLauncherAbilityInfos
getLauncherAbilityInfos(bundleName: string, userId: number) : Promise&lt;Array&lt;LauncherAbilityInfo&gt;&gt;
Obtains the launcher ability information based on a given bundle name. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ----------------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------- |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Promise used to return an array of the launcher ability information.|
## innerBundleManager.on
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback, callback: AsyncCallback&lt;string&gt;) : void;
Registers a callback to receive bundle status changes. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.LISTEN_BUNDLE_CHANGE
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | --------------------- | ---- | ---------------------------------------------------- |
| type | "BundleStatusChange" | Yes | Event type. |
| bundleStatusCallback | BundleStatusCallback | Yes | Callback to register. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.on
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback): Promise&lt;string&gt;
Registers a callback to receive bundle status changes. This API uses a promise to return the result.
**Required permissions**
ohos.permission.LISTEN_BUNDLE_CHANGE
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | -------------------- | ---- | ------------------ |
| type | "BundleStatusChange" | Yes | Event type. |
| bundleStatusCallback | BundleStatusCallback | Yes | Callback to register.|
**Return value**
| Type | Description |
| --------------- | ----------------------------------- |
| Promise\<string> | Promise used to return a successful result or error information.|
## innerBundleManager.off
off(type:"BundleStatusChange", callback: AsyncCallback&lt;string&gt;) : void;
Deregisters the callback that receives bundle status changes. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.LISTEN_BUNDLE_CHANGE
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------------------------------- |
| type | "BundleStatusChange" | Yes | Event type. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.off
off(type:"BundleStatusChange"): Promise&lt;string&gt;
Deregisters the callback that receives bundle status changes. This API uses a promise to return the result.
**Required permissions**
ohos.permission.LISTEN_BUNDLE_CHANGE
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | -------------------- | ---- | ---------------- |
| type | "BundleStatusChange" | Yes | Event type.|
**Return value**
| Type | Description |
| --------------- | ----------------------------------- |
| Promise\<string> | Promise used to return a successful result or error information.|
## innerBundleManager.getAllLauncherAbilityInfos
getAllLauncherAbilityInfos(userId: number, callback: AsyncCallback&lt;Array&lt;LauncherAbilityInfo&gt;&gt;) : void;
Obtains the information about all launcher abilities. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Yes | Callback used to return an array of the launcher ability information. |
## innerBundleManager.getAllLauncherAbilityInfos
getAllLauncherAbilityInfos(userId: number) : Promise&lt;Array&lt;LauncherAbilityInfo&gt;&gt;
Obtains the information about all launcher abilities. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------ | ---- | ----------------------------------------------------- |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------- |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Promise used to return an array of the launcher ability information.|
## innerBundleManager.getShortcutInfos
getShortcutInfos(bundleName :string, callback: AsyncCallback&lt;Array&lt;ShortcutInfo&gt;&gt;) : void;
Obtains the shortcut information based on a given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<Array<[ShortcutInfo](js-apis-bundle-ShortcutInfo.md)>> | Yes | Callback used to return an array of the shortcut information.|
## innerBundleManager.getShortcutInfos
getShortcutInfos(bundleName : string) : Promise&lt;Array&lt;ShortcutInfo&gt;&gt;
Obtains the shortcut information based on a given bundle name. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
| bundleName | string | Yes | Bundle name of an application.|
**Return value**
| Type | Description |
| -------------------------------------------------------- | ----------------------------- |
| Promise\<Array<[ShortcutInfo](js-apis-bundle-ShortcutInfo.md)>> | Promise used to return an array of the shortcut information.|
# distributedBundle
The **distributedBundle** module manages distributed bundles.
> **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.
## Modules to Import
```
import distributedBundle from '@ohos.distributedBundle';
```
## System Capability
SystemCapability.BundleManager.DistributedBundleFramework
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ------------------ |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## distributedBundle.getRemoteAbilityInfo
getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback&lt;RemoteAbilityInfo&gt;): void;
Obtains information about the remote ability that matches the given element name. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.DistributedBundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | **ElementName**. |
| callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)> | Yes | Callback used to return the remote ability information.|
## distributedBundle.getRemoteAbilityInfo
getRemoteAbilityInfo(elementName: ElementName): Promise&lt;RemoteAbilityInfo&gt;
Obtains information about the remote ability that matches the given element name. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.DistributedBundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | -------------------------------------------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | **ElementName**.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)> | Promise used to return the remote ability information.|
## distributedBundle.getRemoteAbilityInfos
getRemoteAbilityInfos(elementNames: Array&lt;ElementName&gt;, callback: AsyncCallback&lt;Array&lt;RemoteAbilityInfo&gt;&gt;): void;
Obtains information about remote abilities that match the given element names. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.DistributedBundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| elementNames | Array<[ElementName](js-apis-bundle-ElementName.md)> | Yes | **ElementName** array, whose maximum length is 10. |
| callback | AsyncCallback< Array<[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)>> | Yes | Callback used to return an array of the remote ability information.|
## distributedBundle.getRemoteAbilityInfos
getRemoteAbilityInfos(elementNames: Array&lt;ElementName&gt;): Promise&lt;Array&lt;RemoteAbilityInfo&gt;&gt;
Obtains information about remote abilities that match the given element names. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.DistributedBundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | --------------------------------------------------- | ---- | ----------------------- |
| elementNames | Array<[ElementName](js-apis-bundle-ElementName.md)> | Yes | **ElementName** array, whose maximum length is 10.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | --------------------------------- |
| Promise\<Array<[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)>> | Promise used to return an array of the remote ability information.|
# wantConstant
The **wantConstant** module provides the action, entity, and flags used in **Want** objects.
The **wantConstant** module provides the actions, entities, and flags used in **Want** objects.
> **NOTE**
>
......@@ -23,15 +23,15 @@ Enumerates the action constants of the **Want** object.
| ACTION_HOME | ohos.want.action.home | Action of returning to the home page. |
| ACTION_DIAL | ohos.want.action.dial | Action of launching the numeric keypad. |
| ACTION_SEARCH | ohos.want.action.search | Action of launching the search function. |
| ACTION_WIRELESS_SETTINGS | ohos.settings.wireless | Action of launching the UI that provides radio network settings, for example, Wi-Fi option. |
| ACTION_WIRELESS_SETTINGS | ohos.settings.wireless | Action of launching the UI that provides wireless network settings, for example, Wi-Fi options. |
| ACTION_MANAGE_APPLICATIONS_SETTINGS | ohos.settings.manage.applications | Action of launching the UI for managing installed applications. |
| ACTION_APPLICATION_DETAILS_SETTINGS | ohos.settings.application.details | Action of launching the UI that displays the details of an application. |
| ACTION_SET_ALARM | ohos.want.action.setAlarm | Action of launching the UI for setting the alarm clock. |
| ACTION_SHOW_ALARMS | ohos.want.action.showAlarms | Action of launching the UI that displays all clock alarms. |
| ACTION_SHOW_ALARMS | ohos.want.action.showAlarms | Action of launching the UI that displays all alarms. |
| ACTION_SNOOZE_ALARM | ohos.want.action.snoozeAlarm | Action of launching the UI for snoozing an alarm. |
| ACTION_DISMISS_ALARM | ohos.want.action.dismissAlarm | Action of launching the UI for deleting an alarm. |
| ACTION_DISMISS_TIMER | ohos.want.action.dismissTimer | Action of launching the UI for dismissing a timer. |
| ACTION_SEND_SMS | ohos.want.action.sendSms | Action of launching the UI for sending an SMS. |
| ACTION_SEND_SMS | ohos.want.action.sendSms | Action of launching the UI for sending an SMS message. |
| ACTION_CHOOSE | ohos.want.action.choose | Action of launching the UI for openning a contact or picture. |
| ACTION_IMAGE_CAPTURE<sup>8+</sup> | ohos.want.action.imageCapture | Action of launching the UI for photographing. |
| ACTION_VIDEO_CAPTURE<sup>8+</sup> | ohos.want.action.videoCapture | Action of launching the UI for shooting a video. |
......
......@@ -49,7 +49,7 @@ Checks whether an application has been granted the specified permission. This AP
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
| tokenID | number | Yes | ID of the application. |
| tokenID | number | Yes | ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
| permissionName | string | Yes | Name of the permission to verify.|
**Return value**
......@@ -105,7 +105,7 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl
Grants a user granted permission to an application. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications.
This is a system API.
**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
......@@ -143,7 +143,7 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl
Grants a user granted permission to an application. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications.
This is a system API.
**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
......@@ -179,7 +179,7 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF
Revokes a user granted permission given to an application. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications.
This is a system API.
**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
......@@ -217,7 +217,7 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF
Revokes a user granted permission given to an application. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications.
This is a system API.
**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
......@@ -253,7 +253,7 @@ getPermissionFlags(tokenID: number, permissionName: string): Promise&lt;number&g
Obtains the flags of the specified permission of a given application. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications.
This is a system API.
**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS, ohos.permission.GRANT_SENSITIVE_PERMISSIONS, or ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
......
......@@ -23,23 +23,94 @@ import Want from '@ohos.application.Want';
| abilityName | Read only | string | No | Name of the ability. If both **package** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.|
| uri | Read only | string | No | URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| type | Read only | string | No | MIME type, for example, **text/plain** or **image/***. |
| flags | Read only | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](js-apis-featureAbility.md#flags).|
| flags | Read only | number | No | How the **Want** object will be handled. For details, see [flags](js-apis-featureAbility.md#flags).|
| action | Read only | string | No | Action option. |
| parameters | Read only | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>**ohos.aafwk.callerPid**: PID of the caller.<br>**ohos.aafwk.param.callerToken**: token of the caller.<br>**ohos.aafwk.param.callerUid**: UID of the caller. The **userId** parameter in the [Bundle](js-apis-Bundle.js) module can be used to obtain application and bundle information. |
| parameters | Read only | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>**ohos.aafwk.callerPid**: PID of the caller.<br>**ohos.aafwk.param.callerToken**: token of the caller.<br>**ohos.aafwk.param.callerUid**: UID of the caller. The **userId** parameter in the [Bundle](js-apis-Bundle.md) module can be used to obtain application and bundle information. |
| entities | Read only | Array\<string> | No | List of entities. |
| moduleName<sup>9+</sup> | Read only | string | No | Module to which the ability belongs.|
**Example**
``` js
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry" // moduleName is optional.
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
- Basic usage
``` js
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry" // moduleName is optional.
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
- Passing a file descriptor (FD)
``` js
var fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
}
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry" // moduleName is optional.
"parameters": {
"keyFd":{"type":"FD", "value":fd}
}
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
- Passing **RemoteObject** data
``` js
class Stub extends rpc.RemoteObject {
constructor(des) {
if (typeof des == 'string') {
super(des);
} else {
return null;
}
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.log('onRemoteRequest called')
let token = data.readInterfaceToken();
let num = data.readInt();
this.method();
return true;
}
return false;
}
method() {
console.log('method called');
}
}
var remoteObject = new Stub('want-test');
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry" // moduleName is optional.
"parameters": {
"keyRemoteObject":{"type":"RemoteObject", "value":remoteObject}
}
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
<!--no_check-->
\ No newline at end of file
# AbilityLifecycleCallback
The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onAbilityWindowStageCreate**, and **onAbilityWindowStageDestroy**, to receive lifecycle state changes in the application context.
The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onWindowStageCreate**, and **onWindowStageDestroy**, to receive lifecycle state changes in the application context.
> **NOTE**
>
......@@ -30,9 +30,9 @@ Called when an ability is created.
| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityWindowStageCreate
## AbilityLifecycleCallback.onWindowStageCreate
onAbilityWindowStageCreate(ability: Ability): void;
onWindowStageCreate(ability: Ability, windowStage: window.WindowStage): void;
Called when the window stage of an ability is created.
......@@ -43,11 +43,44 @@ Called when the window stage of an ability is created.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onAbilityWindowStageDestroy
## AbilityLifecycleCallback.onWindowStageActive
onAbilityWindowStageDestroy(ability: Ability): void;
onWindowStageActive(ability: Ability, windowStage: window.WindowStage): void;
Called when the window stage of an ability gains focus.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageInactive
onWindowStageInactive(ability: Ability, windowStage: window.WindowStage): void;
Called when the window stage of an ability loses focus.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageDestroy
onWindowStageDestroy(ability: Ability, windowStage: window.WindowStage): void;
Called when the window stage of an ability is destroyed.
......@@ -58,6 +91,7 @@ Called when the window stage of an ability is destroyed.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onAbilityDestroy
......@@ -132,12 +166,22 @@ Called when an ability is continued on another device.
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
},
onAbilityWindowStageCreate(ability){
console.log("AbilityLifecycleCallback onAbilityWindowStageCreate ability:" + JSON.stringify(ability));
},
onAbilityWindowStageDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityWindowStageDestroy ability:" + JSON.stringify(ability));
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
},
......
......@@ -19,7 +19,7 @@ import AbilityContext from '@ohos.application.Ability'
let context = this.context.createBundleContext(test);
}
}
```
```
## Attributes
......@@ -53,15 +53,15 @@ Creates a context for a given application.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context created.|
| Type| Description|
| -------- | -------- |
| Context | Context created.|
**Example**
......@@ -87,15 +87,15 @@ Creates a context for a given HAP.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| moduleName | string | Yes| HAP name in the application.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| moduleName | string | Yes| HAP name in the application.|
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context created.|
| Type| Description|
| -------- | -------- |
| Context | Context created.|
**Example**
......@@ -123,16 +123,16 @@ Creates a context for a given HAP in an application.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
| moduleName | string | Yes| HAP name in the application.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
| moduleName | string | Yes| HAP name in the application.|
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context created.|
| Type| Description|
| -------- | -------- |
| Context | Context created.|
**Example**
......
......@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| 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.|
| 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.|
**Example**
......@@ -46,9 +46,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| 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.|
| 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.|
**Example**
......@@ -72,9 +72,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| 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.|
| 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.|
**Example**
......@@ -96,9 +96,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| 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.|
| 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.|
**Example**
......@@ -119,9 +119,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
**Example**
......@@ -143,9 +143,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example**
......@@ -155,7 +155,11 @@ Obtains the memory size of this application. This API uses an asynchronous callb
console.log('startAbility result success:' + JSON.stringify(data));
})
```
## appManager.getProcessRunningInfos<sup>8+</sup>
## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9) instead.
getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
......@@ -181,7 +185,11 @@ Obtains information about the running processes. This API uses a promise to retu
});
```
## appManager.getProcessRunningInfos<sup>8+</sup>
## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9-1) instead.
getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void;
......@@ -206,11 +214,62 @@ Obtains information about the running processes. This API uses an asynchronous c
})
```
## appManager.getProcessRunningInformation<sup>9+</sup>
getProcessRunningInformation(): Promise\<Array\<ProcessRunningInformation>>;
Obtains information about the running processes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<Array\<ProcessRunningInformation>> | Promise used to return the process information.|
**Example**
```js
app.getProcessRunningInformation().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
```
## appManager.getProcessRunningInformation<sup>9+</sup>
getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInformation>>): void;
Obtains information about the running processes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<ProcessRunningInformation>> | No| Callback used to return the process information.|
**Example**
```js
app.getProcessRunningInformation((err, data) => {
console.log('startAbility result failed :' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
```
## appManager.registerApplicationStateObserver<sup>8+</sup>
registerApplicationStateObserver(observer: ApplicationStateObserver): number;
Registers the application state observer.
Registers an observer to listen for the state of all applications.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
......@@ -222,7 +281,7 @@ Registers the application state observer.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observer | ApplicationStateObserver | No| Numeric code of the observer.|
| observer | [ApplicationStateObserver](#applicationstateobserver) | No| Numeric code of the observer.|
**Example**
......@@ -244,6 +303,48 @@ Registers the application state observer.
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.registerApplicationStateObserver<sup>9+</sup>
registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameList: Array<string>): number;
Registers an observer to listen for the state of a specified application.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observer | [ApplicationStateObserver](#applicationstateobserver) | No| Numeric code of the observer.|
| bundleNameList | Array<string> | No| **bundleName** array to be registered for listening. The maximum value is 128.|
**Example**
```js
var applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
},
onAbilityStateChanged(abilityStateData) {
console.log('------------ onAbilityStateChanged -----------', abilityStateData);
},
onProcessCreated(processData) {
console.log('------------ onProcessCreated -----------', processData);
},
onProcessDied(processData) {
console.log('------------ onProcessDied -----------', processData);
}
}
var bundleNameList = ['bundleName1', 'bundleName2'];
const observerCode = app.registerApplicationStateObserver(applicationStateObserver, bundleNameList);
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.unregisterApplicationStateObserver<sup>8+</sup>
......@@ -258,7 +359,7 @@ Deregisters the application state observer. This API uses an asynchronous callba
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
......@@ -319,7 +420,7 @@ Deregisters the application state observer. This API uses a promise to return th
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
Obtains applications that run in the foreground. This API uses an asynchronous callback to return the result.
Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
......@@ -350,7 +451,7 @@ Obtains applications that run in the foreground. This API uses an asynchronous c
getForegroundApplications(): Promise\<Array\<AppStateData>>;
Obtains applications that run in the foreground. This API uses a promise to return the result.
Obtains applications that are running in the foreground. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
......@@ -380,7 +481,7 @@ Obtains applications that run in the foreground. This API uses a promise to retu
killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
Kills the process by bundle name and account ID. This API uses a promise to return the result.
Kills a process by bundle name and account ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
......@@ -390,10 +491,10 @@ Kills the process by bundle name and account ID. This API uses a promise to retu
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| Account ID.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example**
......@@ -414,7 +515,7 @@ app.killProcessWithAccount(bundleName, accountId)
killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void
Kills the process by bundle name and account ID. This API uses an asynchronous callback to return the result.
Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -424,11 +525,11 @@ Kills the process by bundle name and account ID. This API uses an asynchronous c
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| Account ID.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
......@@ -708,7 +809,7 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo);
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name of an application. |
| abilityName<sup>8+</sup> | string | Yes | No | Ability name. |
| uid<sup>8+</sup> | number | Yes | No | User ID. |
| state<sup>8+</sup> | number | Yes | No | Application information. |
| state<sup>8+</sup> | number | Yes | No | Ability state. |
| moduleName<sup>9+</sup> | string | Yes | No | Name of the HAP file to which the ability belongs. |
| abilityType<sup>8+</sup> | string | Yes | No | Ability type. |
......@@ -736,3 +837,16 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo);
| uid<sup>9+</sup> | Read only | number | No | User ID.|
| processName<sup>9+</sup> | Read only | string | No | Process name.|
| bundleNames<sup>9+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.|
## ApplicationStateObserver
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
| [onForegroundApplicationChanged<sup>8+</sup>](#applicationstateobserveronforegroundapplicationchanged8) | AsyncCallback\<void> | Yes | No | Callback invoked when the foreground or background state of an application changes. |
| [onAbilityStateChanged<sup>8+</sup>](#applicationstateobserveronabilitystatechanged8) | AsyncCallback\<void> | Yes | No | Callback invoked when the ability state changes. |
| [onProcessCreated<sup>8+</sup>](#applicationstateobserveronprocesscreated8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is created. |
| [onProcessDied<sup>8+</sup>](#applicationstateobserveronprocessdied8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is destroyed. |
# BackgroundTaskManager
# Background Task Management
This module provides background task management.
The **BackgroundTaskManager** module provides APIs to manage background tasks.
If a service needs to be continued when the application or service module is running in the background (not visible to users), the application or service module can request a transient task or continuous task for delayed suspension based on the service type.
......@@ -15,7 +15,7 @@ If an application has a service that can be intuitively perceived by users and n
## Modules to Import
```
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
```
......@@ -144,12 +144,12 @@ Requests a continuous task from the system. This API uses an asynchronous callba
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ------------------------ |
| context | [Context](js-apis-Context.md) | Yes | Application context. |
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```js
......@@ -196,11 +196,11 @@ Requests a continuous task from the system. This API uses a promise to return th
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-Context.md) | Yes | Application context. |
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked.|
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
**Return value**
| Type | Description |
......@@ -245,10 +245,10 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------- | ---- | ---------------------- |
| context | [Context](js-apis-Context.md) | Yes | Application context. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```js
......@@ -276,9 +276,9 @@ Requests to cancel a continuous task. This API uses a promise to return the resu
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------------------------- | ---- | --------- |
| context | [Context](js-apis-Context.md) | Yes | Application context.|
| Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
**Return value**
| Type | Description |
......@@ -314,14 +314,14 @@ Provides the information about the suspension delay.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
| Name | Value| Description |
| ----------------------- | ------ | ------------------------------------------------------------ |
| DATA_TRANSFER | 1 | Data transfer. |
| AUDIO_PLAYBACK | 2 | Audio playback. |
| AUDIO_RECORDING | 3 | Audio recording. |
| LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related.<br>This is a system API and cannot be called by third-party applications.|
| VOIP | 8 | Audio and video calls.<br>This is a system API and cannot be called by third-party applications.|
| TASK_KEEPING | 9 | Computing task (effective only for specific devices). |
| Name | Value | Description |
| ----------------------- | ---- | --------------------- |
| DATA_TRANSFER | 1 | Data transfer. |
| AUDIO_PLAYBACK | 2 | Audio playback. |
| AUDIO_RECORDING | 3 | Audio recording. |
| LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related.<br>This is a system API.|
| VOIP | 8 | Audio and video calls.<br>This is a system API. |
| TASK_KEEPING | 9 | Computing task (effective only for specific devices). |
# AbilityInfo
Unless otherwise specified, ability information is obtained through **GET_BUNDLE_DEFAULT**.
> **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.
Provides the ability information.
## AbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
......@@ -25,24 +20,24 @@ Provides the ability information.
| iconId | number | Yes | No | Ability icon ID. |
| moduleName | string | Yes | No | Name of the HAP file to which the ability belongs. |
| process | string | Yes | No | Process in which the ability runs. If this parameter is not set, the bundle name is used.|
| targetAbility | string | Yes | No | Target ability that the ability alias points to. |
| backgroundModes | number | Yes | No | Background service mode of the ability. |
| targetAbility | string | Yes | No | Target ability that the ability alias points to.<br>This attribute can be used only in the FA model.|
| backgroundModes | number | Yes | No | Background service mode of the ability.<br>This attribute can be used only in the FA model. |
| isVisible | boolean | Yes | No | Whether the ability can be called by other applications. |
| formEnabled | boolean | Yes | No | Whether the ability provides the service widget capability. |
| type | AbilityType | Yes | No | Ability type. |
| formEnabled | boolean | Yes | No | Whether the ability provides the service widget capability.<br>This attribute can be used only in the FA model.|
| type | AbilityType | Yes | No | Ability type.<br>This attribute can be used only in the FA model. |
| orientation | DisplayOrientation | Yes | No | Ability display orientation. |
| launchMode | LaunchMode | Yes | No | Ability launch mode. |
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the ability.|
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_PERMISSION**.|
| deviceTypes | Array\<string> | Yes | No | Device types supported by the ability. |
| deviceCapabilities | Array\<string> | Yes | No | Device capabilities required for the ability. |
| readPermission | string | Yes | No | Permission required for reading the ability data. |
| writePermission | string | Yes | No | Permission required for writing data to the ability. |
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | Yes | No | Application configuration information. |
| uri | string | Yes | No | URI of the ability. |
| readPermission | string | Yes | No | Permission required for reading the ability data.<br>This attribute can be used only in the FA model.|
| writePermission | string | Yes | No | Permission required for writing data to the ability.<br>This attribute can be used only in the FA model.|
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | Yes | No | Application configuration information.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_APPLICATION**.|
| uri | string | Yes | No | URI of the ability.<br>This attribute can be used only in the FA model.|
| labelId | number | Yes | No | Ability label ID. |
| subType | AbilitySubType | Yes | No | Subtype of the template that can be used by the ability. |
| metaData<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Custom metadata of the ability. |
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability. |
| subType | AbilitySubType | Yes | No | Subtype of the template that can be used by the ability.<br>This attribute can be used only in the FA model.|
| metaData<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Custom metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| enabled<sup>8+</sup> | boolean | Yes | No | Whether the ability is enabled. |
| supportWindowMode<sup>9+</sup> | Array\<[SupportWindowMode](js-apis-Bundle.md)> | Yes | No | Window modes supported by the ability. |
| maxWindowRatio<sup>9+</sup> | number | Yes | No | Maximum window ratio supported by the ability. |
......
# BundleInstaller
The **BundleInstaller** module provides APIs for installing, updating, and deleting bundles on devices.
> **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.
## System Capability
SystemCapability.BundleManager.BundleFramework
## BundleInstaller.install
install(bundleFilePaths: Array&lt;string&gt;, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
Installs bundles. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.INSTALL_BUNDLE
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| bundleFilePaths | Array&lt;string&gt; | Yes | Paths where the bundles are stored. Each path should point to a relative directory of the current application's data directory.|
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status. |
## BundleInstaller.uninstall
uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
Uninstalls a bundle. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.INSTALL_BUNDLE
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status.|
## BundleInstaller.recover
recover(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
Recovers a bundle. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.INSTALL_BUNDLE
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status.|
## InstallParam
Describes the parameters required for bundle installation or uninstall.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ----------- | ------- | ------------------ |
| userId | number | User ID. |
| installFlag | number | Installation flag. |
| isKeepData | boolean | Whether data is kept.|
## InstallStatus
Describes the bundle installation status.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------ |
| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | Yes | No | Installation or uninstall error code. |
| statusMessage | string | Yes | No | Installation or uninstall status message.|
# ElementName
The **ElementName** module provides the element name information.
> **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.
Provides the element name information.
## ElementName
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
......
# LauncherAbilityInfo
The **LauncherAbilityInfo** module provides information about a launcher ability.
> **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.
## LauncherAbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| --------------- | ---------------------------------------------------- | ---- | ---- | ------------------------------------ |
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | Yes | No | Application information of the launcher ability.|
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | No | Element name of the launcher ability. |
| labelId | number | Yes | No | Label ID of the launcher ability. |
| iconId | number | Yes | No | Icon ID of the launcher ability. |
| userId | number | Yes | No | User ID of the launcher ability. |
| installTime | number | Yes | No | Time when the launcher ability is installed. |
# PermissionDef
The **PermissionDef** module provides permission details defined in the configuration file.
> **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.
## **PermissionDef**
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| -------------- | ------ | ---- | ---- | -------------- |
| permissionName | string | Yes | No | Name of the permission. |
| grantMode | number | Yes | No | Grant mode of the permission.|
| labelId | number | Yes | No | Label ID of the permission. |
| descriptionId | number | Yes | No | Description ID of the permission. |
# ShortcutInfo
The **ShortcutInfo** module provides shortcut information defined in the configuration file.
> **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.
## ShortcutWant
Describes the information about the target to which the shortcut points.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ------------------------- | ------ | ---- | ---- | -------------------- |
| targetBundle | string | Yes | No | Target bundle of the shortcut.|
| targetModule<sup>9+</sup> | string | Yes | No | Target module of the shortcut. |
| targetClass | string | Yes | No | Target class required by the shortcut.|
## ShortcutInfo
Describes the shortcut attribute information.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ----------------------- | ------------------------------------------ | ---- | ---- | ---------------------------- |
| id | string | Yes | No | ID of the application to which the shortcut belongs. |
| bundleName | string | Yes | No | Name of the bundle that contains the shortcut. |
| hostAbility | string | Yes | No | Local ability information of the shortcut. |
| icon | string | Yes | No | Icon of the shortcut. |
| iconId<sup>8+</sup> | number | Yes | No | Icon ID of the shortcut. |
| label | string | Yes | No | Label of the shortcut. |
| labelId<sup>8+</sup> | number | Yes | No | Label ID of the shortcut. |
| disableMessage | string | Yes | No | Message displayed when the shortcut is disabled. |
| wants | Array&lt;[ShortcutWant](#shortcutwant)&gt; | Yes | No | Want information required for the shortcut. |
| isStatic | boolean | Yes | No | Whether the shortcut is static. |
| isHomeShortcut | boolean | Yes | No | Whether the shortcut is a home shortcut.|
| isEnabled | boolean | Yes | No | Whether the shortcut is enabled. |
| moduleName<sup>9+</sup> | string | Yes | No | Module name of the shortcut. |
# RemoteAbilityInfo
The **RemoteAbilityInfo** module provides information about a remote ability.
> **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.
## RemoteAbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ----------- | -------------------------------------------- | ---- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | No | Element name of the ability. |
| label | string | Yes | No | Label of the ability. |
| icon | string | Yes | No | Icon of the ability.|
# Standard NFC Card Emulation
The cardEmulation module implements Near-Field Communication (NFC) card emulation.
The **cardEmulation** module implements Near-Field Communication (NFC) card emulation.
> **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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -19,7 +19,7 @@ isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
......@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported.
| -------- | -------- |
| boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.|
## HceService
## HceService<sup>8+</sup>
Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance.
### startHCE
### startHCE<sup>8+</sup>
startHCE(aidList: string[]): boolean
......@@ -39,7 +39,7 @@ Starts HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**System capability**: SystemCapability.Communication.NFC.Core
**Parameters**
......@@ -47,7 +47,7 @@ Starts HCE.
| ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.|
### stopHCE
### stopHCE<sup>8+</sup>
stopHCE(): boolean
......@@ -55,9 +55,9 @@ Stops HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**System capability**: SystemCapability.Communication.NFC.Core
### on
### on<sup>8+</sup>
on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
......@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**System capability**: SystemCapability.Communication.NFC.Core
**Parameters**
......@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**.
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).|
### sendResponse
### sendResponse<sup>8+</sup>
sendResponse(responseApdu: number[]): void;
......@@ -82,7 +82,7 @@ Sends a response to the peer device.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**System capability**: SystemCapability.Communication.NFC.Core
**Parameters**
......
# Active Tag
The **connectedTag** module provides methods for using active tags. You can use the APIs provided by this module to initialize the active tag chip and read and write active tags.
> **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.
......@@ -22,9 +24,9 @@ Initializes the active tag chip.
**System capability**: SystemCapability.Communication.ConnectedTag
- Return value
| **Type** | **Description** |
| -------- | -------- |
| boolean | Returns **true** if the initialization is successful; returns **false** otherwise. |
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the initialization is successful; returns **false** otherwise.|
## connectedTag.uninit
......@@ -38,9 +40,9 @@ Uninitializes the active tag resources.
**System capability**: SystemCapability.Communication.ConnectedTag
- Return value
| **Type** | **Description** |
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.readNdefTag
......@@ -54,14 +56,14 @@ Reads the content of this active tag. This method uses a promise to return the r
**System capability**: SystemCapability.Communication.ConnectedTag
- Return value
| **Type** | **Description** |
| -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the content of the active tag. |
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the content of the active tag.|
- Example
```
import connectedTag from '@ohos.connectedTag';
connectedTag.readNdefTag().then(result => {
console.log("promise recv ndef response: " + result);
});
......@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback
**System capability**: SystemCapability.Communication.ConnectedTag
- Parameters
| **Name** | **Type** | **Mandatory** | **Description** |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the active tag content obtained. |
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example
```
......@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result.
**System capability**: SystemCapability.Communication.ConnectedTag
- Parameters
| **Name** | **Type** | **Mandatory** | **Description** |
| -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. |
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | string | Yes| Data to write. The maximum length is 1024 bytes.|
- Return value
| **Type** | **Description** |
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. This method returns no value. |
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. This method returns no value.|
- Example
```
......@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result.
## connectedTag.writeNdefTag
writeNdefTag(data: string, callback: AsyncCallback&lt;string&gt;): void
writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
Writes data to this active tag. This method uses an asynchronous callback to return the result.
......@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
**System capability**: SystemCapability.Communication.ConnectedTag
- Parameters
| **Name** | **Type** | **Mandatory** | **Description** |
| -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the operation result. |
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | string | Yes| Data to write. The maximum length is 1024 bytes.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example
```
......@@ -151,7 +153,7 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
console.error(`failed to write event because ${err.code}`);
return;
}
// Data is written to the tag.
console.log(`success to write event: ${value}`);
});
......@@ -168,16 +170,16 @@ Registers the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag
- Parameters
| **Name** | **Type** | **Mandatory** | **Description** |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. |
| callback | Callback&lt;number&gt; | Yes | Callback invoked to return the field strength state. |
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the field strength state.|
- Enumerates the field strength states.
| **Value** | **Description** |
| -------- | -------- |
| 0 | Field off. |
| 1 | Field on. |
| **Value**| **Description**|
| -------- | -------- |
| 0 | Field off.|
| 1 | Field on.|
## connectedTag.off('notify')
......@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag
- Parameters
| **Name** | **Type** | **Mandatory** | **Description** |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. |
| callback | Callback&lt;number&gt; | No | Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered. |
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | No| Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
- Example
```
......@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events.
console.info("nfc rf receive state: " + result);
}
// Register event notification
// Register event notification.
connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
// Unregister event notification
// Unregister event notification.
connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
```
......@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events.
Enumerates the NFC states.
| Name | Default Value | Description |
| -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field off. |
| NFC_RF_ENTER | 1 | Field on. |
**System capability**: SystemCapability.Communication.ConnectedTag
| Name| Default Value| Description|
| -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field on.|
| NFC_RF_ENTER | 1 | Field on.|
......@@ -4,7 +4,7 @@ The relational database (RDB) manages data based on relational models. With the
This module provides the following RDB-related functions:
- [RdbPredicates](#rdbpredicates): predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbStore](#rdbstore): provides APIs for managing an RDB store.
> **NOTE**<br/>
......@@ -166,14 +166,14 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
inDevices(devices: Array&lt;string&gt;): RdbPredicates
Specifies a remote device on the network during distributed database synchronization.
Connects to the specified remote devices on the network during distributed database synchronization.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| devices | Array&lt;string&gt; | Yes| ID of the remote device to specify.|
| devices | Array&lt;string&gt; | Yes| IDs of the remote devices in the same network.|
**Return value**
| Type| Description|
......@@ -948,6 +948,8 @@ predicates.notIn("NAME", ["Lisa", "Rose"])
Provides methods to manage an RDB store.
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
### insert
......@@ -977,7 +979,7 @@ rdbStore.insert("EMPLOYEE", valueBucket, function (status, rowId) {
console.log("Failed to insert data");
return;
}
console.log("Inserted data, rowId = " + rowId);
console.log("Inserted data successfully, rowId = " + rowId);
})
```
......@@ -1011,7 +1013,7 @@ const valueBucket = {
}
let promise = rdbStore.insert("EMPLOYEE", valueBucket)
promise.then((rowId) => {
console.log("Inserted data, rowId = " + rowId);
console.log("Inserted data successfully, rowId = " + rowId);
}).catch((status) => {
console.log("Failed to insert data");
})
......@@ -1056,10 +1058,10 @@ const valueBucket3 = {
var valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
rdbStore.batchInsert("EMPLOYEE", valueBuckets, function(status, insertNum) {
if (status) {
console.log("bathInsert failed, status = " + status);
console.log("Failed to batch insert data, status = " + status);
return;
}
console.log("bathInsert is successful, the number of values that were inserted = " + insertNum);
console.log("Batch inserted data successfully. The number of values that were inserted = " + insertNum);
})
```
......@@ -1106,9 +1108,9 @@ const valueBucket3 = {
var valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
let promise = rdbStore.batchInsert("EMPLOYEE", valueBuckets);
promise.then((insertNum) => {
console.log("bathInsert is successful, the number of values that were inserted = " + insertNum);
console.log("Batch inserted data successfully. The number of values that were inserted = " + insertNum);
}).catch((status) => {
console.log("bathInsert failed, status = " + status);
console.log("Failed to batch insert data, status = " + status);
})
```
......@@ -1116,14 +1118,14 @@ promise.then((insertNum) => {
update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
Updates data based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The key-value pair is associated with the column name in the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
......@@ -1158,7 +1160,7 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The key-value pair is associated with the column name in the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
**Return value**
......@@ -1187,7 +1189,7 @@ promise.then(async (ret) => {
### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Updates data based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
Updates data in the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -1222,7 +1224,7 @@ rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
Updates data based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
Updates data in the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -1520,7 +1522,7 @@ Queries data from the RDB store of a remote device based on specified conditions
| -------- | -------- | -------- | -------- |
| device | string | Yes| Network ID of the remote device.|
| table | string | Yes| Name of the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions for querying data.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
| columns | Array&lt;string&gt; | Yes| Columns to query. If this parameter is not specified, the query applies to all columns.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md#resultset)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
......@@ -1553,7 +1555,7 @@ Queries data from the RDB store of a remote device based on specified conditions
| -------- | -------- | -------- | -------- |
| device | string | Yes| Network ID of the remote device.|
| table | string | Yes| Name of the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions for querying data.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|
**Return value**
......@@ -1580,7 +1582,7 @@ promise.then((resultSet) => {
querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result.
Queries data in the RDB store using the specified SQL statement. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -1588,7 +1590,7 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Values of the parameters in the SQL statement.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example**
......@@ -1608,7 +1610,7 @@ rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?",
querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
Queries data using the specified SQL statement. This API uses a promise to return the result.
Queries data in the RDB store using the specified SQL statement. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -1616,7 +1618,7 @@ Queries data using the specified SQL statement. This API uses a promise to retur
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Values of the parameters in the SQL statement.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.|
**Return value**
| Type| Description|
......@@ -1648,7 +1650,7 @@ Executes an SQL statement that contains specified arguments but returns no value
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback that returns no value.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example**
```js
......@@ -1658,7 +1660,7 @@ rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
console.info("Failed to execute SQL, err: " + err)
return
}
console.info('Create table done.')
console.info('Created table successfully.')
})
```
......@@ -1680,14 +1682,14 @@ Executes an SQL statement that contains specified arguments but returns no value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(() => {
console.info('Create table done.')
console.info('Created table successfully.')
}).catch((err) => {
console.info("Failed to execute SQL, err: " + err)
})
......@@ -1785,7 +1787,7 @@ rdbStore.backup("dbBackup.db", function(err) {
console.info('Failed to back up data, err: ' + err)
return
}
console.info('Backup successful.')
console.info('Backed up data successfully.')
})
```
......@@ -1811,7 +1813,7 @@ Backs up an RDB store. This API uses a promise to return the result.
```js
let promiseBackup = rdbStore.backup("dbBackup.db")
promiseBackup.then(()=>{
console.info('Backup successful.')
console.info('Backed up data successfully.')
}).catch((err)=>{
console.info('Failed to back up data, err: ' + err)
})
......@@ -1838,7 +1840,7 @@ rdbStore.restore("dbBackup.db", function(err) {
console.info('Failed to restore data, err: ' + err)
return
}
console.info('Restore successful.')
console.info('Restored data successfully.')
})
```
......@@ -1864,7 +1866,7 @@ Restores an RDB store from a backup file. This API uses a promise to return the
```js
let promiseRestore = rdbStore.restore("dbBackup.db")
promiseRestore.then(()=>{
console.info('Restore successful.')
console.info('Restored data successfully.')
}).catch((err)=>{
console.info('Failed to restore data, err: ' + err)
})
......@@ -1924,7 +1926,7 @@ let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => {
console.info("Set distributed tables successfully.")
}).catch((err) => {
console.info("Failed to set distributed tables, err: " + err)
console.info('Failed to set distributed tables, err: ' + err)
})
```
......@@ -1932,7 +1934,7 @@ promise.then(() => {
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the RDB store of a remote device is queried. This API uses an asynchronous callback to return the result.
Obtains the distributed table name for a remote device based on the local table name. This API uses an asynchronous callback to return the result. The distributed table name is required when the RDB store of a remote device is queried.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
......@@ -1961,7 +1963,7 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err,
obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the RDB store of a remote device is queried. This API uses a promise to return the result.
Obtains the distributed table name for a remote device based on the local table name. This API uses a promise to return the result. The distributed table name is required when the RDB store of a remote device is queried.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
......@@ -2003,7 +2005,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
| -------- | -------- | -------- | -------- |
| mode | [SyncMode](#syncmode8) | Yes| Data synchronization mode. The value can be **push** or **pull**.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.|
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example**
```js
......@@ -2042,7 +2044,7 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example**
```js
......
......@@ -119,7 +119,7 @@ helper.on(
off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void
Unregisters the observer used to observe data specified by a given URI. This API uses an asynchronous callback to return the result.
Deregisters the observer used to observe data specified by a given URI. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
......@@ -647,7 +647,7 @@ Deletes one or more data records from the database. This API uses an asynchronou
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -662,7 +662,7 @@ DAHelper.delete(
## DataAbilityHelper.delete
delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\<number>
delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>;
Deletes one or more data records from the database. This API uses a promise to return the result.
......@@ -685,7 +685,7 @@ Deletes one or more data records from the database. This API uses a promise to r
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -719,7 +719,7 @@ Updates data records in the database. This API uses an asynchronous callback to
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -741,7 +741,7 @@ DAHelper.update(
## DataAbilityHelper.update
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\<number>
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>;
Updates data records in the database. This API uses a promise to return the result.
......@@ -765,7 +765,7 @@ Updates data records in the database. This API uses a promise to return the resu
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -806,7 +806,7 @@ Queries data in the database. This API uses an asynchronous callback to return t
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -825,7 +825,7 @@ DAHelper.query(
## DataAbilityHelper.query
query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates): Promise\<ResultSet>
query(uri: string, columns?: Array\<string>, predicates?: dataAbility.DataAbilityPredicates): Promise\<ResultSet>;
Queries data in the database. This API uses a promise to return the result.
......@@ -849,7 +849,7 @@ Queries data in the database. This API uses a promise to return the result.
```js
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
......@@ -876,7 +876,7 @@ Calls the extended API of the Data ability. This API uses a promise to return th
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx" |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx". |
| method | string | Yes | Name of the API to call. |
| arg | string | Yes |Parameter to pass. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
......@@ -912,7 +912,7 @@ Calls the extended API of the Data ability. This API uses an asynchronous callba
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx" |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx". |
| method | string | Yes | Name of the API to call. |
| arg | string | Yes |Parameter to pass. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
......@@ -932,8 +932,107 @@ dataAbilityHelper.call("dataability:///com.example.jsapidemo.UserDataAbility", "
console.info('Operation succeeded: ' + data);
});
```
## DataAbilityHelper.executeBatch
executeBatch(uri: string, operations: Array\<DataAbilityOperation>, callback: AsyncCallback\<Array\<DataAbilityResult>>): void;
Operates data in the database. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx".|
| operations | Array\<[DataAbilityOperation](#dataabilityoperation)> | Yes | A list of data operations on the database. |
| callback | AsyncCallback\<Array\<[DataAbilityResult](#dataabilityresult)>> | Yes |Callback used to return the result of each operation in the **DataAbilityResult** array. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper("dataability:///com.example.jsapidemo.UserDataAbility");
dataAbilityHelper.executeBatch("dataability:///com.example.jsapidemo.UserDataAbility", op, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + err);
return;
}
console.info('Operation succeeded: ' + data);
});
```
## DataAbilityHelper.executeBatch
executeBatch(uri: string, operations: Array\<DataAbilityOperation>): Promise\<Array\<DataAbilityResult>>;
Operates data in the database. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------------------| ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx".|
| operations | Array\<[DataAbilityOperation](#dataabilityoperation)> | Yes | A list of data operations on the database. |
**Return value**
| Type| Description|
|------ | ------- |
|Promise\<Array\<[DataAbilityResult](#dataabilityresult)>> | Promise used to return the result of each operation in the **DataAbilityResult** array.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper("dataability:///com.example.jsapidemo.UserDataAbility");
dataAbilityHelper.executeBatch("dataability:///com.example.jsapidemo.UserDataAbility",op ).then((data) => {
console.info('Operation succeeded: ' + data);
}).catch((error) => {
console.error('Operation failed. Cause: ' + error);
});
```
## PacMap
[key: string]: number | string | boolean | Array\<string | number | boolean> | null;
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name| Type| Mandatory| Description|
| ------ | ------ | ------ | ------ |
| [key: string] | number \| string \| boolean \| Array\<string \| number \| boolean\> \| null | Yes| Data stored in key-value pairs.|
## DataAbilityOperation
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Readable | Writable | Mandatory| Description |
| -------- | -------- | -------- | -------- | --------| -------- |
| uri | string | Yes | No | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx". |
| type | featureAbility.DataAbilityOperationType | Yes | No | Yes | Operation type. |
| valuesBucket? | rdb.ValuesBucket | Yes | No | No | Data value to set. |
| valueBackReferences? | rdb.ValuesBucket | Yes | No | No | **ValuesBucket** object that contains a set of key-value pairs. |
| predicates? | dataAbility.DataAbilityPredicates | Yes | No | No | Predicates to set. If no predicate is set, all data records are displayed. |
| predicatesBackReferences? | Map\<number, number> | Yes | No | No | Back references of the predicates. |
| interrupted? | boolean | Yes | No | No | Whether batch operations can be interrupted. |
| expectedCount? | number | Yes | No | No | Expected number of rows to be updated or deleted. |
## DataAbilityResult
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Readable | Writable | Mandatory | Description |
| -------- | -------- | -------- | -------- | -------- | -------- |
| uri? | string | Yes | No | No | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx". |
| count? | number | Yes | No | No | Number of rows affected by the operation. |
# DispatchInfo
The **DispatchInfo** module provides dispatch information.
> **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.
## DispatchInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ----------- | ------ | ---- | ---- | ------------------------ |
| verison | string | Yes | No | Version of the API to dispatch.|
| dispatchAPI | string | Yes | No | API to dispatch. |
# ErrorManager
The **ErrorManager** module provides APIs for registering and deregistering error observers.
> **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.
## Modules to Import
```
import errorManager from '@ohos.application.errorManager'
```
## ErrorManager.registerErrorObserver
registerErrorObserver(observer: ErrorObserver): number;
Registers an error observer.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observer | [ErrorObserver](#errorobserver) | No| Numeric code of the observer.|
**Example**
```js
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
errorManager.registerErrorObserver(observer)
.then((data) => {
console.log('----------- registerErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- registerErrorObserver fail ----------', err);
})
```
## ErrorManager.unregisterErrorObserver
unregisterErrorObserver(observerId: number, callback: AsyncCallback\<void>): void;
Deregisters an error observer. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
| callback | AsyncCallback\<void> | No| Callback used to return the result.|
**Example**
```js
var observerId = 100;
function unregisterErrorObserverCallback(err) {
if (err) {
console.log('------------ unregisterErrorObserverCallback ------------', err);
}
}
errorManager.unregisterErrorObserver(observerId, unregisterErrorObserverCallback);
```
## ErrorManager.unregisterErrorObserver
unregisterErrorObserver(observerId: number): Promise\<void>;
Deregisters an error observer. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var observerId = 100;
errorManager.unregisterErrorObserver(observerId)
.then((data) => {
console.log('----------- unregisterErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterErrorObserver fail ----------', err);
})
```
## ErrorObserver
onUnhandledException(errMsg: string): void;
Called when an unhandled exception occurs in the JS runtime.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errMsg | string | No| Message and error stack trace about the exception.|
**Example**
```js
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
errorManager.registerErrorObserver(observer)
.then((data) => {
console.log('----------- registerErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- registerErrorObserver fail ----------', err);
})
```
# User File Access and Management
The fileManager module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
The **fileManager** module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
>**NOTE**<br/>
>
......@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This
**Example**
```js
filemanager.getRoot().then((fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
filemanager.getRoot().then((fileInfos) => {
for (var i = 0; i < fileInfos.length; i++) {
console.log("files:"+JSON.stringify(fileInfos));
}
}).catch((err) => {
console.log(err)
});
......@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This
"name":"local"
}
};
filemanager.getRoot(options, (err, fileInfo)=>{
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
filemanager.getRoot(options, (err, fileInfos)=>{
for (var i = 0; i < fileInfos.length; i++) {
console.log("files:"+JSON.stringify(fileInfos));
}
});
```
## filemanager.listFile
......@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example**
```js
// Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI.
let media_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));
}
}
// Obtain all files in the directory. You can use getRoot to obtain the directory URI.
filemanager.getRoot().then((fileInfos) => {
let file = fileInfos.find(item => item.name == "file_folder");
let path = file.path;
filemanager.listFile(path, "file").then((files) => {
console.log("files:" + JSON.stringify(files));
}).catch((err) => {
console.log("failed to get files" + err);
});
}).catch((err) => {
console.log("Failed to get file"+err);
console.log("failed to get root" + err);
});
```
......@@ -153,33 +147,18 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example**
```js
// Call listFile() and getRoot() to obtain the file path.
let fileInfos = filemanager.getRoot();
let media_path = "";
for (let i = 0; i < fileInfos.length; i++) {
if (fileInfos[i].name == "image_album") {
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("Failed to get file"+err);
});
```
```js
// Obtain all files in the directory. You can use getRoot to obtain the directory URI.
filemanager.getRoot().then((fileInfos) => {
let file = fileInfos.find(item => item.name == "image_album");
let path = file.path;
filemanager.listFile(path, "image",function(err, files){
console.log("files:" + JSON.stringify(files));
})
}).catch((err) => {
console.log("failed to get root" + err);
});
```
## filemanager.createFile
......
......@@ -35,15 +35,15 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
**Example**
......@@ -72,9 +72,9 @@ Called to notify the widget provider that a temporary widget has been converted
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ |
| formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ |
| formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
**Example**
......@@ -96,9 +96,9 @@ Called to notify the widget provider that a widget has been updated. After obtai
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.|
**Example**
......@@ -127,9 +127,9 @@ Called to notify the widget provider of the change of visibility.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
**Example**
......@@ -162,10 +162,10 @@ Called to instruct the widget provider to receive and process the widget event.
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- |
| formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes | Event message. |
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- |
| formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes | Event message. |
**Example**
......@@ -187,9 +187,9 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget to be destroyed.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget to be destroyed.|
**Example**
......@@ -211,9 +211,9 @@ Called when the configuration of the environment where the ability is running is
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes| New configuration.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes| New configuration.|
**Example**
......@@ -235,9 +235,9 @@ Called when the widget provider receives the status query result of a widget. By
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | No| Description of the widget state, including the bundle name, ability name, module name, widget name, and widget dimension.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | No| Description of the widget state, including the bundle name, ability name, module name, widget name, and widget dimension.|
**Example**
......@@ -250,3 +250,40 @@ Called when the widget provider receives the status query result of a widget. By
}
}
```
## FormExtension.onShare
onShare?(formId: string): {[key: string]: any};
Called by the widget provider to receive shared widget data.
This is a system API.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| formId | string | Yes | ID of a widget.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| {[key: string]: any} | Data to be shared by the widget, in the form of key-value pairs.|
**Example**
```js
class MyFormExtension extends FormExtension {
onShare(formId) {
console.log('FormExtension onShare, formId:' + formId);
let wantParams = {
"temperature":"20",
"time":"2022-8-8 09:59",
};
return wantParams;
}
}
```
......@@ -2,13 +2,32 @@
The **FormExtensionContext** module, inherited from **ExtensionContext**, provides context for Form Extension abilities.
You can use the APIs of this module to start abilities.
You can use the APIs of this module to start Form Extension abilities.
> **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 APIs of this module can be used only in the stage model.
## Usage
Before using the **ServiceExtensionContext** module, you must first obtain a **FormExtension** instance.
```js
import FormExtension from '@ohos.application.FormExtension';
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onCreate() {
let dataObj1 = {
temperature:"11c",
"time":"11:00"
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
}
```
## FormExtensionContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
......@@ -64,7 +83,7 @@ Starts an ability. This API uses a promise to return the result.
| Type | Description |
| ------------ | ---------------------------------- |
| Promise\<void> | Promise used to return the result.|
| Promise&lt;void&lt; | Promise used to return the result.|
**Example**
......
......@@ -32,7 +32,7 @@ This is a system API.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.|
| keyOptions | [keyOptions](#keyOptions) | Yes| Key option, which specifies the condition for combination key input.|
| keyOptions | [keyOptions](#keyoptions) | Yes| Key option, which specifies the condition for combination key input.|
| callback | Callback&lt;KeyOptions&gt; | Yes| Callback used to return the result.<br> When a key input event that meets the specified options occurs, **keyOptions** will be passed as an input parameter to **callback**.|
**Example**
......@@ -62,7 +62,7 @@ This is a system API.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.|
| keyOptions | [keyOptions](#keyOptions) | Yes| Key options passed to the key input event when listening starts.|
| keyOptions | [keyOptions](#keyoptions) | Yes| Key options passed to the key input event when listening starts.|
| callback | Callback&lt;KeyOptions&gt; | Yes| Callback function passed to the key input event with **keyOptions** when listening starts.|
**Example**
......
......@@ -536,7 +536,7 @@ Parameters
**Example**
```
var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
var pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
```
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册