未验证 提交 5728d46f 编写于 作者: O openharmony_ci 提交者: Gitee

!2276 Done! 1921:Fix format issues of ability api

Merge pull request !2276 from wusongqing/TR1921
# DataUriUtils Module
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
......@@ -12,15 +15,17 @@ getId(uri: string): number
Obtains the ID attached to the end of a given URI.
**Parameters**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be obtained.|
| uri | string | Yes | URI object from which the ID is to be obtained.|
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------------ |
| number | ID obtained from the URI object.|
......@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string
Attaches an ID to the end of a given URI.
**Parameters**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object to which an ID is to be attached.|
| id | number | Yes| ID to be attached.|
| uri | string | Yes | URI object to which an ID is to be attached.|
| id | number | Yes | ID to be attached. |
**Return value**
| Type| Description|
| Type | Description |
| ------ | --------------------- |
| string | URI object with the ID attached.|
......@@ -69,14 +76,17 @@ deleteId(uri: string): string
Deletes the ID from the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be deleted.|
| uri | string | Yes | URI object from which the ID is to be deleted.|
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------- |
| string | URI object with the ID deleted.|
......@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string
Updates the ID in a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------- |
| uri | string | Yes| URI object to be updated.|
| id | number | Yes| New ID.|
| uri | string | Yes | URI object to be updated.|
| id | number | Yes | New ID. |
**Return value**
| Type| Description|
| Type | Description |
| ------ | --------------- |
| string | URI object with the new ID.|
......
......@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i
```
```js
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
......@@ -28,28 +28,28 @@ class MainAbility extends Ability {
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
| abilityInfo | AbilityInfo | Yes| No| Ability information.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
Starts an ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
Starts an ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
**Example**
```
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions): Promise&lt;void&gt;;
startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result.
Starts an ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| options | StartOptions | No| Parameters used for starting the ability.|
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
this.context.startAbilityForResult(
{bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
(error, result) => {
......@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core
);
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
......@@ -181,8 +180,9 @@ SystemCapability.Ability.AbilityRuntime.Core
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
var options = {
windowMode: 0,
};
......@@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions): Promise&lt;AbilityResult&gt;;
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
Starts an ability. This method uses a promise to return the execution result when the ability is terminated.
Starts an ability. This API uses a promise to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| options | StartOptions | No| Parameters used for starting the ability.|
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
var options = {
windowMode: 0,
};
......@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelf
## AbilityContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result.
Terminates this ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
## terminateSelf
## AbilityContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result.
Terminates this ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelfWithResult
## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
......@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelfWithResult
## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
......@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityByCall
## AbilityContext.startAbilityByCall
startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;&gt; | Promise used to return the caller object to communicate with.|
| Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
......@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## requestPermissionsFromUser
## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
Requests permissions from the user by displaying a pop-up window. This method uses a callback to return the result.
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
this.context.requestPermissionsFromUser(permissions,(result) => {
......@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## requestPermissionsFromUser
## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;
Requests permissions from the user by displaying a pop-up window. This method uses a promise to return the result.
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
this.context.requestPermissionsFromUser(permissions).then((data) => {
......@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## setMissionLabel
## AbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
Sets the label of the ability displayed in the task. This method uses a callback to return the result.
Sets the label of the ability displayed in the task. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
```js
this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
});
```
## setMissionLabel
## AbilityContext.setMissionLabel
setMissionLabel(label: string): Promise&lt;void&gt;
Sets the label of the ability displayed in the task. This method uses a promise to return the result.
Sets the label of the ability displayed in the task. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
```js
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......
......@@ -10,38 +10,39 @@ Provides ability running information.
## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** method in **abilityManager**.
The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**.
```
```js
import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes| No| Information that matches an ability.|
| ability | ElementName | Yes| No| Information that matches an ability. |
| pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.|
| startTime | number | Yes| No| Ability start time.|
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.|
| uid | number | Yes| No| User ID. |
| processName | string | Yes| No| Process name. |
| startTime | number | Yes| No| Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state. |
## abilityManager.AbilityState
Enumerates the ability states.
| Name| Value| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| 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.|
| 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. |
......@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance.
```
```js
import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
......@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage {
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.|
# Ability
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The 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.
Manages the ability lifecycle and context.
......@@ -14,31 +14,33 @@ Manages the ability lifecycle and context.
import Ability from '@ohos.application.Ability';
```
## Attributes
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.|
| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.|
| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.|
| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
## onCreate
## Ability.onCreate
onCreate(want: Want, param: LaunchParam): void
onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
Called to initialize the service logic when an ability is created.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this ability, including the ability name and bundle name.|
| param | LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
| param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName);
......@@ -47,20 +49,23 @@ Called to initialize the service logic when an ability is created.
```
## onWindowStageCreate
## Ability.onWindowStageCreate
onWindowStageCreate(windowStage: window.WindowStage): void
Called when a **WindowStage** is created for this ability.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
......@@ -69,15 +74,17 @@ Called when a **WindowStage** is created for this ability.
```
## onWindowStageDestroy
## Ability.onWindowStageDestroy
onWindowStageDestroy(): void
Called when the **WindowStage** is destroyed for this ability.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
```
**Example**
```js
class myAbility extends Ability {
onWindowStageDestroy() {
console.log('onWindowStageDestroy');
......@@ -86,20 +93,23 @@ Called when the **WindowStage** is destroyed for this ability.
```
## onWindowStageRestore
## Ability.onWindowStageRestore
onWindowStageRestore(windowStage: window.WindowStage): void
Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onWindowStageRestore(windowStage) {
console.log('onWindowStageRestore');
......@@ -108,15 +118,17 @@ Called when the **WindowStage** is restored during the migration of this ability
```
## onDestroy
## Ability.onDestroy
onDestroy(): void;
Called when this ability is destroyed to clear resources.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
```
**Example**
```js
class myAbility extends Ability {
onDestroy() {
console.log('onDestroy');
......@@ -125,15 +137,17 @@ Called when this ability is destroyed to clear resources.
```
## onForeground
## Ability.onForeground
onForeground(): void;
Called when this ability is running in the foreground.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
```
**Example**
```js
class myAbility extends Ability {
onForeground() {
console.log('onForeground');
......@@ -142,15 +156,17 @@ Called when this ability is running in the foreground.
```
## onBackground
## Ability.onBackground
onBackground(): void;
Callback when this ability is switched to the background.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
```
**Example**
```js
class myAbility extends Ability {
onBackground() {
console.log('onBackground');
......@@ -159,25 +175,29 @@ Callback when this ability is switched to the background.
```
## onContinue
## Ability.onContinue
onContinue(wantParam : {[key: string]: any}): boolean;
onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
Called to save data during the ability migration preparation process.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the migration is accepted; returns **false** otherwise.|
| AbilityConstant.OnContinueResult | Continuation result.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onContinue(wantParams) {
console.log('onContinue');
......@@ -188,20 +208,23 @@ Called to save data during the ability migration preparation process.
```
## onNewWant
## Ability.onNewWant
onNewWant(want: Want): void;
Called when the ability startup mode is set to singleton.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Want parameters, such as the ability name and bundle name.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onNewWant(want) {
console.log('onNewWant, want:' + want.abilityName);
......@@ -210,20 +233,23 @@ Called when the ability startup mode is set to singleton.
```
## onConfigurationUpdated
## Ability.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](#section188911144124715) | Yes| New configuration.|
- Example
**Example**
```
```js
class myAbility extends Ability {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
......@@ -237,31 +263,36 @@ Called when the configuration of the environment where the ability is running is
Implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee).
### call
## Caller.call
call(method, data: rpc.Sequenceable): Promise&lt;void&gt;;
call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
Sends sequenceable data to the target ability.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return a response.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{ // Custom sequenceable data structure
num: 0
str: ''
constructor() {}
constructor(name, str) {
this.name = name;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
messageParcel.writeString(this.str);
......@@ -279,11 +310,12 @@ Sends sequenceable data to the target ability.
var caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility",
deviceId: ""
});
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable.
caller.call(method, msg)
.then(() => {
......@@ -291,35 +323,46 @@ Sends sequenceable data to the target ability.
}).catch((e) => {
console.log('Caller call() catch error ' + e);
});
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
}
}
```
### callWithResult
## Caller.callWithResult
callWithResult(method, data: rpc.Sequenceable): Promise&lt;rpc.MessageParcel&gt;;
callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessageParcel&gt;;
Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{
num: 0
str: ''
constructor(name, str) {
this.name = name;
this.str = str;
}
constructor() {}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -338,76 +381,93 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
var caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility",
deviceId: ""
});
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble(1, "world");
caller.callWithResult(method, msg)
.then((data) => {
console.log('Caller call() called');
console.log('Caller callWithResult() called');
let retmsg = new MyMessageAble(0, "");
data.readSequenceable(retmsg);
}).catch((e) => {
console.log('Caller call() catch error ' + e);
console.log('Caller callWithResult() catch error ' + e);
});
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
}
}
```
### release
## Caller.release
release(): void;
Releases the caller interface of the target ability.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
```
**Example**
```js
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility",
deviceId: ""
});
}).then((obj) => {
caller = obj;
try {
caller.release();
} catch (e) {
console.log('Caller Release error ' + e);
}
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
}
}
```
### onRelease
## Caller.onRelease
onRelease(callback: function): void;
onRelease(callback: OnReleaseCallBack): void;
Registers a callback that is invoked when the Stub on the target ability is disconnected.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | function | Yes| Callback used for the **onRelease** method.|
| callback | OnReleaseCallBack | Yes| Callback used for the **onRelease** API.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility",
deviceId: ""
});
}).then((obj) => {
caller = obj;
try {
caller.onRelease((str) => {
console.log(' Caller OnRelease CallBack is called ' + str);
......@@ -415,6 +475,10 @@ Registers a callback that is invoked when the Stub on the target ability is disc
} catch (e) {
console.log('Caller Release error ' + e);
}
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
}
}
```
......@@ -425,26 +489,30 @@ Registers a callback that is invoked when the Stub on the target ability is disc
Implements callbacks for caller notification registration and unregistration.
### on
## Callee.on
on(method: string, callback: function): void;
on(method: string, callback: CaleeCallBack): void;
Registers a caller notification callback, which is invoked when the target ability registers a function.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities.|
| callback | function | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.|
| callback | CaleeCallBack | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{
num: 0
str: ''
constructor() {}
constructor(name, str) {
this.name = name;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
messageParcel.writeString(this.str);
......@@ -474,20 +542,23 @@ Registers a caller notification callback, which is invoked when the target abili
```
### off
## Callee.off
off(method: string): void;
Unregisters a caller notification callback, which is invoked when the target ability registers a function.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| method | string | Yes| Registered notification message string.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
var method = 'call_Function';
export default class MainAbility extends Ability {
......@@ -497,3 +568,20 @@ Unregisters a caller notification callback, which is invoked when the target abi
}
}
```
## OnReleaseCallBack
(msg: string): void;
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | Yes| No| Prototype of the listener function interface registered by the caller.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore |
## CaleeCallBack
(indata: rpc.MessageParcel): rpc.Sequenceable;
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| (indata: rpc.MessageParcel) | rpc.Sequenceable | Yes| No| Prototype of the message listener function interface registered by the callee.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore |
......@@ -4,26 +4,29 @@
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Runtime class for HAP files. It provides methods to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads.
Runtime class for HAP files. It provides APIs to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads.
## Modules to Import
```
```js
import AbilityStage from '@ohos.application.AbilityStage';
```
## onCreate
## AbilityStage.onCreate
onCreate(): void
Called when the application is created.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
```
**Example**
```js
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
......@@ -32,25 +35,29 @@ Called when the application is created.
```
## onAcceptWant
## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string;
Called when a specified ability is started.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, such as the ability name and bundle name.|
- Return value
**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
**Example**
```
```js
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
......@@ -60,23 +67,33 @@ Called when a specified ability is started.
```
## onConfigurationUpdated
## AbilityStage.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the global configuration is updated.
- Parameters
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-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
**Example**
```
```js
class MyAbilityStage extends AbilityStage {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, language:' + config.language);
}
}
```
## AbilityStage.context
Describes the configuration information about the context.
| Name | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-featureAbility.md) | Called when initialization is performed during ability startup.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
......@@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
......@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module.
| eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.|
## createBundleContext
## Context.createBundleContext
createBundleContext(bundleName: string): Context;
Creates an application context.
- **Parameters**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context of the application created.|
- Example
**Example**
```
```js
let test = "com.example.test";
let context = this.context.createBundleContext(test);
```
## getApplicationContext
## Context.getApplicationContext
getApplicationContext(): Context;
Obtains the context of this application.
- Return value
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context obtained.|
- Example
**Example**
```
```js
// This part is mandatory.
let context = this.context.getApplicationContext();
```
# appManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements application management.
......@@ -10,50 +10,159 @@ Implements application management.
## Modules to Import
```
```js
import app from '@ohos.application.appManager';
```
## isRunningInStabilityTest
## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this application is undergoing a stability test. This API uses a callback to return the result.
Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result.|
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example
**Example**
```
```js
import app from '@ohos.application.appManager';
app.isRunningInStabilityTest((err, flag) => {
console.log('startAbility result:' + JSON.stringfy(err);
}
console.log('startAbility result:' + JSON.stringfy(err));
})
```
## isRunningInStabilityTest
## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(): Promise&lt;boolean&gt;
Checks whether this application is undergoing a stability test. This method uses a promise to return the result.
Checks whether this application is undergoing a stability test. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example
**Example**
```
```js
import app from '@ohos.application.appManager';
app.isRunningInStabilityTest().then((flag) => {
console.log('success:' + JSON.stringfy(flag));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(): Promise\<boolean>;
Checks whether this application is running in a RAM constrained device. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDevicePromise(){
app.isRamConstrainedDevicePromise().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
Checks whether this application is running in a RAM constrained device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDeviceCallBack(){
app.isRamConstrainedDevicePromise((err, data) => {
console.log('startAbility result failed:' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
## appManager.getAppMemorySize
getAppMemorySize(): Promise\<number>;
Obtains the memory size of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
**Example**
```js
GetAppMemorySize(){
app.getAppMemorySize().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.getAppMemorySize
getAppMemorySize(callback: AsyncCallback\<number>): void;
Obtains the memory size of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example**
```js
GetAppMemorySizeCallBack(){
app.getAppMemorySize((err, data) => {
console.log('startAbility result failed :' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
......@@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running.
## Modules to Import
```
```js
import Configuration from '@ohos.application.Configuration';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application.|
| colorMode | [ColorMode](js-apis-configurationconstant.md) | 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.|
| direction<sup>9+</sup> | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity<sup>9+</sup> | 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<sup>9+</sup> | number | Yes| No| ID of the display where the application is located.|
......@@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi
## Modules to Import
```
```js
import ConfigurationConstant from '@ohos.application.ConfigurationConstant';
```
## ColorMode
## ConfigurationConstant.ColorMode
The value is obtained through the **ConfigurationConstant.ColorMode** API.
To obtain the value, use **ConfigurationConstant.ColorMode**, for example, **ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT**.
**Example**
```
ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
```
| Name| Value| Description|
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
| COLOR_MODE_DARK | 0 | Dark mode.|
| COLOR_MODE_LIGHT | 1 | Light mode.|
## Direction
## ConfigurationConstant.Direction
To obtain the value, use **ConfigurationConstant.Direction**, for example, **ConfigurationConstant.Direction.DIRECTION_VERTICAL**.
The value is obtained through the **ConfigurationConstant.Direction** API.
**Example**
| Name| Value| Description|
```
ConfigurationConstant.Direction.DIRECTION_VERTICAL
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| DIRECTION_NOT_SET | -1 | Unspecified direction.|
| DIRECTION_VERTICAL | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
| DIRECTION_NOT_SET<sup>9+</sup> | -1 | Unspecified direction.|
| DIRECTION_VERTICAL<sup>9+</sup> | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL<sup>9+</sup> | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity
## ScreenDensity
The value is obtained through the **ConfigurationConstant.ScreenDensity** API.
To obtain the value, use **ConfigurationConstant.ScreenDensity**, for example, **ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET**.
**Example**
```
ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| Name| Value| Description|
| -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.|
| SCREEN_DENSITY_NOT_SET<sup>9+</sup> | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI<sup>9+</sup> | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI<sup>9+</sup> | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI<sup>9+</sup> | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI<sup>9+</sup> | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI<sup>9+</sup> | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI<sup>9+</sup> | 640 | The screen resolution is xxxldpi.|
......@@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering.
## Usage
Before using any methods in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
```
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onForeground() {
......@@ -24,25 +24,24 @@ export default class MainAbility extends Ability {
```
## on
## EventHub.on
on(event: string, callback: Function): void;
Subscribes to an event.
**System capability**:
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.|
| callback | Function | Yes| Callback invoked when the event is triggered.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
......@@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## off
## EventHub.off
off(event: string, callback?: Function): void;
Unsubscribes from an event. If **callback** is specified, this method unsubscribes from the specified callback. If **callback** is not specified, this method unsubscribes from all callbacks in the event.
Unsubscribes from an event. If **callback** is specified, this API unsubscribes from the specified callback. If **callback** is not specified, this API unsubscribes from all callbacks in the event.
**System capability**:
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.|
| callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
......@@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## emit
## EventHub.emit
emit(event: string, ...args: Object[]): void;
Triggers an event.
**System capability**:
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.|
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
......
# ExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core |
# FormBindingData
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData
Creates a **FormBindingData** object.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object or string| No| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object or string| No | Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
- Return value
**Return value**
| Type| Description|
| ----------------------------------- | --------------------------------------- |
| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.|
| Type | Description |
| ----------------------------------- | --------------------------------------- |
| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.|
**Example**
- Example
```
```js
let obj = {"temperature": "21°"};
let formBindingDataObj = formBindingData.createFormBindingData(obj);
```
## FormBindingData
## formBindingData.FormBindingData
data: Object
Describes a **FormBindingData** object.
| Name| Type| Description|
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Description |
| ---- | -------------- | ------------------------------------------------------------ |
| obj | Object or string| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
| data | Object or string| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
# FormExtension
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides **FormExtension** APIs.
......@@ -17,9 +17,9 @@ None
## Attributes
| Name| Type| Readable| Writable| Description|
| Name | Type | Readable| Writable| Description |
| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- |
| context | [FormExtensionContext](js-apis-formextensioncontext.md) | Yes| No| Context of the **FormExtension**. This class is inherited from **ExtensionContext**.|
| context | [FormExtensionContext](js-apis-formextensioncontext.md) | Yes | No | Context of the **FormExtension**. This class is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.Form|
## onCreate
......@@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData
Called to notify the widget provider that a **Form** instance (widget) has been created.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-featureAbility.md#want) | Yes| Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
| want | [Want](js-apis-featureAbility.md#want) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
- Return value
**Return value**
| Type| Description|
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
- Example
**Example**
```
```js
export default class MyFormExtension extends FormExtension {
onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName);
......@@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been
}
```
## onCastToNormal
## FormExtension.onCastToNormal
onCastToNormal(formId: string): void
Called to notify the widget provider that a temporary widget has been converted to a normal one.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ |
| formId | string | Yes| ID of the widget that requests to be converted to a normal one.|
| formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
- Example
**Example**
```
export default class MyFormExtension extends FormExtension {
......@@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted
}
```
## onUpdate
## FormExtension.onUpdate
onUpdate(formId: string): void
Called to notify the widget provider that a widget has been updated. After obtaining the latest data, the caller invokes **updateForm** of the [FormExtensionContext](js-apis-formextensioncontext.md) class to update the widget data.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget that requests to be updated.|
| formId | string | Yes | ID of the widget that requests to be updated.|
- Example
**Example**
```
```js
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
......@@ -105,21 +111,23 @@ Called to notify the widget provider that a widget has been updated. After obtai
}
```
## onVisibilityChange
## FormExtension.onVisibilityChange
onVisibilityChange(newStatus: { [key: string]: number }): void
Called to notify the widget provider of the change of visibility.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes| ID and visibility status of the widget to be changed.|
| newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
- Example
**Example**
```
```js
export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
......@@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility.
}
```
## onEvent
## FormExtension.onEvent
onEvent(formId: string, message: string): void
Called to instruct the widget provider to receive and process the widget event.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- |
| formId | string | Yes| ID of the widget that requests the event.|
| message | string | Yes| Event message.|
| formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes | Event message. |
- Example
**Example**
```
```js
export default class MyFormExtension extends FormExtension {
onEvent(formId, message) {
console.log('FormExtension onEvent, formId:' + formId + ", message:" + message);
......@@ -160,24 +170,50 @@ Called to instruct the widget provider to receive and process the widget event.
}
```
## onDestroy
## FormExtension.onDestroy
onDestroy(formId: string): void
Called to notify the widget provider that a **Form** instance (widget) has been destroyed.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget to be destroyed.|
| formId | string | Yes | ID of the widget to be destroyed.|
- Example
**Example**
```
```js
export default class MyFormExtension extends FormExtension {
onDestroy(formId) {
console.log('FormExtension onDestroy, formId:' + formId);
}
}
```
## FormExtension.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](#section188911144124715) | Yes| New configuration.|
**Example**
```js
class MyFormExtension extends MyFormExtension {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
}
}
```
# FormExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
## updateForm
## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
Updates a widget. This method uses a callback to return the result.
- Parameters
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| formId | string | Yes| ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result indicating whether the method is successfully called.|
| formId | string | Yes | ID of the widget that requests to be updated. |
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result indicating whether the method is successfully called.|
- Example
**Example**
```
```js
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data);
});
```
## updateForm
## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>
Updates a widget. This method uses a promise to return the result.
- Parameters
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.|
| formId | string | Yes | ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
- Return value
**Return value**
| Type| Description|
| Type | Description |
| -------------- | --------------------------------- |
| Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|
- Example
**Example**
```
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
......
......@@ -9,7 +9,9 @@ Provides the permission request result.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. |
......@@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance.
```
```js
import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInfos((error,data) => {
console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data));
......@@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => {
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| uid | number | Yes| No| User ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| processName | string | Yes| No| Process name. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.|
......@@ -9,25 +9,22 @@ Implements the context that provides the capabilities and APIs of **ServiceExten
## startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
Starts an ability. This API uses a callback to return the result.
Starts an ability. This method uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, such as the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
......@@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbility
## ServiceExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result.
Starts an ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, such as the ability name and bundle name.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
......@@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelf
## ServiceExtensionContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result.
Terminates this ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
## terminateSelf
## ServiceExtensionContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result.
Terminates this ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......@@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## connectAbility
## ServiceExtensionContext.connectAbility
connectAbility(want: Want, options: ConnectOptions): number;
Connects this ability to a Service ability.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to connect to, such as the ability name and bundle name.|
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | A number, based on which the connection will be interrupted.|
- Example
```
**Example**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
......@@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## disconnectAbility
## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
Disconnects this ability from the Service ability. This method uses a callback to return the result.
Disconnects this ability from the Service ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
## disconnectAbility
## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number): Promise&lt;void&gt;;
Disconnects this ability from the Service ability. This method uses a promise to return the result.
Disconnects this ability from the Service ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......@@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core
Defines the **ConnectOptions** data structure.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Description|
| -------- | -------- |
| onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| onFailed(code:&nbsp;number) | Called when the connection fails.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onFailed(code:&nbsp;number) | Called when the connection fails.|
......@@ -23,7 +23,7 @@ None
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.|
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## onCreate
......@@ -32,17 +32,17 @@ onCreate(want: Want): void;
Called when an extension is created to initialize the service logic.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Example
```
**Example**
```js
class ServiceExt extends ServiceExtension {
onCreate(want) {
console.log('onCreate, want:' + want.abilityName);
......@@ -57,12 +57,11 @@ onDestroy(): void;
Called when this extension is destroyed to clear resources.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Example**
- Example
```
```js
class ServiceExt extends ServiceExtension {
onDestroy() {
console.log('onDestroy');
......@@ -77,18 +76,18 @@ onRequest(want: Want, startId: number): void;
Called after **onCreate** is invoked when an ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
- Example
```
**Example**
```js
class ServiceExt extends ServiceExtension {
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
......@@ -103,22 +102,23 @@ onConnect(want: Want): rpc.RemoteObject;
Called after **onCreate** is invoked when an ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
- Example
```
**Example**
```js
import rpc from '@ohos.rpc'
class StubTest extends rpc.RemoteObject{
constructor(des) {
......@@ -142,17 +142,17 @@ onDisconnect(want: Want): void;
Called when the ability is disconnected.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Example
```
**Example**
```js
class ServiceExt extends ServiceExtension {
onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册