提交 7bcf774a 编写于 作者: S shawn_he 提交者: Gitee

Merge branch 'OpenHarmony-3.2-Beta2' of gitee.com:openharmony/docs into 7345-a

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
...@@ -243,7 +243,7 @@ zh-cn/application-dev/reference/apis/js-apis-data-preferences.md @ge-yafang ...@@ -243,7 +243,7 @@ zh-cn/application-dev/reference/apis/js-apis-data-preferences.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-data-storage.md @ge-yafang zh-cn/application-dev/reference/apis/js-apis-data-storage.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-system-storage.md @ge-yafang zh-cn/application-dev/reference/apis/js-apis-system-storage.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-data-rdb.md @ge-yafang zh-cn/application-dev/reference/apis/js-apis-data-rdb.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-settings.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-settings.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-data-resultset.md @ge-yafang zh-cn/application-dev/reference/apis/js-apis-data-resultset.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-document.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-document.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-environment.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-environment.md @qinxiaowang
...@@ -279,7 +279,7 @@ zh-cn/application-dev/reference/apis/js-apis-hitracechain.md @zengyawen ...@@ -279,7 +279,7 @@ zh-cn/application-dev/reference/apis/js-apis-hitracechain.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-hitracemeter.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-hitracemeter.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @sun-yue14
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @sun-yue14
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-pasteboard.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-screen-lock.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-screen-lock.md @sun-yue14
zh-cn/application-dev/reference/apis/js-apis-system-time.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-system-time.md @sun-yue14
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-wallpaper.md @sun-yue14
......
...@@ -6,22 +6,20 @@ The Distributed Data Service (DDS) implements synchronization of application dat ...@@ -6,22 +6,20 @@ The Distributed Data Service (DDS) implements synchronization of application dat
## Available APIs ## Available APIs
For details about the APIs related to distributed data, see [Distributed Data Management](../reference/apis/js-apis-distributed-data.md). 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 **Table 1** APIs provided by the DDS
| Category | API | Description | | 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.| | 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**.| | 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**.|
| 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.| | 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. | | 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. | | 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.| | 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. | | 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 ...@@ -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. 2. Create a **KvManager** instance based on the specified **KvManagerConfig** object.
(1) Create a **KvManagerConfig** object based on the application context. (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: The sample code is as follows:
```js
```
let kvManager; let kvManager;
try { try {
const kvManagerConfig = { const kvManagerConfig = {
...@@ -62,9 +63,12 @@ The following uses a single KV store as an example to describe the development p ...@@ -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); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
3. Create and obtain a single KV store. 3. Create and obtain a single KV store.
(1) Declare the ID of the single KV store to create. (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. (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: 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 ...@@ -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/> > **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. >
> 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/> 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: 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 ...@@ -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. 5. Write data to the single KV store.
(1) Construct the key and value to be written into 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. (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: 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 ...@@ -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. 6. Query data in the single KV store.
(1) Construct the key to be queried from the single KV store. (1) Construct the key to be queried from the single KV store.
(2) Query data 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: 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 ...@@ -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/> 7. Synchronize data to other devices.<br/>
Select the devices in the same network and the synchronization mode to synchronize data. 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 ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; 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 ...@@ -161,7 +174,7 @@ The following uses a single KV store as an example to describe the development p
deviceManager.createDeviceManager("bundleName", (err, value) => { deviceManager.createDeviceManager("bundleName", (err, value) => {
if (!err) { if (!err) {
devManager = value; devManager = value;
// Obtain deviceIds. // deviceIds is obtained by deviceManager by calling getTrustedDeviceListSync().
let deviceIds = []; let deviceIds = [];
if (devManager != null) { if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync(); var devices = devManager.getTrustedDeviceListSync();
...@@ -170,6 +183,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -170,6 +183,7 @@ The following uses a single KV store as an example to describe the development p
} }
} }
try{ try{
// 1000 indicates that the maximum delay is 1000 ms.
kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000); kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000);
}catch (e) { }catch (e) {
console.log("An unexpected error occurred. Error:" + 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 ...@@ -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,38 +39,38 @@ function printfDescription(obj) { ...@@ -39,38 +39,38 @@ function printfDescription(obj) {
// Set the player callbacks. // Set the player callbacks.
function setCallBack(audioPlayer) { 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'); 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.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'); console.info('audio play success');
audioPlayer.pause(); // Trigger the 'pause' event callback and pause the playback. 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'); console.info('audio pause success');
audioPlayer.seek(5000); // Trigger the 'timeUpdate' event callback, and seek to 5000 ms for playback. 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'); console.info('audio stop success');
audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song. 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'); console.info('audio reset success');
audioPlayer.release(); // Release the AudioPlayer instance. audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
audioPlayer.on('timeUpdate', (seekDoneTime) => {// Set the 'timeUpdate' event callback. audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == 'undefined') { if (typeof(seekDoneTime) == 'undefined') {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
} }
console.info('audio seek success, and seek time is ' + seekDoneTime); console.info('audio seek success, and seek time is ' + seekDoneTime);
audioPlayer.setVolume(0.5); // Trigger the 'volumeChange' event callback. 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'); console.info('audio volumeChange success');
audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode. audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode.
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
for (let i = 0; i < arrlist.length; i++) { for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]); printfDescription(arrlist[i]);
...@@ -78,13 +78,13 @@ function setCallBack(audioPlayer) { ...@@ -78,13 +78,13 @@ function setCallBack(audioPlayer) {
} else { } else {
console.log(`audio getTrackDescription fail, error:${error.message}`); console.log(`audio getTrackDescription fail, error:${error.message}`);
} }
audioPlayer.stop(); // Trigger the 'stop' event callback to stop the playback. audioPlayer.stop(); // Trigger the 'stop' event callback to stop the playback.
}); });
}); });
audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete. audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
}); });
audioPlayer.on('error', (error) => { // Set the 'error' event callback. audioPlayer.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`); console.info(`audio error called, errMessage is ${error.message}`);
...@@ -94,7 +94,7 @@ function setCallBack(audioPlayer) { ...@@ -94,7 +94,7 @@ function setCallBack(audioPlayer) {
async function audioPlayerDemo() { async function audioPlayerDemo() {
// 1. Create an AudioPlayer instance. // 1. Create an AudioPlayer instance.
let audioPlayer = media.createAudioPlayer(); let audioPlayer = media.createAudioPlayer();
setCallBack(audioPlayer); // Set the event callbacks. setCallBack(audioPlayer); // Set the event callbacks.
// 2. Set the URI of the audio file. // 2. Set the URI of the audio file.
let fdPath = 'fd://' let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
...@@ -119,23 +119,23 @@ import fileIO from '@ohos.fileio' ...@@ -119,23 +119,23 @@ import fileIO from '@ohos.fileio'
export class AudioDemo { export class AudioDemo {
// Set the player callbacks. // Set the player callbacks.
setCallBack(audioPlayer) { 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'); console.info('audio set source success');
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback. 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'); console.info('audio play success');
}); });
audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete. audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.release(); // Release the AudioPlayer instance. audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
} }
async audioPlayerDemo() { async audioPlayerDemo() {
let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
this.setCallBack(audioPlayer); // Set the event callbacks. this.setCallBack(audioPlayer); // Set the event callbacks.
let fdPath = 'fd://' let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
...@@ -161,20 +161,20 @@ export class AudioDemo { ...@@ -161,20 +161,20 @@ export class AudioDemo {
// Set the player callbacks. // Set the player callbacks.
private isNextMusic = false; private isNextMusic = false;
setCallBack(audioPlayer) { 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'); console.info('audio set source success');
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback. 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'); console.info('audio play success');
audioPlayer.reset(); // Call the reset() API and trigger the 'reset' event callback. 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'); console.info('audio play success');
if (!this.isNextMusic) { // When isNextMusic is false, changing songs is implemented. if (!this.isNextMusic) { // When isNextMusic is false, changing songs is implemented.
this.nextMusic(audioPlayer); // Changing songs is implemented. this.nextMusic(audioPlayer); // Changing songs is implemented.
} else { } else {
audioPlayer.release(); // Release the AudioPlayer instance. audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
} }
}); });
...@@ -197,8 +197,8 @@ export class AudioDemo { ...@@ -197,8 +197,8 @@ export class AudioDemo {
} }
async audioPlayerDemo() { async audioPlayerDemo() {
let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
this.setCallBack(audioPlayer); // Set the event callbacks. this.setCallBack(audioPlayer); // Set the event callbacks.
let fdPath = 'fd://' let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
...@@ -223,19 +223,19 @@ import fileIO from '@ohos.fileio' ...@@ -223,19 +223,19 @@ import fileIO from '@ohos.fileio'
export class AudioDemo { export class AudioDemo {
// Set the player callbacks. // Set the player callbacks.
setCallBack(audioPlayer) { 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'); console.info('audio set source success');
audioPlayer.loop = true; // Set the loop playback attribute. audioPlayer.loop = true; // Set the loop playback attribute.
audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback. audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
}); });
audioPlayer.on('play', () => { // Set the 'play' event callback to start loop playback. audioPlayer.on('play', () => { // Set the 'play' event callback to start loop playback.
console.info('audio play success'); console.info('audio play success');
}); });
} }
async audioPlayerDemo() { async audioPlayerDemo() {
let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
this.setCallBack(audioPlayer); // Set the event callbacks. this.setCallBack(audioPlayer); // Set the event callbacks.
let fdPath = 'fd://' let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
......
# 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.|
# Ability Access Control # Ability Access Control
Provides program permission management capabilities, including authentication, authorization, and revocation. The **AbilityAccessCtrl** module provides APIs for application permission management, including authentication, authorization, and revocation.
> **NOTE** > **NOTE**
> >
...@@ -69,13 +69,43 @@ promise.then(data => { ...@@ -69,13 +69,43 @@ promise.then(data => {
}); });
``` ```
### verifyAccessTokenSync<sup>9+</sup>
verifyAccessTokenSync(tokenID: number, permissionName: string): GrantStatus
Checks whether an application has been granted the specified permission. This API synchronously returns the result.
**System capability**: SystemCapability.Security.AccessToken
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
| tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to verify.|
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
| [GrantStatus](#grantstatus) | Permission grant state.|
**Example**
```js
var AtManager = abilityAccessCtrl.createAtManager();
let tokenID = 0;
let data = verifyAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
console.log(`data->${JSON.stringify(data)}`);
```
### grantUserGrantedPermission ### grantUserGrantedPermission
grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise&lt;number&gt; grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise&lt;number&gt;
Grants a user granted permission to an application. This API uses a promise to return the result. 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 **Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
...@@ -113,7 +143,7 @@ grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFl ...@@ -113,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. 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 **Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS
...@@ -149,7 +179,7 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF ...@@ -149,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. 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 **Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
...@@ -187,7 +217,7 @@ revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionF ...@@ -187,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. 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 **Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
...@@ -223,7 +253,7 @@ getPermissionFlags(tokenID: number, permissionName: string): Promise&lt;number&g ...@@ -223,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. 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 **Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS, ohos.permission.GRANT_SENSITIVE_PERMISSIONS, or ohos.permission.REVOKE_SENSITIVE_PERMISSIONS
......
...@@ -89,7 +89,7 @@ Adds an app account name and additional information (information that can be con ...@@ -89,7 +89,7 @@ Adds an app account name and additional information (information that can be con
### addAccount ### addAccount
addAccount(name: string, extraInfo: string): Promise&lt;void&gt; addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;
Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses a promise to return the result. Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses a promise to return the result.
...@@ -100,7 +100,7 @@ Adds an app account name and additional information (information that can be con ...@@ -100,7 +100,7 @@ Adds an app account name and additional information (information that can be con
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------------------------------------- | | --------- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the app account to add. | | name | string | Yes | Name of the app account to add. |
| extraInfo | string | Yes | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.| | extraInfo | string | No | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.|
**Return value** **Return value**
...@@ -1696,7 +1696,7 @@ Checks whether an app account has specific labels. This API uses an asynchronous ...@@ -1696,7 +1696,7 @@ Checks whether an app account has specific labels. This API uses an asynchronous
| name | string | Yes | Name of the target app account. | | name | string | Yes | Name of the target app account. |
| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.|
| labels | Array&lt;string&gt; | Yes | Labels to check. | | labels | Array&lt;string&gt; | Yes | Labels to check. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. |
**Example** **Example**
...@@ -1710,7 +1710,7 @@ Checks whether an app account has specific labels. This API uses an asynchronous ...@@ -1710,7 +1710,7 @@ Checks whether an app account has specific labels. This API uses an asynchronous
### checkAccountLabels<sup>9+</sup> ### checkAccountLabels<sup>9+</sup>
checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;): Promise&lt;void&gt; checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;): Promise&lt;boolean&gt;
Checks whether an app account has specific labels. This API uses a promise to return the result. Checks whether an app account has specific labels. This API uses a promise to return the result.
...@@ -1771,7 +1771,7 @@ Selects the accounts accessible to the requester based on the options. This API ...@@ -1771,7 +1771,7 @@ Selects the accounts accessible to the requester based on the options. This API
### selectAccountsByOptions<sup>9+</sup> ### selectAccountsByOptions<sup>9+</sup>
selectAccountsByOptions(options: SelectAccountsOptions): Promise&lt;void&gt; selectAccountsByOptions(options: SelectAccountsOptions): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
Selects the accounts accessible to the requester based on the options. This API uses a promise to return the result. Selects the accounts accessible to the requester based on the options. This API uses a promise to return the result.
...@@ -1836,7 +1836,7 @@ Verifies the user credential. This API uses an asynchronous callback to return t ...@@ -1836,7 +1836,7 @@ Verifies the user credential. This API uses an asynchronous callback to return t
### verifyCredential<sup>9+</sup> ### verifyCredential<sup>9+</sup>
verifyCredential(name: string, owner: string, options, callback: AuthenticatorCallback): void; verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): void;
Verifies the user credential. This API uses an asynchronous callback to return the result. Verifies the user credential. This API uses an asynchronous callback to return the result.
...@@ -1952,10 +1952,11 @@ Defines OAuth token information. ...@@ -1952,10 +1952,11 @@ Defines OAuth token information.
**System capability**: SystemCapability.Account.AppAccount **System capability**: SystemCapability.Account.AppAccount
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------ | ---- | -------- | | -------------------- | -------------- | ----- | ---------------- |
| authType | string | Yes | Authentication type.| | authType | string | Yes | Authentication type. |
| token | string | Yes | Value of the token. | | token | string | Yes | Value of the token. |
| account<sup>9+</sup> | AppAccountInfo | No | Account information of the token.|
## AuthenticatorInfo<sup>8+</sup> ## AuthenticatorInfo<sup>8+</sup>
...@@ -1977,7 +1978,7 @@ Represents the options for selecting accounts. ...@@ -1977,7 +1978,7 @@ Represents the options for selecting accounts.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------------- | --------------------------- | ----- | ------------------- | | --------------- | --------------------------- | ----- | ------------------- |
| allowedAccounts | Array&lt;[AppAccountInfo](#appAccountinfo)&gt; | No | Allowed accounts. | | allowedAccounts | Array&lt;[AppAccountInfo](#appaccountinfo)&gt; | No | Allowed accounts. |
| allowedOwners | Array&lt;string&gt; | No | Allowed account owners.| | allowedOwners | Array&lt;string&gt; | No | Allowed account owners.|
| requiredLabels | Array&lt;string&gt; | No | Labels required for the authenticator. | | requiredLabels | Array&lt;string&gt; | No | Labels required for the authenticator. |
...@@ -2011,21 +2012,21 @@ Enumerates the constants. ...@@ -2011,21 +2012,21 @@ Enumerates the constants.
**System capability**: SystemCapability.Account.AppAccount **System capability**: SystemCapability.Account.AppAccount
| Name | Default Value | Description | | Name | Default Value | Description |
| ----------------------------- | ---------------------- | ------------- | | -------------------------------- | ---------------------- | ----------------------- |
| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation of adding an account implicitly. | | ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation of adding an account implicitly. |
| ACTION_AUTHENTICATE | "authenticate" | Authentication operation. | | ACTION_AUTHENTICATE | "authenticate" | Authentication operation. |
| KEY_NAME | "name" | App account name. | | KEY_NAME | "name" | App account name. |
| KEY_OWNER | "owner" | Owner of an app account.| | KEY_OWNER | "owner" | Owner of an app account.|
| KEY_TOKEN | "token" | Token. | | KEY_TOKEN | "token" | Token. |
| KEY_ACTION | "action" | Operation. | | KEY_ACTION | "action" | Operation. |
| KEY_AUTH_TYPE | "authType" | Authentication type. | | KEY_AUTH_TYPE | "authType" | Authentication type. |
| KEY_SESSION_ID | "sessionId" | Session ID. | | KEY_SESSION_ID | "sessionId" | Session ID. |
| KEY_CALLER_PID | "callerPid" | PID of the caller. | | KEY_CALLER_PID | "callerPid" | PID of the caller. |
| KEY_CALLER_UID | "callerUid" | UID of the caller. | | KEY_CALLER_UID | "callerUid" | UID of the caller. |
| KEY_CALLER_BUNDLE_NAME | "callerBundleName" | Bundle name of the caller. | | KEY_CALLER_BUNDLE_NAME | "callerBundleName" | Bundle name of the caller. |
| KEY_REQUIRED_LABELS | "requiredLabels" | Required labels. | | KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. |
| KEY_BOOLEAN_RESULT | "booleanResult" | Return value of the Boolean type. | | KEY_BOOLEAN_RESULT<sup>9+</sup> | "booleanResult" | Return value of the Boolean type. |
## ResultCode<sup>8+</sup> ## ResultCode<sup>8+</sup>
...@@ -2124,7 +2125,7 @@ Called to redirect a request. ...@@ -2124,7 +2125,7 @@ Called to redirect a request.
### onRequestContinued<sup>9+</sup> ### onRequestContinued<sup>9+</sup>
onRequestContinued: () =&gt; void onRequestContinued?: () =&gt; void
Called to continue to process the request. Called to continue to process the request.
......
# Want # Want
The **Want** module provides the basic communication component of the system.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Want** is the basic communication component of the system.
## Modules to Import ## Modules to Import
``` ```
...@@ -20,11 +20,96 @@ import Want from '@ohos.application.Want'; ...@@ -20,11 +20,96 @@ import Want from '@ohos.application.Want';
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | Read only | string | No | ID of the device running the ability. | | deviceId | Read only | string | No | ID of the device running the ability. |
| bundleName | Read only | string | No | Bundle name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability.| | bundleName | Read only | string | No | Bundle name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability.|
| 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.| | 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**.| | 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/***. | | 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. | | action | Read only | string | No | Action option. |
| parameters | Read only | {[key: string]: any} | No | List of parameters in the **Want** object. | | 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. | | entities | Read only | Array\<string> | No | List of entities. |
| moduleName<sup>9+</sup> | Read only | string | No | Module to which the ability belongs. Different abilities among HAP files in an application may use the same name. If the abilities cannot be distinguished by the combination of **bundleName** and **abilityName**, you can set **moduleName** for better distinguishing.| | | moduleName<sup>9+</sup> | Read only | string | No | Module to which the ability belongs.|
**Example**
- 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)
})
```
# AbilityInfo # AbilityInfo
Unless otherwise specified, ability information is obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## AbilityInfo
Provides the ability information.
**System capability**: SystemCapability.BundleManager.BundleFramework **System capability**: SystemCapability.BundleManager.BundleFramework
...@@ -25,24 +20,24 @@ Provides the ability information. ...@@ -25,24 +20,24 @@ Provides the ability information.
| iconId | number | Yes | No | Ability icon ID. | | iconId | number | Yes | No | Ability icon ID. |
| moduleName | string | Yes | No | Name of the HAP file to which the ability belongs. | | 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.| | 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. | | 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. | | 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. | | 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. | | 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. | | type | AbilityType | Yes | No | Ability type.<br>This attribute can be used only in the FA model. |
| orientation | DisplayOrientation | Yes | No | Ability display orientation. | | orientation | DisplayOrientation | Yes | No | Ability display orientation. |
| launchMode | LaunchMode | Yes | No | Ability launch mode. | | 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. | | deviceTypes | Array\<string> | Yes | No | Device types supported by the ability. |
| deviceCapabilities | Array\<string> | Yes | No | Device capabilities required for the ability. | | deviceCapabilities | Array\<string> | Yes | No | Device capabilities required for the ability. |
| readPermission | string | Yes | No | Permission required for reading the ability data. | | 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. | | 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. | | 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. | | 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. | | labelId | number | Yes | No | Ability label ID. |
| subType | AbilitySubType | Yes | No | Subtype of the template that can be used by 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. | | 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. | | 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. | | 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. | | 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. | | 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 # ElementName
The **ElementName** module provides the element name information.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the element name information.
## ElementName ## ElementName
**System capability**: SystemCapability.BundleManager.BundleFramework **System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description | | 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. |
# Metadata # Metadata
The **Metadata** module provides the metadata information.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the metadata information.
## Metadata ## Metadata
**System capability**: SystemCapability.BundleManager.BundleFramework **System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| -------- | ------ | ---- | ---- | ---------- | | -------- | ------ | ---- | ---- | ---------- |
| name | string | Yes | Yes | Metadata name.| | name | string | Yes | Yes | Metadata name.|
......
# 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 # 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> > **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 ## Modules to Import
...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean ...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported. ...@@ -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.| | 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. 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 startHCE(aidList: string[]): boolean
...@@ -39,7 +39,7 @@ Starts HCE. ...@@ -39,7 +39,7 @@ Starts HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -47,7 +47,7 @@ Starts HCE. ...@@ -47,7 +47,7 @@ Starts HCE.
| ------- | -------- | ---- | ----------------------- | | ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.| | aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.|
### stopHCE ### stopHCE<sup>8+</sup>
stopHCE(): boolean stopHCE(): boolean
...@@ -55,9 +55,9 @@ Stops HCE. ...@@ -55,9 +55,9 @@ Stops HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **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; on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -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**. | | 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).| | 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; sendResponse(responseApdu: number[]): void;
...@@ -82,7 +82,7 @@ Sends a response to the peer device. ...@@ -82,7 +82,7 @@ Sends a response to the peer device.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
......
# Active Tag # 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> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,9 +24,9 @@ Initializes the active tag chip. ...@@ -22,9 +24,9 @@ Initializes the active tag chip.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the initialization is successful; returns **false** otherwise. | | boolean | Returns **true** if the initialization is successful; returns **false** otherwise.|
## connectedTag.uninit ## connectedTag.uninit
...@@ -38,9 +40,9 @@ Uninitializes the active tag resources. ...@@ -38,9 +40,9 @@ Uninitializes the active tag resources.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.readNdefTag ## connectedTag.readNdefTag
...@@ -54,14 +56,14 @@ Reads the content of this active tag. This method uses a promise to return the r ...@@ -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 **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the content of the active tag. | | Promise&lt;string&gt; | Promise used to return the content of the active tag.|
- Example - Example
``` ```
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
connectedTag.readNdefTag().then(result => { connectedTag.readNdefTag().then(result => {
console.log("promise recv ndef response: " + 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 ...@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the active tag content obtained. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | data | string | Yes| Data to write. The maximum length is 1024 bytes.|
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. This method returns no value. | | Promise&lt;void&gt; | Promise used to return the result. This method returns no value.|
- Example - Example
``` ```
...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result.
## connectedTag.writeNdefTag ## 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. 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 ...@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | 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. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -151,7 +153,7 @@ Writes data to this active tag. This method uses an asynchronous callback to ret ...@@ -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}`); console.error(`failed to write event because ${err.code}`);
return; return;
} }
// Data is written to the tag. // Data is written to the tag.
console.log(`success to write event: ${value}`); console.log(`success to write event: ${value}`);
}); });
...@@ -168,16 +170,16 @@ Registers the NFC field strength state events. ...@@ -168,16 +170,16 @@ Registers the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | Yes | Callback invoked to return the field strength state. | | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the field strength state.|
- Enumerates the field strength states. - Enumerates the field strength states.
| **Value** | **Description** | | **Value**| **Description**|
| -------- | -------- | | -------- | -------- |
| 0 | Field off. | | 0 | Field off.|
| 1 | Field on. | | 1 | Field on.|
## connectedTag.off('notify') ## connectedTag.off('notify')
...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events. ...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | 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. | | 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 - Example
``` ```
...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events. ...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events.
console.info("nfc rf receive state: " + result); console.info("nfc rf receive state: " + result);
} }
// Register event notification // Register event notification.
connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
// Unregister event notification // Unregister event notification.
connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
``` ```
...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events. ...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events.
Enumerates the NFC states. Enumerates the NFC states.
| Name | Default Value | Description | **System capability**: SystemCapability.Communication.ConnectedTag
| -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field off. | | Name| Default Value| Description|
| NFC_RF_ENTER | 1 | Field on. | | -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field on.|
| NFC_RF_ENTER | 1 | Field on.|
# 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. |
...@@ -43,7 +43,7 @@ Obtains distributed account information. This API uses an asynchronous callback ...@@ -43,7 +43,7 @@ Obtains distributed account information. This API uses an asynchronous callback
**System capability**: SystemCapability.Account.OsAccount **System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -68,7 +68,7 @@ Obtains distributed account information. This API uses a promise to return the r ...@@ -68,7 +68,7 @@ Obtains distributed account information. This API uses a promise to return the r
**System capability**: SystemCapability.Account.OsAccount **System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
- Return value - Return value
| Type| Description| | Type| Description|
...@@ -94,7 +94,7 @@ Updates distributed account information. This API uses an asynchronous callback ...@@ -94,7 +94,7 @@ Updates distributed account information. This API uses an asynchronous callback
**System capability**: SystemCapability.Account.OsAccount **System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only to system applications) **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -119,7 +119,7 @@ Updates distributed account information. This API uses a promise to return the r ...@@ -119,7 +119,7 @@ Updates distributed account information. This API uses a promise to return the r
**System capability**: SystemCapability.Account.OsAccount **System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS (available only to system applications) **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
......
# Emitter # Emitter
> **NOTE**<br> The **Emitter** module provides APIs for sending and processing in-process events, including the APIs for processing events that are subscribed to in persistent or one-shot manner, unsubscribing from events, and emitting events to the event queue.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. > The initial APIs of this module are supported since API version 7.
## Modules to Import ## Modules to Import
...@@ -17,12 +20,14 @@ None ...@@ -17,12 +20,14 @@ None
Enumerates the event emit priority levels. Enumerates the event emit priority levels.
| Name | Value | Description | **System capability**: SystemCapability.Notification.Emitter
| --------- | ---- | ------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Value | Description |
| HIGH | 1 | The event will be emitted before low-priority events.<br>**System capability**: SystemCapability.Notification.Emitter | | --------- | ---- | ------------------------------------------------- |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.<br>**System capability**: SystemCapability.Notification.Emitter | | IMMEDIATE | 0 | The event will be emitted immediately. |
| IDLE | 3 | The event will be emitted after all the other events.<br>**System capability**: SystemCapability.Notification.Emitter | | HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## emitter.on ## emitter.on
...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return ...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve ...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -88,9 +93,9 @@ Unsubscribes from an event. ...@@ -88,9 +93,9 @@ Unsubscribes from an event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------ | | ------- | ------ | ---- | ------ |
| eventId | number | Yes | Event ID. | | eventId | number | Yes | Event ID.|
**Example** **Example**
...@@ -108,10 +113,10 @@ Emits an event to the event queue. ...@@ -108,10 +113,10 @@ Emits an event to the event queue.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------- | ---- | -------------- | | ------ | ------------------------- | ---- | -------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to emit. | | event | [InnerEvent](#innerevent) | Yes | Event to emit. |
| data | [EventData](#eventdata) | No | Data carried by the event. | | data | [EventData](#eventdata) | No | Data carried by the event.|
**Example** **Example**
...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData); ...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData);
## InnerEvent ## InnerEvent
Describes an intra-process event. Describes an in-process event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Type | Readable| Writable| Description |
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event.<br>**System capability**: SystemCapability.Notification.Emitter | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData ## EventData
Describes the data passed in the event. Describes the data passed in the event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.<br>**System capability**: SystemCapability.Notification.Emitter | | Name| Type | Readable| Writable| Description |
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.|
# User File Access and Management # 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/> >**NOTE**<br/>
> >
...@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This ...@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This
**Example** **Example**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfos) => {
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}); });
...@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This ...@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This
"name":"local" "name":"local"
} }
}; };
filemanager.getRoot(options, (err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfos)=>{
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
...@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example** **Example**
```js ```js
// Obtain all files in the directory. // Obtain all files in the directory. You can use getRoot to obtain the directory URI.
// Call listFile() and getRoot() to obtain the file URI. filemanager.getRoot().then((fileInfos) => {
let media_path = "" let file = fileInfos.find(item => item.name == "file_folder");
filemanager.listFile(media_path, "file") let path = file.path;
.then((fileInfo) => { filemanager.listFile(path, "file").then((files) => {
if(Array.isArray(fileInfo)) { console.log("files:" + JSON.stringify(files));
for (var i = 0; i < fileInfo.length; i++) { }).catch((err) => {
console.log("file:"+JSON.stringify(fileInfo)); console.log("failed to get files" + err);
} });
}
}).catch((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. ...@@ -153,33 +147,18 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example** **Example**
```js ```js
// Call listFile() and getRoot() to obtain the file path. // Obtain all files in the directory. You can use getRoot to obtain the directory URI.
let fileInfos = filemanager.getRoot(); filemanager.getRoot().then((fileInfos) => {
let media_path = ""; let file = fileInfos.find(item => item.name == "image_album");
for (let i = 0; i < fileInfos.length; i++) { let path = file.path;
if (fileInfos[i].name == "image_album") { filemanager.listFile(path, "image",function(err, files){
media_path = fileInfos[i].path; console.log("files:" + JSON.stringify(files));
} else if (fileInfos[i].name == "audio_album") { })
media_path = fileInfos[i].path; }).catch((err) => {
} else if (fileInfos[i].name == "video_album") { console.log("failed to get root" + err);
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);
});
```
## filemanager.createFile ## filemanager.createFile
......
...@@ -247,11 +247,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ...@@ -247,11 +247,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono
### displayOptionalInputMethod ### displayOptionalInputMethod
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
......
# Standard NFC # Standard NFC
Implements Near-Field Communication (NFC). The **nfcController** module implements Near-Field Communication (NFC).
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean ...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean
Checks whether NFC is available. Checks whether NFC is available.
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
...@@ -34,7 +36,7 @@ Opens NFC. ...@@ -34,7 +36,7 @@ Opens NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -50,7 +52,7 @@ Closes NFC. ...@@ -50,7 +52,7 @@ Closes NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -64,7 +66,7 @@ isNfcOpen(): boolean ...@@ -64,7 +66,7 @@ isNfcOpen(): boolean
Checks whether NFC is open. Checks whether NFC is open.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -78,7 +80,7 @@ getNfcState(): NfcState ...@@ -78,7 +80,7 @@ getNfcState(): NfcState
Obtains the NFC state. Obtains the NFC state.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void ...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void
Subscribes to NFC state changes. Subscribes to NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void ...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void
Unsubscribes from the NFC state changes. Unsubscribes from the NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes. ...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes.
Enumerates the NFC states. Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Default Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | Off| | STATE_OFF | 1 | Off|
......
# Standard NFC Tag # Standard NFC Tag
Manages Near-Field Communication (NFC) tags. The **nfcTag** module provides methods for managing Near-Field Communication (NFC) tags.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags. ...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags.
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
``` ```
## tag.getNfcATag ## tag.getNfcATag
getNfcATag(tagInfo: TagInfo): NfcATag getNfcATag(tagInfo: TagInfo): NfcATag
...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC- ...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC- ...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC- ...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC- ...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| NfcVTag | **NfcVTag** object obtained.| | NfcVTag | **NfcVTag** object obtained.|
...@@ -21,7 +21,7 @@ getUriSync(name: string): string ...@@ -21,7 +21,7 @@ getUriSync(name: string): string
Obtains the URI of a data item. Obtains the URI of a data item.
**System capability**: SystemCapability.Applictaions.settings.Core **System capability**: SystemCapability.Applications.settings.Core
**Parameters** **Parameters**
...@@ -50,7 +50,7 @@ getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: strin ...@@ -50,7 +50,7 @@ getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: strin
Obtains the value of a data item. Obtains the value of a data item.
**System capability**: SystemCapability.Applictaions.settings.Core **System capability**: SystemCapability.Applications.settings.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -87,7 +87,7 @@ If the specified data item exists in the database, the **setValueSync** method u ...@@ -87,7 +87,7 @@ If the specified data item exists in the database, the **setValueSync** method u
**Required permissions**: ohos.permission.MODIFY_SETTINGS **Required permissions**: ohos.permission.MODIFY_SETTINGS
**System capability**: SystemCapability.Applictaions.settings.Core **System capability**: SystemCapability.Applications.settings.Core
**Parameters** **Parameters**
......
...@@ -136,7 +136,7 @@ zlib.unzipFile(inFile, outFile, options).then((data) => { ...@@ -136,7 +136,7 @@ zlib.unzipFile(inFile, outFile, options).then((data) => {
| Name | Value | Description | | Name | Value | Description |
| ----------------- | ---- | -------------------------------- | | ----------------- | ---- | -------------------------------- |
| MEM_LEVEL_MIN | 1 | Minimum memory used by the **zip** API during compression.| | MEM_LEVEL_MIN | 1 | Minimum memory used by the **zip** API during compression.|
| MEM_LEVEL_MIN | 9 | Maximum memory used by the **zip** API during compression.| | MEM_LEVEL_MAX | 9 | Maximum memory used by the **zip** API during compression.|
| MEM_LEVEL_DEFAULT | 8 | Default memory used by the **zip** API during compression.| | MEM_LEVEL_DEFAULT | 8 | Default memory used by the **zip** API during compression.|
## zip.CompressLevel ## zip.CompressLevel
......
...@@ -91,7 +91,11 @@ struct ProgressExample { ...@@ -91,7 +91,11 @@ struct ProgressExample {
Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50) Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100).height(50) Progress({ value: 20, total: 150, type: ProgressType.Capsule })
.color(Color.Grey)
.value(50)
.width(100)
.height(50)
} }
}.width('100%').margin({ top: 30 }) }.width('100%').margin({ top: 30 })
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册