提交 8a70aed3 编写于 作者: 小马奔腾 提交者: Gitee

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

Signed-off-by: N小马奔腾 <maxiaodong16@huawei.com>

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
此差异已折叠。
...@@ -6,20 +6,20 @@ The Distributed Data Service (DDS) implements synchronization of application dat ...@@ -6,20 +6,20 @@ The Distributed Data Service (DDS) implements synchronization of application dat
## Available APIs ## Available APIs
For details about the APIs, see [Distributed Data Management](../reference/apis/js-apis-distributed-data.md).
For details about the APIs, see [Distributed KV Store](../reference/apis/js-apis-distributedKVStore.md).
**Table 1** APIs provided by the DDS **Table 1** APIs provided by the DDS
| API | Description | | API | Description |
| ------------------------------------------------------------ | ----------------------------------------------- | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KVManager** object for database management.| | createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KvManager** object for database management. |
| getKVStore&lt;TextendsKVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;TextendsKVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Obtains a KV store with the specified **Options** and **storeId**.| | 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; | Creates and obtains a 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. |
| 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. |
| 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. |
| 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. |
| 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. |
## How to Develop ## How to Develop
...@@ -28,23 +28,25 @@ The following uses a single KV store as an example to describe the development p ...@@ -28,23 +28,25 @@ The following uses a single KV store as an example to describe the development p
1. Import the distributed data module. 1. Import the distributed data module.
```js ```js
import distributedData from '@ohos.data.distributedData'; import distributedKVStore from '@ohos.data.distributedKVStore';
``` ```
2. Apply for the required permission if data synchronization is required. 2. Apply for the required permission if data synchronization is required.
Add the permission required (FA model) in the **config.json** file. The sample code is as follows: Add the permission required (FA model) in the **config.json** file. The sample code is as follows:
```json ```json
{ {
"module": { "module": {
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.DISTRIBUTED_DATASYNC" "name": "ohos.permission.DISTRIBUTED_DATASYNC"
} }
] ]
} }
} }
``` ```
For the apps based on the stage model, see [Declaring Permissions](../security/accesstoken-guidelines.md#stage-model). For the apps based on the stage model, see [Declaring Permissions](../security/accesstoken-guidelines.md#stage-model).
This permission must also be granted by the user when the application is started for the first time. The sample code is as follows: This permission must also be granted by the user when the application is started for the first time. The sample code is as follows:
...@@ -52,7 +54,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -52,7 +54,7 @@ The following uses a single KV store as an example to describe the development p
```js ```js
// FA model // FA model
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() { function grantPermission() {
console.info('grantPermission'); console.info('grantPermission');
let context = featureAbility.getContext(); let context = featureAbility.getContext();
...@@ -62,21 +64,21 @@ The following uses a single KV store as an example to describe the development p ...@@ -62,21 +64,21 @@ The following uses a single KV store as an example to describe the development p
console.info('failed: ${error}'); console.info('failed: ${error}');
}) })
} }
grantPermission(); grantPermission();
// Stage model // Stage model
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
let context = null; let context = null;
function grantPermission() { function grantPermission() {
class MainAbility extends Ability { class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
let context = this.context; let context = this.context;
} }
} }
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC']; let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => { context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}'); console.log('success: ${data}');
...@@ -84,14 +86,14 @@ The following uses a single KV store as an example to describe the development p ...@@ -84,14 +86,14 @@ The following uses a single KV store as an example to describe the development p
console.log('failed: ${error}'); console.log('failed: ${error}');
}); });
} }
grantPermission(); grantPermission();
``` ```
3. Create a **kvManager** instance based on the specified **kvManagerConfig** object. 3. 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:
...@@ -99,7 +101,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -99,7 +101,7 @@ The following uses a single KV store as an example to describe the development p
// Obtain the context of the FA model. // Obtain the context of the FA model.
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
// Obtain the context of the stage model. // Obtain the context of the stage model.
import AbilityStage from '@ohos.application.Ability'; import AbilityStage from '@ohos.application.Ability';
let context = null; let context = null;
...@@ -108,27 +110,23 @@ The following uses a single KV store as an example to describe the development p ...@@ -108,27 +110,23 @@ The following uses a single KV store as an example to describe the development p
context = this.context; context = this.context;
} }
} }
let kvManager; let kvManager;
try { try {
const kvManagerConfig = { const kvManagerConfig = {
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
userInfo: { context:context,
context:context,
userId: '0',
userType: distributedData.UserType.SAME_USER_ID
}
} }
distributedData.createKVManager(kvManagerConfig, function (err, manager) { distributedKVStore.createKVManager(kvManagerConfig, function (err, manager) {
if (err) { if (err) {
console.log('Failed to create KVManager: ${error}'); console.error(`Failed to create KVManager.code is ${err.code},message is ${err.message}`);
return; return;
} }
console.log('Created KVManager successfully'); console.log('Created KVManager successfully');
kvManager = manager; kvManager = manager;
}); });
} catch (e) { } catch (e) {
console.log('An unexpected error occurred. Error: ${e}'); console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`);
} }
``` ```
...@@ -147,34 +145,38 @@ The following uses a single KV store as an example to describe the development p ...@@ -147,34 +145,38 @@ The following uses a single KV store as an example to describe the development p
encrypt: false, encrypt: false,
backup: false, backup: false,
autoSync: false, autoSync: false,
kvStoreType: distributedData.KVStoreType.SINGLE_VERSION, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
securityLevel: distributedData.SecurityLevel.S0 securityLevel: distributedKVStore.SecurityLevel.S1
}; };
kvManager.getKVStore('storeId', options, function (err, store) { kvManager.getKVStore('storeId', options, function (err, store) {
if (err) { if (err) {
console.log('Failed to get KVStore: ${err}'); console.error(`Failed to get KVStore: code is ${err.code},message is ${err.message}`);
return; return;
} }
console.log('Got KVStore successfully'); console.log('Obtained KVStore successfully');
kvStore = store; kvStore = store;
}); });
} catch (e) { } catch (e) {
console.log('An unexpected error occurred. Error: ${e}'); console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`);
} }
``` ```
> **NOTE**<br> > **NOTE**<br>
> >
> For data synchronization between networked devices, you are advised to open the distributed KV store during application startup to obtain the database handle. With this database handle (`kvStore` in this example), you can perform operations, such as inserting data into the KV store, without creating the KV store repeatedly during the lifecycle of the handle. > 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.
5. Subscribe to changes in the distributed data. 5. Subscribe to changes in the distributed data.
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:
```js ```js
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { try{
console.log("dataChange callback call data: ${data}"); kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
}); console.log(`dataChange callback call data: ${data}`);
});
}catch(e){
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`);
}
``` ```
6. Write data to the single KV store. 6. Write data to the single KV store.
...@@ -188,15 +190,15 @@ The following uses a single KV store as an example to describe the development p ...@@ -188,15 +190,15 @@ The following uses a single KV store as an example to describe the development p
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.log('Failed to put data: ${error}'); console.error(`Failed to put.code is ${err.code},message is ${err.message}`);
return; return;
} }
console.log('Put data successfully'); console.log('Put data successfully');
}); });
} catch (e) { }catch (e) {
console.log('An unexpected error occurred. Error: ${e}'); console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`);
} }
``` ```
...@@ -211,18 +213,22 @@ The following uses a single KV store as an example to describe the development p ...@@ -211,18 +213,22 @@ The following uses a single KV store as an example to describe the development p
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.log('Failed to put data: ${error}'); console.error(`Failed to put.code is ${err.code},message is ${err.message}`);
return; return;
} }
console.log('Put data successfully'); console.log('Put data successfully');
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) { kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log('Got data successfully: ${data}'); if (err != undefined) {
console.error(`Failed to get data.code is ${err.code},message is ${err.message}`);
return;
}
console.log(`Obtained data successfully:${data}`);
}); });
}); });
} catch (e) { }catch (e) {
console.log('An unexpected error occurred. Error: ${e}'); console.error(`Failed to get.code is ${e.code},message is ${e.message}`);
} }
``` ```
...@@ -233,7 +239,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -233,7 +239,7 @@ The following uses a single KV store as an example to describe the development p
> **NOTE**<br> > **NOTE**<br>
> >
> The APIs of the `deviceManager` module are system interfaces. > The APIs of the `deviceManager` module are system interfaces.
The following is the example code for synchronizing data in a single KV store: The following is the example code for synchronizing data in a single KV store:
```js ```js
...@@ -254,9 +260,9 @@ The following uses a single KV store as an example to describe the development p ...@@ -254,9 +260,9 @@ 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. // 1000 indicates that the maximum delay is 1000 ms.
kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000); kvStore.sync(deviceIds, distributedKVStore.SyncMode.PUSH_ONLY, 1000);
} catch (e) { } catch (e) {
console.log('An unexpected error occurred. Error: ${e}'); console.error(`An unexpected error occurred. code is ${e.code},message is ${e.message}`);
} }
} }
}); });
......
...@@ -14,6 +14,8 @@ The sample server provides a package search server for checking update packages ...@@ -14,6 +14,8 @@ The sample server provides a package search server for checking update packages
openssl req -newkey rsa:2048 -nodes -keyout serverKey.pem -x509 -days 365 -out serverCert.cer -subj "/C=CN/ST=GD/L=GZ/O=abc/OU=defg/CN=hijk/emailAddress=test.com" openssl req -newkey rsa:2048 -nodes -keyout serverKey.pem -x509 -days 365 -out serverCert.cer -subj "/C=CN/ST=GD/L=GZ/O=abc/OU=defg/CN=hijk/emailAddress=test.com"
``` ```
2. Modify the **bundle.json** file. 2. Modify the **bundle.json** file.
Add **sub_component** to the **build** field. Add **sub_component** to the **build** field.
...@@ -173,7 +175,7 @@ The sample server provides a package search server for checking update packages ...@@ -173,7 +175,7 @@ The sample server provides a package search server for checking update packages
"\"descriptPackageId\": \"abcdefg1234567ABCDEFG\"," "\"descriptPackageId\": \"abcdefg1234567ABCDEFG\","
"}]," "}],"
"\"descriptInfo\": [{" "\"descriptInfo\": [{"
"\"descriptPackageId\": \"abcdefg1234567ABCDEFG\"," "\"descriptionType\": 0,"
"\"content\": \"This package message is used for sampleContent\"" "\"content\": \"This package message is used for sampleContent\""
"}]" "}]"
"}"; "}";
......
...@@ -30,7 +30,7 @@ The following is an example of the JSON response returned by the server. Note th ...@@ -30,7 +30,7 @@ The following is an example of the JSON response returned by the server. Note th
"descriptPackageId": "abcdefg1234567ABCDEFG" "descriptPackageId": "abcdefg1234567ABCDEFG"
}], }],
"descriptInfo": [{ "descriptInfo": [{
"descriptPackageId": "abcdefg1234567ABCDEFG", "descriptionType": 0,
"content": "This package is used for update." "content": "This package is used for update."
}] }]
} }
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
## Introduction ## Introduction
You can use audio playback APIs to convert audio data into audible analog signals and play the signals using output devices. You can also manage playback tasks. For example, you can start, suspend, stop playback, release resources, set the volume, seek to a playback position, and obtain track information. You can use audio playback APIs to convert audio data into audible analog signals and play the signals using output devices. You can also manage playback tasks. For example, you can control the playback and volume, obtain track information, and release resources.
## Working Principles ## Working Principles
The following figures show the audio playback status changes and the interaction with external modules for audio playback. The following figures show the audio playback state transition and the interaction with external modules for audio playback.
**Figure 1** Audio playback state transition **Figure 1** Audio playback state transition
...@@ -28,7 +28,7 @@ For details about the APIs, see [AudioPlayer in the Media API](../reference/apis ...@@ -28,7 +28,7 @@ For details about the APIs, see [AudioPlayer in the Media API](../reference/apis
> **NOTE** > **NOTE**
> >
> The method for obtaining the path in the FA model is different from that in the stage model. **pathDir** used in the sample code below is an example. You need to obtain the path based on project requirements. For details about how to obtain the path, see [Application Sandbox Path Guidelines](../reference/apis/js-apis-fileio.md#guidelines). > The method for obtaining the path in the FA model is different from that in the stage model. For details about how to obtain the path, see [Application Sandbox Path Guidelines](../reference/apis/js-apis-fileio.md#guidelines).
### Full-Process Scenario ### Full-Process Scenario
...@@ -109,7 +109,7 @@ async function audioPlayerDemo() { ...@@ -109,7 +109,7 @@ async function audioPlayerDemo() {
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://'
let pathDir = "/data/storage/el2/base/haps/entry/files" // The method for obtaining pathDir in the FA model is different from that in the stage model. For details, see NOTE just below How to Develop. You need to obtain pathDir based on project requirements. let pathDir = "/data/storage/el2/base/haps/entry/files" // The path used here is an example. Obtain the path based on project requirements.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command.
let path = pathDir + '/01.mp3' let path = pathDir + '/01.mp3'
await fileIO.open(path).then((fdNumber) => { await fileIO.open(path).then((fdNumber) => {
...@@ -151,7 +151,7 @@ export class AudioDemo { ...@@ -151,7 +151,7 @@ export class AudioDemo {
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://'
let pathDir = "/data/storage/el2/base/haps/entry/files" // The method for obtaining pathDir in the FA model is different from that in the stage model. For details, see NOTE just below How to Develop. You need to obtain pathDir based on project requirements. let pathDir = "/data/storage/el2/base/haps/entry/files" // The path used here is an example. Obtain the path based on project requirements.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command.
let path = pathDir + '/01.mp3' let path = pathDir + '/01.mp3'
await fileIO.open(path).then((fdNumber) => { await fileIO.open(path).then((fdNumber) => {
...@@ -199,7 +199,7 @@ export class AudioDemo { ...@@ -199,7 +199,7 @@ export class AudioDemo {
async nextMusic(audioPlayer) { async nextMusic(audioPlayer) {
this.isNextMusic = true; this.isNextMusic = true;
let nextFdPath = 'fd://' let nextFdPath = 'fd://'
let pathDir = "/data/storage/el2/base/haps/entry/files" // The method for obtaining pathDir in the FA model is different from that in the stage model. For details, see NOTE just below How to Develop. You need to obtain pathDir based on project requirements. let pathDir = "/data/storage/el2/base/haps/entry/files" // The path used here is an example. Obtain the path based on project requirements.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command.
let nextpath = pathDir + '/02.mp3' let nextpath = pathDir + '/02.mp3'
await fileIO.open(nextpath).then((fdNumber) => { await fileIO.open(nextpath).then((fdNumber) => {
...@@ -217,7 +217,7 @@ export class AudioDemo { ...@@ -217,7 +217,7 @@ export class AudioDemo {
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://'
let pathDir = "/data/storage/el2/base/haps/entry/files" // The method for obtaining pathDir in the FA model is different from that in the stage model. For details, see NOTE just below How to Develop. You need to obtain pathDir based on project requirements. let pathDir = "/data/storage/el2/base/haps/entry/files" // The path used here is an example. Obtain the path based on project requirements.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command.
let path = pathDir + '/01.mp3' let path = pathDir + '/01.mp3'
await fileIO.open(path).then((fdNumber) => { await fileIO.open(path).then((fdNumber) => {
...@@ -256,7 +256,7 @@ export class AudioDemo { ...@@ -256,7 +256,7 @@ export class AudioDemo {
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://'
let pathDir = "/data/storage/el2/base/haps/entry/files" // The method for obtaining pathDir in the FA model is different from that in the stage model. For details, see NOTE just below How to Develop. You need to obtain pathDir based on project requirements. let pathDir = "/data/storage/el2/base/haps/entry/files" // The path used here is an example. Obtain the path based on project requirements.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command. // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioplayer/haps/entry/files" command.
let path = pathDir + '/01.mp3' let path = pathDir + '/01.mp3'
await fileIO.open(path).then((fdNumber) => { await fileIO.open(path).then((fdNumber) => {
......
...@@ -81,6 +81,9 @@ for (let index = 0; index < cameraArray.length; index++) { ...@@ -81,6 +81,9 @@ for (let index = 0; index < cameraArray.length; index++) {
// Create a camera input stream. // Create a camera input stream.
let cameraInput = await cameraManager.createCameraInput(cameraArray[0]) let cameraInput = await cameraManager.createCameraInput(cameraArray[0])
// Open camera
await cameraInput.open();
// Obtain the output stream capabilities supported by the camera. // Obtain the output stream capabilities supported by the camera.
let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]); let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
if (!cameraOutputCap) { if (!cameraOutputCap) {
......
# APIs # APIs
- [API Reference Document Description](development-intro.md) - [API Reference Document Description](development-intro.md)
- Ability Framework - Ability Framework
- FA Model - Stage Model (Recommended)
- [@ohos.ability.featureAbility](js-apis-featureAbility.md) - [@ohos.app.ability.Ability](js-apis-app-ability-ability.md)
- [@ohos.ability.particleAbility](js-apis-particleAbility.md) - [@ohos.app.ability.AbilityConstant](js-apis-app-ability-abilityConstant.md)
- ability/[dataAbilityHelper](js-apis-dataAbilityHelper.md) - [@ohos.app.ability.abilityLifecycleCallback](js-apis-app-ability-abilityLifecycleCallback.md)
- app/[context](js-apis-Context.md) - [@ohos.app.ability.AbilityStage](js-apis-app-ability-abilityStage.md)
- Stage Model - [@ohos.app.ability.common](js-apis-app-ability-common.md)
- [@ohos.application.Ability](js-apis-application-ability.md) - [@ohos.app.ability.contextConstant](js-apis-app-ability-contextConstant.md)
- [@ohos.application.AbilityConstant](js-apis-application-abilityConstant.md) - [@ohos.app.ability.EnvironmentCallback](js-apis-app-ability-environmentCallback.md)
- [@ohos.application.AbilityStage](js-apis-application-abilitystage.md) - [@ohos.app.ability.ExtensionAbility](js-apis-app-ability-extensionAbility.md)
- [@ohos.application.abilityLifecycleCallback](js-apis-application-abilityLifecycleCallback.md) - [@ohos.app.ability.ServiceExtensionAbility](js-apis-app-ability-serviceExtensionAbility.md)
- [@ohos.app.ability.StartOptions](js-apis-app-ability-startOptions.md)
- [@ohos.app.ability.UIAbility](js-apis-app-ability-uiAbility.md)
- [@ohos.app.form.FormExtensionAbility](js-apis-app-form-formExtensionAbility.md)
- [@ohos.application.DataShareExtensionAbility](js-apis-application-DataShareExtensionAbility.md) - [@ohos.application.DataShareExtensionAbility](js-apis-application-DataShareExtensionAbility.md)
- [@ohos.application.EnvironmentCallback](js-apis-application-EnvironmentCallback.md)
- [@ohos.application.FormExtension](js-apis-formextension.md)
- [@ohos.application.ServiceExtensionAbility](js-apis-service-extension-ability.md)
- [@ohos.application.StartOptions](js-apis-application-StartOptions.md)
- [@ohos.application.StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md) - [@ohos.application.StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md)
- [@ohos.application.WindowExtensionAbility](js-apis-application-WindowExtensionAbility.md) - Stage Model (To Be Deprecated Soon)
- application/[AbilityContext](js-apis-ability-context.md) - [@ohos.application.Ability](js-apis-application-ability.md)
- application/[ApplicationContext](js-apis-application-applicationContext.md) - [@ohos.application.AbilityConstant](js-apis-application-abilityConstant.md)
- application/[AbilityStageContext](js-apis-abilitystagecontext.md) - [@ohos.application.AbilityLifecycleCallback](js-apis-application-abilityLifecycleCallback.md)
- application/[Context](js-apis-application-context.md) - [@ohos.application.AbilityStage](js-apis-application-abilityStage.md)
- application/[ExtensionContext](js-apis-extension-context.md) - [@ohos.application.context](js-apis-application-context.md)
- application/[FormExtensionContext](js-apis-formextensioncontext.md) - [@ohos.application.EnvironmentCallback](js-apis-application-environmentCallback.md)
- application/[PermissionRequestResult](js-apis-permissionrequestresult.md) - [@ohos.application.ExtensionAbility](js-apis-application-extensionAbility.md)
- application/[ServiceExtensionContext](js-apis-service-extension-context.md) - [@ohos.application.FormExtension](js-apis-application-formExtension.md)
- FA and Stage Models - [@ohos.application.ServiceExtensionAbility](js-apis-application-serviceExtensionAbility.md)
- [@ohos.ability.dataUriUtils](js-apis-DataUriUtils.md) - [@ohos.application.StartOptions](js-apis-application-startOptions.md)
- FA Model
- [@ohos.ability.ability](js-apis-ability-ability.md)
- [@ohos.ability.featureAbility](js-apis-ability-featureAbility.md)
- [@ohos.ability.particleAbility](js-apis-ability-particleAbility.md)
- Both Models (Recommended)
- [@ohos.app.ability.abilityDelegatorRegistry](js-apis-app-ability-abilityDelegatorRegistry.md)
- [@ohos.app.ability.abilityManager](js-apis-app-ability-abilityManager.md)
- [@ohos.app.ability.appManager](js-apis-app-ability-appManager.md)
- [@ohos.app.ability.appRecovery](js-apis-app-ability-appRecovery.md)
- [@ohos.app.ability.Configuration](js-apis-app-ability-configuration.md)
- [@ohos.app.ability.ConfigurationConstant](js-apis-app-ability-configurationConstant.md)
- [@ohos.app.ability.dataUriUtils](js-apis-app-ability-dataUriUtils.md)
- [@ohos.app.ability.errorManager](js-apis-app-ability-errorManager.md)
- [@ohos.app.ability.missionManager](js-apis-app-ability-missionManager.md)
- [@ohos.app.ability.quickFixManager](js-apis-app-ability-quickFixManager.md)
- [@ohos.app.ability.Want](js-apis-app-ability-want.md)
- [@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md)
- [@ohos.app.ability.wantConstant](js-apis-app-ability-wantConstant.md)
- [@ohos.app.form.formBindingData](js-apis-app-form-formBindingData.md)
- [@ohos.app.form.formHost](js-apis-app-form-formHost.md)
- [@ohos.app.form.formInfo](js-apis-app-form-formInfo.md)
- [@ohos.app.form.formProvider](js-apis-app-form-formProvider.md)
- Both Models (To Be Deprecated Soon)
- [@ohos.ability.dataUriUtils](js-apis-ability-dataUriUtils.md)
- [@ohos.ability.errorCode](js-apis-ability-errorCode.md) - [@ohos.ability.errorCode](js-apis-ability-errorCode.md)
- [@ohos.ability.wantConstant](js-apis-ability-wantConstant.md) - [@ohos.ability.wantConstant](js-apis-ability-wantConstant.md)
- [@ohos.application.abilityDelegatorRegistry](js-apis-abilityDelegatorRegistry.md) - [@ohos.application.abilityDelegatorRegistry](js-apis-application-abilityDelegatorRegistry.md)
- [@ohos.application.abilityManager](js-apis-application-abilityManager.md) - [@ohos.application.abilityManager](js-apis-application-abilityManager.md)
- [@ohos.application.appManager](js-apis-appmanager.md) - [@ohos.application.appManager](js-apis-application-appManager.md)
- [@ohos.application.errorManager](js-apis-errorManager.md) - [@ohos.application.Configuration](js-apis-application-configuration.md)
- [@ohos.application.formBindingData](js-apis-formbindingdata.md) - [@ohos.application.ConfigurationConstant](js-apis-application-configurationConstant.md)
- [@ohos.application.formError](js-apis-formerror.md) - [@ohos.application.errorManager)](js-apis-application-errorManager.md)
- [@ohos.application.formHost](js-apis-formhost.md) - [@ohos.application.formBindingData](js-apis-application-formBindingData.md)
- [@ohos.application.formInfo](js-apis-formInfo.md) - [@ohos.application.formError](js-apis-application-formError.md)
- [@ohos.application.formProvider](js-apis-formprovider.md) - [@ohos.application.formHost](js-apis-application-formHost.md)
- [@ohos.application.missionManager](js-apis-missionManager.md) - [@ohos.application.formInfo](js-apis-application-formInfo.md)
- [@ohos.application.quickFixManager](js-apis-application-quickFixManager.md) - [@ohos.application.formProvider](js-apis-application-formProvider.md)
- [@ohos.application.Want](js-apis-application-Want.md) - [@ohos.application.missionManager](js-apis-application-missionManager.md)
- [@ohos.continuation.continuationManager](js-apis-continuation-continuationManager.md) - [@ohos.application.Want](js-apis-application-want.md)
- [@ohos.wantAgent](js-apis-wantAgent.md) - [@ohos.wantAgent](js-apis-wantAgent.md)
- application/[abilityDelegator](js-apis-application-abilityDelegator.md) - Dependent Elements and Definitions
- application/[abilityDelegatorArgs](js-apis-application-abilityDelegatorArgs.md) - ability
- application/[abilityMonitor](js-apis-application-abilityMonitor.md) - [abilityResult](js-apis-inner-ability-abilityResult.md)
- application/[AbilityRunningInfo](js-apis-abilityrunninginfo.md) - [connectOptions](js-apis-inner-ability-connectOptions.md)
- application/[ExtensionRunningInfo](js-apis-extensionrunninginfo.md) - [dataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md)
- application/[MissionSnapshot](js-apis-application-MissionSnapshot.md) - [dataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)
- application/[ProcessRunningInformation](js-apis-processrunninginformation.md) - [dataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)
- application/[shellCmdResult](js-apis-application-shellCmdResult.md) - [startAbilityParameter](js-apis-inner-ability-startAbilityParameter.md)
- continuation/[continuationExtraParams](js-apis-continuation-continuationExtraParams.md) - [want](js-apis-inner-ability-want.md)
- continuation/[ContinuationResult](js-apis-continuation-continuationResult.md) - app
- [appVersionInfo](js-apis-inner-app-appVersionInfo.md)
- [context](js-apis-inner-app-context.md)
- [processInfo](js-apis-inner-app-processInfo.md)
- application
- [AbilityContext](js-apis-ability-context.md)
- [abilityDelegator](js-apis-inner-application-abilityDelegator.md)
- [abilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)
- [abilityMonitor](js-apis-inner-application-abilityMonitor.md)
- [AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)
- [AbilityStageContext](js-apis-inner-application-abilityStageContext.md)
- [AbilityStateData](js-apis-inner-application-abilityStateData.md)
- [abilityStageMonitor](js-apis-inner-application-abilityStageMonitor.md)
- [ApplicationContext](js-apis-inner-application-applicationContext.md)
- [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md)
- [AppStateData](js-apis-inner-application-appStateData.md)
- [BaseContext](js-apis-inner-application-baseContext.md)
- [Context](js-apis-inner-application-context.md)
- [ContinueCallback](js-apis-inner-application-continueCallback.md)
- [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo.md)
- [ErrorObserver](js-apis-inner-application-errorObserver.md)
- [ExtensionContext](js-apis-inner-application-extensionContext.md)
- [ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)
- [FormExtensionContext](js-apis-inner-application-formExtensionContext.md)
- [MissionCallbacks](js-apis-inner-application-missionCallbacks.md)
- [MissionDeviceInfo](js-apis-inner-application-missionDeviceInfo.md)
- [MissionInfo](js-apis-inner-application-missionInfo.md)
- [MissionListener](js-apis-inner-application-missionListener.md)
- [MissionParameter](js-apis-inner-application-missionParameter.md)
- [MissionSnapshot](js-apis-inner-application-missionSnapshot.md)
- [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md)
- [ProcessData](js-apis-inner-application-processData.md)
- [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)
- [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)
- [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md)
- [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md)
- [shellCmdResult](js-apis-inner-application-shellCmdResult.md)
- wantAgent
- [triggerInfo](js-apis-inner-wantAgent-triggerInfo.md)
- [wantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md)
- Continuation
- [@ohos.continuation.continuationManager (continuationManager)](js-apis-continuation-continuationManager.md)
- continuation
- [continuationExtraParams](js-apis-continuation-continuationExtraParams.md)
- [continuationResult](js-apis-continuation-continuationResult.md)
- Common Event and Notification - Common Event and Notification
- [@ohos.events.emitter](js-apis-emitter.md) - [@ohos.events.emitter](js-apis-emitter.md)
- [@ohos.notification](js-apis-notification.md) - [@ohos.notification](js-apis-notification.md)
- application/[EventHub](js-apis-eventhub.md) - application/[EventHub](js-apis-inner-application-eventHub.md)
- Bundle Management - Bundle Management
- [@ohos.bundle.appControl](js-apis-appControl.md) - [@ohos.bundle.appControl](js-apis-appControl.md)
- [@ohos.bundle.bundleManager](js-apis-bundleManager.md) - [@ohos.bundle.bundleManager](js-apis-bundleManager.md)
...@@ -69,19 +138,20 @@ ...@@ -69,19 +138,20 @@
- [@ohos.bundle.installer](js-apis-installer.md) - [@ohos.bundle.installer](js-apis-installer.md)
- [@ohos.bundle.launcherBundleManager](js-apis-launcherBundleManager.md) - [@ohos.bundle.launcherBundleManager](js-apis-launcherBundleManager.md)
- [@ohos.zlib](js-apis-zlib.md) - [@ohos.zlib](js-apis-zlib.md)
- bundleManager/[abilityInfo](js-apis-bundleManager-abilityInfo.md) - bundleManager
- bundleManager/[applicationInfo](js-apis-bundleManager-applicationInfo.md) - [abilityInfo](js-apis-bundleManager-abilityInfo.md)
- bundleManager/[bundleInfo](js-apis-bundleManager-bundleInfo.md) - [applicationInfo](js-apis-bundleManager-applicationInfo.md)
- bundleManager/[dispatchInfo](js-apis-bundleManager-dispatchInfo.md) - [bundleInfo](js-apis-bundleManager-bundleInfo.md)
- bundleManager/[elementName](js-apis-bundleManager-elementName.md) - [dispatchInfo](js-apis-bundleManager-dispatchInfo.md)
- bundleManager/[extensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md) - [elementName](js-apis-bundleManager-elementName.md)
- bundleManager/[hapModuleInfo](js-apis-bundleManager-hapModuleInfo.md) - [extensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)
- bundleManager/[launcherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md) - [hapModuleInfo](js-apis-bundleManager-hapModuleInfo.md)
- bundleManager/[metadata](js-apis-bundleManager-metadata.md) - [launcherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)
- bundleManager/[packInfo](js-apis-bundleManager-packInfo.md) - [metadata](js-apis-bundleManager-metadata.md)
- bundleManager/[permissionDef](js-apis-bundleManager-permissionDef.md) - [packInfo](js-apis-bundleManager-packInfo.md)
- bundleManager/[remoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md) - [permissionDef](js-apis-bundleManager-permissionDef.md)
- bundleManager/[shortcutInfo](js-apis-bundleManager-shortcutInfo.md) - [remoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)
- [shortcutInfo](js-apis-bundleManager-shortcutInfo.md)
- UI Page - UI Page
- [@ohos.animator](js-apis-animator.md) - [@ohos.animator](js-apis-animator.md)
- [@ohos.mediaquery](js-apis-mediaquery.md) - [@ohos.mediaquery](js-apis-mediaquery.md)
...@@ -89,16 +159,19 @@ ...@@ -89,16 +159,19 @@
- [@ohos.router](js-apis-router.md) - [@ohos.router](js-apis-router.md)
- Graphics - Graphics
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md) - [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.application.WindowExtensionAbility](js-apis-application-windowExtensionAbility.md)
- [@ohos.display ](js-apis-display.md) - [@ohos.display ](js-apis-display.md)
- [@ohos.effectKit](js-apis-effectKit.md) - [@ohos.effectKit](js-apis-effectKit.md)
- [@ohos.graphics.colorSpaceManager](js-apis-colorSpaceManager.md) - [@ohos.graphics.colorSpaceManager](js-apis-colorSpaceManager.md)
- [@ohos.screen](js-apis-screen.md) - [@ohos.screen](js-apis-screen.md)
- [@ohos.screenshot](js-apis-screenshot.md) - [@ohos.screenshot](js-apis-screenshot.md)
- [@ohos.window](js-apis-window.md) - [@ohos.window](js-apis-window.md)
- [webgl](js-apis-webgl.md) - webgl
- [webgl2](js-apis-webgl2.md) - [webgl](js-apis-webgl.md)
- [webgl2](js-apis-webgl2.md)
- Media - Media
- [@ohos.multimedia.audio](js-apis-audio.md) - [@ohos.multimedia.audio](js-apis-audio.md)
- [@ohos.multimedia.avsession](js-apis-avsession.md)
- [@ohos.multimedia.camera](js-apis-camera.md) - [@ohos.multimedia.camera](js-apis-camera.md)
- [@ohos.multimedia.image](js-apis-image.md) - [@ohos.multimedia.image](js-apis-image.md)
- [@ohos.multimedia.media](js-apis-media.md) - [@ohos.multimedia.media](js-apis-media.md)
...@@ -173,7 +246,7 @@ ...@@ -173,7 +246,7 @@
- Basic Features - Basic Features
- [@ohos.accessibility](js-apis-accessibility.md) - [@ohos.accessibility](js-apis-accessibility.md)
- [@ohos.accessibility.config](js-apis-accessibility-config.md) - [@ohos.accessibility.config](js-apis-accessibility-config.md)
- [@ohos.application.AccessibilityExtensionAbility](js-apis-application-AccessibilityExtensionAbility.md) - [@ohos.application.AccessibilityExtensionAbility](js-apis-application-accessibilityExtensionAbility.md)
- [@ohos.faultLogger](js-apis-faultLogger.md) - [@ohos.faultLogger](js-apis-faultLogger.md)
- [@ohos.hichecker](js-apis-hichecker.md) - [@ohos.hichecker](js-apis-hichecker.md)
- [@ohos.hidebug](js-apis-hidebug.md) - [@ohos.hidebug](js-apis-hidebug.md)
...@@ -181,6 +254,7 @@ ...@@ -181,6 +254,7 @@
- [@ohos.hiSysEvent](js-apis-hisysevent.md) - [@ohos.hiSysEvent](js-apis-hisysevent.md)
- [@ohos.hiTraceChain](js-apis-hitracechain.md) - [@ohos.hiTraceChain](js-apis-hitracechain.md)
- [@ohos.hiTraceMeter](js-apis-hitracemeter.md) - [@ohos.hiTraceMeter](js-apis-hitracemeter.md)
- [@ohos.hiviewdfx.hiAppEvent](js-apis-hiviewdfx-hiappevent.md)
- [@ohos.inputMethod](js-apis-inputmethod.md) - [@ohos.inputMethod](js-apis-inputmethod.md)
- [@ohos.inputMethodEngine](js-apis-inputmethodengine.md) - [@ohos.inputMethodEngine](js-apis-inputmethodengine.md)
- [@ohos.inputmethodextensionability](js-apis-inputmethod-extension-ability.md) - [@ohos.inputmethodextensionability](js-apis-inputmethod-extension-ability.md)
...@@ -190,6 +264,7 @@ ...@@ -190,6 +264,7 @@
- [@ohos.systemTime](js-apis-system-time.md) - [@ohos.systemTime](js-apis-system-time.md)
- [@ohos.systemTimer](js-apis-system-timer.md) - [@ohos.systemTimer](js-apis-system-timer.md)
- [@ohos.wallpaper](js-apis-wallpaper.md) - [@ohos.wallpaper](js-apis-wallpaper.md)
- [@ohos.web.webview](js-apis-webview.md)
- [console](js-apis-logs.md) - [console](js-apis-logs.md)
- [Timer](js-apis-timer.md) - [Timer](js-apis-timer.md)
- application/[AccessibilityExtensionContext](js-apis-accessibility-extension-context.md) - application/[AccessibilityExtensionContext](js-apis-accessibility-extension-context.md)
...@@ -249,15 +324,14 @@ ...@@ -249,15 +324,14 @@
- [@ohos.worker](js-apis-worker.md) - [@ohos.worker](js-apis-worker.md)
- [@ohos.xml](js-apis-xml.md) - [@ohos.xml](js-apis-xml.md)
- Test - Test
- [@ohos.application.testRunner](js-apis-testRunner.md) - [@ohos.application.testRunner](js-apis-application-testRunner.md)
- [@ohos.uitest](js-apis-uitest.md) - [@ohos.uitest](js-apis-uitest.md)
- APIs No Longer Maintained - APIs No Longer Maintained
- [@ohos.backgroundTaskManager](js-apis-backgroundTaskManager.md) - [@ohos.backgroundTaskManager](js-apis-backgroundTaskManager.md)
- [@ohos.bundle](js-apis-Bundle.md) - [@ohos.bundle](js-apis-Bundle.md)
- [@ohos.bundle.innerBundleManager](js-apis-Bundle-InnerBundleManager.md) - [@ohos.bundle.innerBundleManager](js-apis-Bundle-InnerBundleManager.md)
- [@ohos.bundleState](js-apis-deviceUsageStatistics.md) - [@ohos.bundleState](js-apis-deviceUsageStatistics.md)
- [@ohos.bytrace](js-apis-bytrace.md) - [@ohos.bytrace](js-apis-bytrace.md)
- [@ohos.commonEvent](js-apis-commonEvent.md)
- [@ohos.data.storage](js-apis-data-storage.md) - [@ohos.data.storage](js-apis-data-storage.md)
- [@ohos.data.distributedData](js-apis-distributed-data.md) - [@ohos.data.distributedData](js-apis-distributed-data.md)
- [@ohos.distributedBundle](js-apis-Bundle-distributedBundle.md) - [@ohos.distributedBundle](js-apis-Bundle-distributedBundle.md)
...@@ -267,6 +341,7 @@ ...@@ -267,6 +341,7 @@
- [@ohos.prompt](js-apis-prompt.md) - [@ohos.prompt](js-apis-prompt.md)
- [@ohos.reminderAgent](js-apis-reminderAgent.md) - [@ohos.reminderAgent](js-apis-reminderAgent.md)
- [@ohos.systemParameter](js-apis-system-parameter.md) - [@ohos.systemParameter](js-apis-system-parameter.md)
- [@ohos.usb](js-apis-usb-deprecated.md)
- [@ohos.workScheduler](js-apis-workScheduler.md) - [@ohos.workScheduler](js-apis-workScheduler.md)
- [@system.app](js-apis-system-app.md) - [@system.app](js-apis-system-app.md)
- [@system.battery](js-apis-system-battery.md) - [@system.battery](js-apis-system-battery.md)
...@@ -287,17 +362,17 @@ ...@@ -287,17 +362,17 @@
- [@system.sensor](js-apis-system-sensor.md) - [@system.sensor](js-apis-system-sensor.md)
- [@system.storage](js-apis-system-storage.md) - [@system.storage](js-apis-system-storage.md)
- [@system.vibrator](js-apis-system-vibrate.md) - [@system.vibrator](js-apis-system-vibrate.md)
- application/[ProcessRunningInfo](js-apis-processrunninginfo.md) - bundle
- bundle/[abilityInfo](js-apis-bundle-AbilityInfo.md) - [abilityInfo](js-apis-bundle-AbilityInfo.md)
- bundle/[applicationInfo](js-apis-bundle-ApplicationInfo.md) - [applicationInfo](js-apis-bundle-ApplicationInfo.md)
- bundle/[bundleInfo](js-apis-bundle-BundleInfo.md) - [bundleInfo](js-apis-bundle-BundleInfo.md)
- bundle/[bundleInstaller](js-apis-bundle-BundleInstaller.md) - [bundleInstaller](js-apis-bundle-BundleInstaller.md)
- bundle/[bundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md) - [bundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md)
- bundle/[customizeData](js-apis-bundle-CustomizeData.md) - [customizeData](js-apis-bundle-CustomizeData.md)
- bundle/[elementName](js-apis-bundle-ElementName.md) - [elementName](js-apis-bundle-ElementName.md)
- bundle/[hapModuleInfo](js-apis-bundle-HapModuleInfo.md) - [hapModuleInfo](js-apis-bundle-HapModuleInfo.md)
- bundle/[launcherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md) - [launcherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)
- bundle/[moduleInfo](js-apis-bundle-ModuleInfo.md) - [moduleInfo](js-apis-bundle-ModuleInfo.md)
- bundle/[PermissionDef](js-apis-bundle-PermissionDef.md) - [PermissionDef](js-apis-bundle-PermissionDef.md)
- bundle/[remoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md) - [remoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)
- bundle/[shortcutInfo](js-apis-bundle-ShortcutInfo.md) - [shortcutInfo](js-apis-bundle-ShortcutInfo.md)
# EnterpriseAdminExtensionAbility # @ohos.enterprise.EnterpriseAdminExtensionAbility
The **EnterpriseAdminExtensionAbility** module provides Extension abilities for enterprise administrators. The **EnterpriseAdminExtensionAbility** module provides Extension abilities for enterprise administrators.
......
# Ability # @ohos.ability.ability
The **Ability** module provides all level-2 module APIs for developers to export. The **Ability** module provides all level-2 module APIs for developers to export.
...@@ -37,5 +37,3 @@ let abilityResult: ability.AbilityResult; ...@@ -37,5 +37,3 @@ let abilityResult: ability.AbilityResult;
let connectOptions: ability.ConnectOptions; let connectOptions: ability.ConnectOptions;
let startAbilityParameter: ability.StartAbilityParameter; let startAbilityParameter: ability.StartAbilityParameter;
``` ```
<!--no_check-->
\ No newline at end of file
# DataUriUtils # @ohos.ability.dataUriUtils
The **DataUriUtils** module provides APIs to handle utility classes for objects using the **DataAbilityHelper** schema. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI. The **DataUriUtils** module provides APIs to handle utility classes for objects using the **DataAbilityHelper** schema. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI. This module will be replaced by the **app.ability.dataUriUtils** module in the near future. You are advised to use the **[@ohos.app.ability.dataUriUtils](js-apis-app-ability-dataUriUtils.md)** module.
> **NOTE** > **NOTE**
> >
...@@ -8,7 +8,7 @@ The **DataUriUtils** module provides APIs to handle utility classes for objects ...@@ -8,7 +8,7 @@ The **DataUriUtils** module provides APIs to handle utility classes for objects
## Modules to Import ## Modules to Import
```js ```ts
import dataUriUtils from '@ohos.ability.dataUriUtils'; import dataUriUtils from '@ohos.ability.dataUriUtils';
``` ```
...@@ -34,7 +34,7 @@ Obtains the ID attached to the end of a given URI. ...@@ -34,7 +34,7 @@ Obtains the ID attached to the end of a given URI.
**Example** **Example**
```js ```ts
dataUriUtils.getId("com.example.dataUriUtils/1221") dataUriUtils.getId("com.example.dataUriUtils/1221")
``` ```
...@@ -63,7 +63,7 @@ Attaches an ID to the end of a given URI. ...@@ -63,7 +63,7 @@ Attaches an ID to the end of a given URI.
**Example** **Example**
```js ```ts
var idint = 1122; var idint = 1122;
dataUriUtils.attachId( dataUriUtils.attachId(
"com.example.dataUriUtils", "com.example.dataUriUtils",
...@@ -95,12 +95,10 @@ Deletes the ID from the end of a given URI. ...@@ -95,12 +95,10 @@ Deletes the ID from the end of a given URI.
**Example** **Example**
```js ```ts
dataUriUtils.deleteId("com.example.dataUriUtils/1221") dataUriUtils.deleteId("com.example.dataUriUtils/1221")
``` ```
## dataUriUtils.updateId ## dataUriUtils.updateId
updateId(uri: string, id: number): string updateId(uri: string, id: number): string
...@@ -124,7 +122,7 @@ Updates the ID in a given URI. ...@@ -124,7 +122,7 @@ Updates the ID in a given URI.
**Example** **Example**
```js ```ts
var idint = 1122; var idint = 1122;
dataUriUtils.updateId( dataUriUtils.updateId(
"com.example.dataUriUtils", "com.example.dataUriUtils",
......
# ErrorCode # @ohos.ability.errorCode
The **ErrorCode** module defines the error codes that can be used when the ability is started. The **ErrorCode** module defines the error codes that can be used when the ability is started.
**NOTE**
> **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
``` ```ts
import errorCode from '@ohos.ability.errorCode' import errorCode from '@ohos.ability.errorCode'
``` ```
......
# FeatureAbility # @ohos.ability.featureAbility
The **FeatureAbility** module provides a UI for interacting with users. You can use APIs of this module to start a new ability, obtain the **dataAbilityHelper**, set a Page ability, obtain the window corresponding to this ability, and connect to a Service ability. The **FeatureAbility** module provides a UI for interacting with users. You can use APIs of this module to start a new ability, obtain the **dataAbilityHelper**, set a Page ability, obtain the window corresponding to this ability, and connect to a Service ability.
...@@ -13,7 +13,7 @@ APIs of the **FeatureAbility** module can be called only by Page abilities. ...@@ -13,7 +13,7 @@ APIs of the **FeatureAbility** module can be called only by Page abilities.
## Modules to Import ## Modules to Import
``` ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
``` ```
...@@ -29,12 +29,12 @@ Starts an ability. This API uses an asynchronous callback to return the result. ...@@ -29,12 +29,12 @@ Starts an ability. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- | | --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the result. | | callback | AsyncCallback\<number> | Yes | Callback used to return the result. |
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility( featureAbility.startAbility(
...@@ -72,11 +72,11 @@ Starts an ability. This API uses a promise to return the result. ...@@ -72,11 +72,11 @@ Starts an ability. This API uses a promise to return the result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- | | --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility( featureAbility.startAbility(
...@@ -121,7 +121,7 @@ Obtains a **dataAbilityHelper** object. ...@@ -121,7 +121,7 @@ Obtains a **dataAbilityHelper** object.
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var dataAbilityHelper = featureAbility.acquireDataAbilityHelper( var dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
...@@ -140,12 +140,12 @@ Starts an ability. This API uses an asynchronous callback to return the executio ...@@ -140,12 +140,12 @@ Starts an ability. This API uses an asynchronous callback to return the executio
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- | | --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
| callback | AsyncCallback\<[AbilityResult](#abilityresult)> | Yes | Callback used to return the result. | | callback | AsyncCallback\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes | Callback used to return the result. |
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
...@@ -181,17 +181,17 @@ Starts an ability. This API uses a promise to return the execution result when t ...@@ -181,17 +181,17 @@ Starts an ability. This API uses a promise to return the execution result when t
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | ------------- | | --------- | ---------------------------------------- | ---- | ------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------- | ------- | | ---------------------------------------- | ------- |
| Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.| | Promise\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promised returned with the execution result.|
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
...@@ -237,12 +237,12 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -237,12 +237,12 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------------------- | ---- | -------------- | | --------- | ------------------------------- | ---- | -------------- |
| parameter | [AbilityResult](#abilityresult) | Yes | Ability to destroy.| | parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Ability to start.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult( featureAbility.terminateSelfWithResult(
...@@ -289,7 +289,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -289,7 +289,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------------------- | ---- | ------------- | | --------- | ------------------------------- | ---- | ------------- |
| parameter | [AbilityResult](#abilityresult) | Yes | Ability to destroy.| | parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Ability to start.|
**Return value** **Return value**
...@@ -299,7 +299,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -299,7 +299,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult( featureAbility.terminateSelfWithResult(
...@@ -349,7 +349,7 @@ Checks whether the main window of this ability has the focus. This API uses an a ...@@ -349,7 +349,7 @@ Checks whether the main window of this ability has the focus. This API uses an a
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus((err, data) => { featureAbility.hasWindowFocus((err, data) => {
console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data)); console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
...@@ -372,7 +372,7 @@ Checks whether the main window of this ability has the focus. This API uses a pr ...@@ -372,7 +372,7 @@ Checks whether the main window of this ability has the focus. This API uses a pr
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => { featureAbility.hasWindowFocus().then((data) => {
console.info("hasWindowFocus data: " + JSON.stringify(data)); console.info("hasWindowFocus data: " + JSON.stringify(data));
...@@ -391,11 +391,11 @@ Obtains the **Want** object sent from this ability. This API uses an asynchronou ...@@ -391,11 +391,11 @@ Obtains the **Want** object sent from this ability. This API uses an asynchronou
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------------- | ---- | --------- | | -------- | ----------------------------- | ---- | --------- |
| callback | AsyncCallback\<[Want](js-apis-application-Want.md)> | Yes | Callback used to return the result.| | callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes | Callback used to return the result.|
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant((err, data) => { featureAbility.getWant((err, data) => {
console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data)); console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
...@@ -414,11 +414,11 @@ Obtains the **Want** object sent from this ability. This API uses a promise to r ...@@ -414,11 +414,11 @@ Obtains the **Want** object sent from this ability. This API uses a promise to r
| Type | Description | | Type | Description |
| ----------------------- | ---------------- | | ----------------------- | ---------------- |
| Promise\<[Want](js-apis-application-Want.md)> | Promise used to return the result.| | Promise\<[Want](js-apis-application-want.md)> | Promise used to return the result.|
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => { featureAbility.getWant().then((data) => {
console.info("getWant data: " + JSON.stringify(data)); console.info("getWant data: " + JSON.stringify(data));
...@@ -441,7 +441,7 @@ Obtains the application context. ...@@ -441,7 +441,7 @@ Obtains the application context.
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() var context = featureAbility.getContext()
context.getBundleName((err, data) => { context.getBundleName((err, data) => {
...@@ -465,7 +465,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -465,7 +465,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf( featureAbility.terminateSelf(
(err) => { (err) => {
...@@ -490,7 +490,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -490,7 +490,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => { featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelf=======================>"); console.info("==========================>terminateSelf=======================>");
...@@ -509,20 +509,8 @@ Connects this ability to a specific Service ability. This API uses an asynchrono ...@@ -509,20 +509,8 @@ Connects this ability to a specific Service ability. This API uses an asynchrono
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------------- | ---- | --------------------- | | ------- | -------------- | ---- | --------------------- |
| request | [Want](js-apis-application-Want.md) | Yes | Service ability to connect.| | request | [Want](js-apis-application-want.md) | Yes | Service ability to connect.|
| options | [ConnectOptions](#connectoptions) | Yes | Callback used to return the result. | | options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes | Callback used to return the result. |
## ConnectOptions
Describes the connection options.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable|Writable| Type | Mandatory | Description |
| ------------ | -- | -- | -------- | ---- | ------------------------- |
| onConnect<sup>7+</sup> | Yes|No | function | Yes | Callback invoked when the connection is successful. |
| onDisconnect<sup>7+</sup> | Yes|No | function | Yes | Callback invoked when the connection fails. |
| onFailed<sup>7+</sup> | Yes|No | function | Yes | Callback invoked when **connectAbility** fails to be called.|
**Return value** **Return value**
...@@ -532,7 +520,7 @@ Describes the connection options. ...@@ -532,7 +520,7 @@ Describes the connection options.
**Example** **Example**
```javascript ```ts
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
...@@ -575,7 +563,7 @@ Disconnects this ability from a specific Service ability. This API uses an async ...@@ -575,7 +563,7 @@ Disconnects this ability from a specific Service ability. This API uses an async
**Example** **Example**
```javascript ```ts
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
...@@ -627,7 +615,7 @@ Disconnects this ability from a specific Service ability. This API uses a promis ...@@ -627,7 +615,7 @@ Disconnects this ability from a specific Service ability. This API uses a promis
**Example** **Example**
```javascript ```ts
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
...@@ -675,7 +663,7 @@ Obtains the window corresponding to this ability. This API uses an asynchronous ...@@ -675,7 +663,7 @@ Obtains the window corresponding to this ability. This API uses an asynchronous
**Example** **Example**
```javascript ```ts
featureAbility.getWindow((err, data) => { featureAbility.getWindow((err, data) => {
console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data)); console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data));
}); });
...@@ -697,143 +685,12 @@ Obtains the window corresponding to this ability. This API uses a promise to ret ...@@ -697,143 +685,12 @@ Obtains the window corresponding to this ability. This API uses a promise to ret
**Example** **Example**
```javascript ```ts
featureAbility.getWindow().then((data) => { featureAbility.getWindow().then((data) => {
console.info("getWindow data: " + typeof(data)); console.info("getWindow data: " + typeof(data));
}); });
``` ```
## ConnectOptions.onConnect<sup>7+</sup>
onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void;
Callback invoked when the connection is successful.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ----------------- | ---- | -------- |
| elementName | ElementName | Yes | Element name. |
| remote | rpc.IRemoteObject | Yes | RPC remote object.|
**Example**
```javascript
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
```
## ConnectOptions.onDisconnect<sup>7+</sup>
onDisconnect(elementName: ElementName): void;
Callback invoked when the connection fails.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ----------- | ---- | ---- |
| elementName | ElementName | Yes | Element name.|
**Example**
```javascript
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
```
## ConnectOptions.onFailed<sup>7+</sup>
onFailed(code: number): void;
Callback invoked when **connectAbility** fails to be called.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | --------- |
| code | number | Yes | Number type.|
**Example**
```javascript
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
```
## AbilityWindowConfiguration ## AbilityWindowConfiguration
The value is obtained through the **featureAbility.AbilityWindowConfiguration** API. The value is obtained through the **featureAbility.AbilityWindowConfiguration** API.
...@@ -902,26 +759,6 @@ Enumerates operation types of the Data ability. ...@@ -902,26 +759,6 @@ Enumerates operation types of the Data ability.
| TYPE_DELETE<sup>7+</sup> | 3 | Deletion operation.| | TYPE_DELETE<sup>7+</sup> | 3 | Deletion operation.|
| TYPE_ASSERT<sup>7+</sup> | 4 | Assert operation.| | TYPE_ASSERT<sup>7+</sup> | 4 | Assert operation.|
## AbilityResult
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Type | Readable| Writable | Mandatory | Description |
| --------------- |-------- | ------ | ------------- | ---- | ------------------------------------- |
| resultCode<sup>7+</sup>| number| Yes | No | Yes | Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.|
| want<sup>7+</sup> | [Want](js-apis-application-Want.md)| Yes | No| No | Data returned after the ability is destroyed. You can define the data to be returned. This parameter can be **null**. |
## StartAbilityParameter
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Readable| Writable | Mandatory | Description |
| ------------------- | -------- | -------------------- | ---- | -------------------------------------- |
| want | [Want](js-apis-application-Want.md)| Yes | No | Yes | Information about the ability to start. |
| abilityStartSetting | {[key: string]: any} | Yes |No | No | Special attribute of the ability to start. This attribute can be passed in the method call.|
## flags ## flags
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
......
# particleAbility # @ohos.ability.particleAbility
The **particleAbility** module provides APIs for Service abilities. You can use the APIs to start and terminate a Particle ability, obtain a **dataAbilityHelper** object, connect the current ability to a specific Service ability, and disconnect the current ability from a specific Service ability. The **particleAbility** module provides APIs for Service abilities. You can use the APIs to start and terminate a Particle ability, obtain a **dataAbilityHelper** object, connect the current ability to a specific Service ability, and disconnect the current ability from a specific Service ability.
...@@ -13,7 +13,7 @@ The ParticleAbility module is used to perform operations on abilities of the Dat ...@@ -13,7 +13,7 @@ The ParticleAbility module is used to perform operations on abilities of the Dat
## Modules to Import ## Modules to Import
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
``` ```
...@@ -27,19 +27,19 @@ Starts a Particle ability. This API uses an asynchronous callback to return the ...@@ -27,19 +27,19 @@ Starts a Particle ability. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------------------------------- | ---- | ----------------- | | --------- | ----------------------------------------------- | ---- | ----------------- |
| parameter | [StartAbilityParameter](js-apis-featureAbility.md#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility( particleAbility.startAbility(
{ {
want: want:
{ {
action: "action.system.home", action: "action.system.home",
...@@ -49,17 +49,15 @@ particleAbility.startAbility( ...@@ -49,17 +49,15 @@ particleAbility.startAbility(
deviceId: "", deviceId: "",
bundleName: "com.example.Data", bundleName: "com.example.Data",
abilityName: "com.example.Data.MainAbility", abilityName: "com.example.Data.MainAbility",
uri:"" uri: ""
}, },
}, },
(error, result) => { (error, result) => {
console.log('particleAbility startAbility errCode:' + error + 'result:' + result) console.log('particleAbility startAbility errCode:' + error + 'result:' + result)
}, },
) )
``` ```
## particleAbility.startAbility ## particleAbility.startAbility
startAbility(parameter: StartAbilityParameter): Promise\<void>; startAbility(parameter: StartAbilityParameter): Promise\<void>;
...@@ -70,10 +68,9 @@ Starts a Particle ability. This API uses a promise to return the result. ...@@ -70,10 +68,9 @@ Starts a Particle ability. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------------------------------- | ---- | ----------------- | | --------- | ----------------------------------------------- | ---- | ----------------- |
| parameter | [StartAbilityParameter](js-apis-featureAbility.md#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
**Return value** **Return value**
...@@ -83,11 +80,12 @@ Starts a Particle ability. This API uses a promise to return the result. ...@@ -83,11 +80,12 @@ Starts a Particle ability. This API uses a promise to return the result.
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility( particleAbility.startAbility(
{ {
want: want:
{ {
action: "action.system.home", action: "action.system.home",
...@@ -97,7 +95,7 @@ particleAbility.startAbility( ...@@ -97,7 +95,7 @@ particleAbility.startAbility(
deviceId: "", deviceId: "",
bundleName: "com.example.Data", bundleName: "com.example.Data",
abilityName: "com.example. Data.MainAbility", abilityName: "com.example. Data.MainAbility",
uri:"" uri: ""
}, },
}, },
).then((data) => { ).then((data) => {
...@@ -105,8 +103,6 @@ particleAbility.startAbility( ...@@ -105,8 +103,6 @@ particleAbility.startAbility(
}); });
``` ```
## particleAbility.terminateSelf ## particleAbility.terminateSelf
terminateSelf(callback: AsyncCallback\<void>): void terminateSelf(callback: AsyncCallback\<void>): void
...@@ -123,17 +119,16 @@ Terminates this Particle ability. This API uses an asynchronous callback to retu ...@@ -123,17 +119,16 @@ Terminates this Particle ability. This API uses an asynchronous callback to retu
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
particleAbility.terminateSelf( particleAbility.terminateSelf(
(error, result) => { (error, result) => {
console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result) console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result)
} }
) )
``` ```
## particleAbility.terminateSelf ## particleAbility.terminateSelf
terminateSelf(): Promise\<void> terminateSelf(): Promise\<void>
...@@ -150,8 +145,9 @@ Terminates this Particle ability. This API uses a promise to return the result. ...@@ -150,8 +145,9 @@ Terminates this Particle ability. This API uses a promise to return the result.
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
particleAbility.terminateSelf().then((data) => { particleAbility.terminateSelf().then((data) => {
console.info("particleAbility terminateSelf"); console.info("particleAbility terminateSelf");
}); });
...@@ -181,8 +177,9 @@ Obtains a **dataAbilityHelper** object. ...@@ -181,8 +177,9 @@ Obtains a **dataAbilityHelper** object.
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
var uri = ""; var uri = "";
particleAbility.acquireDataAbilityHelper(uri) particleAbility.acquireDataAbilityHelper(uri)
``` ```
...@@ -208,7 +205,7 @@ Requests a continuous task from the system. This API uses an asynchronous callba ...@@ -208,7 +205,7 @@ Requests a continuous task from the system. This API uses an asynchronous callba
**Example** **Example**
```js ```ts
import notification from '@ohos.notification'; import notification from '@ohos.notification';
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.wantAgent';
...@@ -277,7 +274,7 @@ Requests a continuous task from the system. This API uses a promise to return th ...@@ -277,7 +274,7 @@ Requests a continuous task from the system. This API uses a promise to return th
**Example** **Example**
```js ```ts
import notification from '@ohos.notification'; import notification from '@ohos.notification';
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.wantAgent';
...@@ -333,7 +330,7 @@ Requests to cancel a continuous task from the system. This API uses an asynchron ...@@ -333,7 +330,7 @@ Requests to cancel a continuous task from the system. This API uses an asynchron
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
function callback(err, data) { function callback(err, data) {
...@@ -364,7 +361,7 @@ Requests a continuous task from the system. This API uses a promise to return th ...@@ -364,7 +361,7 @@ Requests a continuous task from the system. This API uses a promise to return th
**Example** **Example**
```js ```ts
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
particleAbility.cancelBackgroundRunning().then(() => { particleAbility.cancelBackgroundRunning().then(() => {
...@@ -375,7 +372,6 @@ particleAbility.cancelBackgroundRunning().then(() => { ...@@ -375,7 +372,6 @@ particleAbility.cancelBackgroundRunning().then(() => {
``` ```
## particleAbility.connectAbility ## particleAbility.connectAbility
connectAbility(request: Want, options:ConnectOptions): number connectAbility(request: Want, options:ConnectOptions): number
...@@ -388,7 +384,7 @@ Connects this ability to a specific Service ability. This API uses a callback to ...@@ -388,7 +384,7 @@ Connects this ability to a specific Service ability. This API uses a callback to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------------- | ---- | ---------------------------- | | ------- | -------------- | ---- | ---------------------------- |
| request | [Want](js-apis-application-Want.md) | Yes | Service ability to connect.| | request | [Want](js-apis-application-want.md) | Yes | Service ability to connect.|
| options | ConnectOptions | Yes | Callback used to return the result. | | options | ConnectOptions | Yes | Callback used to return the result. |
...@@ -396,46 +392,48 @@ ConnectOptions ...@@ -396,46 +392,48 @@ ConnectOptions
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------ | ---- | -------- | ---- | ------------------------- | | ------------ | -------- | ---- | ------------------------- |
| onConnect | Read only | function | Yes | Callback invoked when the connection is successful. | | onConnect | function | Yes | Callback invoked when the connection is successful. |
| onDisconnect | Read only | function | Yes | Callback invoked when the connection fails. | | onDisconnect | function | Yes | Callback invoked when the connection fails. |
| onFailed | Read only | function | Yes | Callback invoked when **connectAbility** fails to be called.| | onFailed | function | Yes | Callback invoked when **connectAbility** fails to be called.|
**Example** **Example**
```js ```ts
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
});
``` function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
```
## particleAbility.disconnectAbility ## particleAbility.disconnectAbility
...@@ -453,34 +451,37 @@ Disconnects this ability from the Service ability. This API uses a callback to r ...@@ -453,34 +451,37 @@ Disconnects this ability from the Service ability. This API uses a callback to r
**Example** **Example**
```js ```ts
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
});
function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
``` ```
...@@ -500,34 +501,38 @@ Disconnects this ability from the Service ability. This API uses a promise to re ...@@ -500,34 +501,38 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**Example** **Example**
```js ```ts
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); function onConnectCallback(element, remote) {
} console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
function onDisconnectCallback(element){ }
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
} function onDisconnectCallback(element) {
function onFailedCallback(code){ console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) }
}
var connId = particleAbility.connectAbility( function onFailedCallback(code) {
{ console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
bundleName: "com.ix.ServiceAbility", }
abilityName: "ServiceAbilityA",
}, var connId = particleAbility.connectAbility(
{ {
onConnect: onConnectCallback, bundleName: "com.ix.ServiceAbility",
onDisconnect: onDisconnectCallback, abilityName: "ServiceAbilityA",
onFailed: onFailedCallback, },
}, {
); onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
particleAbility.disconnectAbility(connId).then((data)=>{ onFailed: onFailedCallback,
console.log( " data: " + data); },
}).catch((error)=>{ );
console.log('particleAbilityTest result errCode : ' + error.code )
}); particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
``` ```
......
# wantConstant # @ohos.ability.wantConstant
The **wantConstant** module provides the actions, entities, and flags used in **Want** objects. The **wantConstant** module provides the actions, entities, and flags used in **Want** objects.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 6 and deprecated since API version 9. You are advised to use [@ohos.app.ability.wantConstant](js-apis-app-ability-wantConstant.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
```js ```ts
import wantConstant from '@ohos.ability.wantConstant'; import wantConstant from '@ohos.ability.wantConstant';
``` ```
...@@ -46,6 +46,7 @@ Enumerates the action constants of the **Want** object. ...@@ -46,6 +46,7 @@ Enumerates the action constants of the **Want** object.
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. | | ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. | | PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. | | ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| ACTION_APP_ACCOUNT_AUTH <sup>9+</sup> | account.appAccount.action.auth | Action of providing the authentication service. |
| ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. | | ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. | | ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_SANDBOX<sup>9+</sup> |ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications. | | DLP_PARAMS_SANDBOX<sup>9+</sup> |ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications. |
......
# @ohos.app.ability.Ability
The **Ability** module manages the ability lifecycle and context, such as creating and destroying an ability, and dumping client 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.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import Ability from '@ohos.app.ability.Ability';
```
## Ability.onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
**Example**
```ts
class myAbility extends Ability {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
}
}
```
## Ability.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```ts
class myAbility extends Ability {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
# @ohos.app.ability.AbilityConstant
The **AbilityConstant** module provides ability launch parameters.
The parameters include the initial launch reasons, reasons for the last exit, and ability continuation results.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| launchReason | LaunchReason| Yes| Yes| Ability launch reason.|
| lastExitReason | LastExitReason | Yes| Yes| Reason for the last exit.|
## AbilityConstant.LaunchReason
Enumerates the ability launch reasons.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
| START_ABILITY | 1 | Ability startup.|
| CALL | 2 | Call.|
| CONTINUATION | 3 | Ability continuation.|
| APP_RECOVERY | 4 | Application recovery.|
## AbilityConstant.LastExitReason
Enumerates reasons for the last exit.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
| ABILITY_NOT_RESPONDING | 1 | The ability does not respond.|
| NORMAL | 2 | Normal status.|
## AbilityConstant.OnContinueResult
Enumerates ability continuation results.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| AGREE | 0 | Continuation agreed.|
| REJECT | 1 | Continuation denied.|
| MISMATCH | 2 | Mismatch.|
## AbilityConstant.WindowMode
Enumerates the window modes in which an ability can be displayed at startup.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
| --- | --- | --- |
| WINDOW_MODE_UNDEFINED | 0 | Undefined window mode. |
| WINDOW_MODE_FULLSCREEN | 1 | The ability is displayed in full screen. |
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. |
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. |
| WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.|
## AbilityConstant.MemoryLevel
Enumerates the memory levels.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | Moderate memory usage. |
| MEMORY_LEVEL_LOW | 1 | Low memory usage. |
| MEMORY_LEVEL_CRITICAL | 2 | High memory usage. |
## AbilityConstant.OnSaveResult
Enumerates the result types for the operation of saving application data.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALL_AGREE | 0 | Agreed to save the status.|
| CONTINUATION_REJECT | 1 | Rejected to save the status in continuation.|
| CONTINUATION_MISMATCH | 2 | Continuation mismatch.|
| RECOVERY_AGREE | 3 | Agreed to restore the saved status.|
| RECOVERY_REJECT | 4 | Rejected to restore the saved state.|
| ALL_REJECT | 5 | Rejected to save the status.|
## AbilityConstant.StateType
Enumerates the scenarios for saving application data.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | Saving the status in continuation.|
| APP_RECOVERY | 1 | Saving the status in application recovery.|
# @ohos.app.ability.abilityDelegatorRegistry
The **AbilityDelegatorRegistry** module provides APIs for storing the global registers of the registered **AbilityDelegator** and **AbilityDelegatorArgs** objects. You can use the APIs to obtain the **AbilityDelegator** and **AbilityDelegatorArgs** objects of an application.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
```
## AbilityLifecycleState
Enumerates the ability lifecycle states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ------------- | ---- | --------------------------- |
| UNINITIALIZED | 0 | The ability is in an invalid state. |
| CREATE | 1 | The ability is created.|
| FOREGROUND | 2 | The ability is running in the foreground. |
| BACKGROUND | 3 | The ability is running in the background. |
| DESTROY | 4 | The ability is destroyed.|
## AbilityDelegatorRegistry.getAbilityDelegator
getAbilityDelegator(): AbilityDelegator
Obtains the **AbilityDelegator** object of the application.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) | [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) object, which can be used to schedule functions related to the test framework.|
**Example**
```ts
var abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
```
## AbilityDelegatorRegistry.getArguments
getArguments(): AbilityDelegatorArgs
Obtains the **AbilityDelegatorArgs** object of the application.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) | [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) object, which can be used to obtain test parameters.|
**Example**
```ts
var args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
```
# @ohos.app.ability.abilityLifecycleCallback
The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onWindowStageCreate**, and **onWindowStageDestroy**, to receive lifecycle state changes in the application context.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
```
## AbilityLifecycleCallback.onAbilityCreate
onAbilityCreate(ability: UIAbility): void;
Called when an ability is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onWindowStageCreate
onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
Called when the window stage of an ability is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageActive
onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
Called when the window stage of an ability gains focus.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageInactive
onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void;
Called when the window stage of an ability loses focus.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageDestroy
onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
Called when the window stage of an ability is destroyed.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onAbilityDestroy
onAbilityDestroy(ability: UIAbility): void;
Called when an ability is destroyed.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityForeground
onAbilityForeground(ability: UIAbility): void;
Called when an ability is switched from the background to the foreground.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityBackground
onAbilityBackground(ability: UIAbility): void;
Called when an ability is switched from the foreground to the background.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityContinue
onAbilityContinue(ability: UIAbility): void;
Called when an ability is continued on another device.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
**Example**
```ts
import UIAbility from "@ohos.app.ability.UIAbility";
export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground ability:" + JSON.stringify(ability));
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground ability:" + JSON.stringify(ability));
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue ability:" + JSON.stringify(ability));
}
}
// 1. Obtain applicationContext through the context attribute.
let applicationContext = this.context.getApplicationContext();
// 2. Use applicationContext to register a listener for the ability lifecycle in the application.
let lifecycleid = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.off("abilityLifecycle", lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
```
# @ohos.app.ability.abilityManager
The **AbilityManager** module provides APIs for obtaining, adding, and modifying ability running information and state 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.
> The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```ts
import AbilityManager from '@ohos.app.ability.abilityManager'
```
## AbilityState
Enumerates the ability states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Value| Description|
| -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state. |
## updateConfiguration
updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
Updates the configuration. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
var config = {
language: 'chinese'
}
try {
abilitymanager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## updateConfiguration
updateConfiguration(config: Configuration): Promise\<void>
Updates the configuration. This API uses a promise to return the result.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
var config = {
language: 'chinese'
}
try {
abilitymanager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getAbilityRunningInfos
getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
Obtains the ability running information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<AbilityRunningInfo>> | Yes | Callback used to return the result. |
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
try {
abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getAbilityRunningInfos
getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
Obtains the ability running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<AbilityRunningInfo>> | Promise used to return the result.|
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
try {
abilitymanager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getExtensionRunningInfos
getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<ExtensionRunningInfo>>): void
Obtains the extension running information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
| callback | AsyncCallback\<Array\<AbilityRunningInfo>> | Yes | Callback used to return the result. |
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
var upperLimit = 0;
try {
abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getExtensionRunningInfos
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
Obtains the extension running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<AbilityRunningInfo>> | Promise used to return the result.|
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
var upperLimit = 0;
try {
abilitymanager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err);
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getTopAbility<sup>9+</sup>
getTopAbility(callback: AsyncCallback\<ElementName>): void;
Obtains the top ability, which is the ability that has the window focus. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<ElementName> | Yes | Callback used to return the result. |
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
try {
abilitymanager.getTopAbility((err,data) => {
console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## getTopAbility
getTopAbility(): Promise\<ElementName>;
Obtains the top ability, which is the ability that has the window focus. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<ElementName>| Promise used to return the result.|
**Example**
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
try {
abilitymanager.getTopAbility().then((data) => {
console.log("getTopAbility data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility err: " + err);
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
# @ohos.app.ability.AbilityStage
**AbilityStage** is a runtime class for HAP files.
**AbilityStage** notifies you of when you can perform HAP initialization such as resource pre-loading and thread creation during the HAP loading.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import AbilityStage from '@ohos.app.ability.AbilityStage';
```
## AbilityStage.onCreate
onCreate(): void
Called when the application is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
}
}
```
## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string;
Called when a specified ability is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-app-ability-want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
## AbilityStage.onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void;
Called when the global configuration is updated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
}
}
```
## AbilityStage.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```ts
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
## AbilityStage.context
context: AbilityStageContext;
Describes the configuration information about the context.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Called when initialization is performed during ability startup.|
# @ohos.app.ability.appRecovery
The **appRecovery** module provides APIs for recovering faulty applications.
> **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. In the current version, only applications with a single ability in a single process can be recovered.
## Modules to Import
```ts
import appRecovery from '@ohos.app.ability.appRecovery'
```
## appRecovery.RestartFlag
Enumerates the application restart options used in [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALWAYS_RESTART | 0 | The application is restarted in all cases.|
| CPP_CRASH_NO_RESTART | 0x0001 | The application is not restarted in the case of CPP_CRASH.|
| JS_CRASH_NO_RESTART | 0x0002 | The application is not restarted in the case of JS_CRASH.|
| APP_FREEZE_NO_RESTART | 0x0004 | The application is not restarted in the case of APP_FREEZE.|
| NO_RESTART | 0xFFFF | The application is not restarted in any case.|
## appRecovery.SaveOccasionFlag
Enumerates the scenarios for saving the application state, which is used in [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| SAVE_WHEN_ERROR | 0x0001 | Saving the application state when an application fault occurs.|
| SAVE_WHEN_BACKGROUND | 0x0002 | Saving the application state when the application is switched to the background.|
## appRecovery.SaveModeFlag
Enumerates the application state saving modes used in [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| SAVE_WITH_FILE | 0x0001 | The application state is saved and written to the local file cache.|
| SAVE_WITH_SHARED_MEMORY | 0x0002 | The application state is saved in the memory. When the application exits due to a fault, it is written to the local file cache.|
## appRecovery.enableAppRecovery
enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void;
Enables application recovery.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| restart | [RestartFlag](#apprecoveryrestartflag) | No| Whether the application is restarted upon a fault. By default, the application is not restarted.|
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | No| Scenario for saving the application state. By default, the state is saved when a fault occurs.|
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | No| Application state saving mode. By default, the application state is written to the local file cache.|
**Example**
```ts
export default class MyAbilityStage extends AbilityStage {
onCreate() {
appRecovery.enableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE);
}
}
```
## appRecovery.restartApp
restartApp(): void;
Restarts the application. This API can be used together with APIs of [errorManager](js-apis-app-ability-errorManager.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
```ts
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.restartApp();
}
}
```
## appRecovery.saveAppState
saveAppState(): boolean;
Saves the application state. This API can be used together with APIs of [errorManager](js-apis-app-ability-errorManager.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Whether the saving is successful.|
**Example**
```ts
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.saveAppState();
}
}
```
# @ohos.app.ability.common
The **Common** module provides all level-2 module APIs for developers to export.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common'
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| UIAbilityContext | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | No | Level-2 module **UIAbilityContext**. |
| AbilityStageContext | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | No | Level-2 module **AbilityStageContext**.|
| ApplicationContext | [ApplicationContext](js-apis-inner-application-applicationContext.md) | No | Level-2 module **ApplicationContext**.|
| BaseContext | [BaseContext](js-apis-inner-application-baseContext.md) | No | Level-2 module **BaseContext**.|
| Context | [Context](js-apis-inner-application-context.md) | No | Level-2 module **Context**.|
| ExtensionContext | [ExtensionContext](js-apis-inner-application-extensionContext.md) | No | Level-2 module **ExtensionContext**.|
| FormExtensionContext | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | No | Level-2 module **FormExtensionContext**.|
| AreaMode | [AreaMode](#areamode) | No | Enumerated values of **AreaMode**.|
| EventHub | [EventHub](js-apis-inner-application-eventHub.md) | No | Level-2 module **EventHub**.|
| PermissionRequestResult | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | No | Level-2 module **PermissionRequestResult**.|
| PacMap | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#PacMap) | No | Level-2 module **PacMap**.|
| AbilityResult | [AbilityResult](js-apis-inner-ability-abilityResult.md) | No | Level-2 module **AbilityResult**.|
| ConnectOptions | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | No | Level-2 module **ConnectOptions**.|
**Example**
```ts
import common from '@ohos.app.ability.common'
let uiAbilityContext: common.UIAbilityContext;
let abilityStageContext: common.AbilityStageContext;
let applicationContext: common.ApplicationContext;
let baseContext: common.BaseContext;
let context: common.Context;
let extensionContext: common.ExtensionContext;
let formExtensionContext: common.FormExtensionContext;
let areaMode: common.AreaMode;
let eventHub: common.EventHub;
let permissionRequestResult: common.PermissionRequestResult;
let pacMap: common.PacMap;
let abilityResult: common.AbilityResult;
let connectOptions: common.ConnectOptions;
```
## AreaMode
Defines the area where the file to be access is located. Each area has its own content.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| --------------- | ---- | --------------- |
| EL1 | 0 | Device-level encryption area. |
| EL2 | 1 | User credential encryption area. The default value is **EL2**.|
# @ohos.app.ability.Configuration
The **Configuration** module defines environment change 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.
## Modules to Import
```ts
import Configuration from '@ohos.app.ability.Configuration'
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application.|
| colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.|
| direction | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).|
| displayId | number | Yes| No| ID of the display where the application is located.|
| hasPointerDevice | boolean | Yes| No| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.|
For details about the fields, see the **ohos.app.ability.Configuration.d.ts** file.
**Example**
```ts
let envCallback = {
onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
let language = config.language;
let colorMode = config.colorMode;
let direction = config.direction;
let screenDensity = config.screenDensity;
let displayId = config.displayId;
let hasPointerDevice = config.hasPointerDevice;
}
};
try {
var callbackId = applicationContext.on("environment", envCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
# @ohos.app.ability.contextConstant
The **ContextConstant** module defines data encryption levels.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import contextConstant from '@ohos.app.ability.contextConstant';
```
## ContextConstant.AreaMode
You can obtain the value of this constant by calling the **ContextConstant.AreaMode** API.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description|
| -------- | -------- | -------- |
| EL1 | 0 | Device-level encryption area.|
| EL2 | 1 | User credential encryption area.|
# Want # @ohos.app.ability.Want
Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When ability A needs to start ability B and transfer some data to ability B, it can use Want a carrier to transfer the data. Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When ability A needs to start ability B and transfer some data to ability B, it can use Want a carrier to transfer the data.
......
...@@ -107,5 +107,3 @@ export default class MyWindowExtensionAbility extends WindowExtensionAbility { ...@@ -107,5 +107,3 @@ export default class MyWindowExtensionAbility extends WindowExtensionAbility {
} }
``` ```
<!--no_check-->
\ No newline at end of file
# AbilityResult<sup>7+</sup> # AbilityResult
The **AbilityResult** module defines the result code and data returned when an ability is started or destroyed. The **AbilityResult** module defines the result code and data returned when an ability is started or destroyed.
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册