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

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

Merge pull request !2276 from wusongqing/TR1921
# DataUriUtils Module # 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 ## Modules to Import
```js ```js
...@@ -12,15 +15,17 @@ getId(uri: string): number ...@@ -12,15 +15,17 @@ getId(uri: string): number
Obtains the ID attached to the end of a given URI. 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** **Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------------ | | ------ | ------------------------ |
| number | ID obtained from the URI object.| | number | ID obtained from the URI object.|
...@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string ...@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string
Attaches an ID to the end of a given URI. 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.| | uri | string | Yes | URI object to which an ID is to be attached.|
| id | number | Yes| ID to be attached.| | id | number | Yes | ID to be attached. |
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | --------------------- | | ------ | --------------------- |
| string | URI object with the ID attached.| | string | URI object with the ID attached.|
...@@ -69,14 +76,17 @@ deleteId(uri: string): string ...@@ -69,14 +76,17 @@ deleteId(uri: string): string
Deletes the ID from the end of a given URI. Deletes the ID from the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **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** **Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------- | | ------ | ------------------- |
| string | URI object with the ID deleted.| | string | URI object with the ID deleted.|
...@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string ...@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string
Updates the ID in a given URI. Updates the ID in a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------- | | ---- | ------ | ---- | ------------------- |
| uri | string | Yes| URI object to be updated.| | uri | string | Yes | URI object to be updated.|
| id | number | Yes| New ID.| | id | number | Yes | New ID. |
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | --------------- | | ------ | --------------- |
| string | URI object with the new ID.| | string | URI object with the new ID.|
......
...@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i ...@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
class MainAbility extends Ability { class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
...@@ -28,28 +28,28 @@ class MainAbility extends Ability { ...@@ -28,28 +28,28 @@ class MainAbility extends Ability {
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.| | abilityInfo | AbilityInfo | Yes| No| Ability information.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.| | 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 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | 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.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbility ## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| | 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 | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | 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| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
- Example **Example**
```
```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbilityForResult ## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | 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.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
this.context.startAbilityForResult( this.context.startAbilityForResult(
{bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
(error, result) => { (error, result) => {
...@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core
); );
``` ```
## startAbilityForResult ## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | 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 ...@@ -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.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
var options = { var options = {
windowMode: 0, windowMode: 0,
}; };
...@@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | 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| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.| | Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
- Example **Example**
```
```js
var options = { var options = {
windowMode: 0, windowMode: 0,
}; };
...@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelf ## AbilityContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void; 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| | 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) => { this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## terminateSelf ## AbilityContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;; 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| | 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) => { this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelfWithResult ## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | 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.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
this.context.terminateSelfWithResult( this.context.terminateSelfWithResult(
{ {
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
...@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelfWithResult ## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
- Example **Example**
```
```js
this.context.terminateSelfWithResult( this.context.terminateSelfWithResult(
{ {
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
...@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbilityByCall ## AbilityContext.startAbilityByCall
startAbilityByCall(want: Want): Promise&lt;Caller&gt;; 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. 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|
| 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.| | 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|
| 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'; import Ability from '@ohos.application.Ability';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## requestPermissionsFromUser ## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void; 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | 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) => { this.context.requestPermissionsFromUser(permissions,(result) => {
...@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## requestPermissionsFromUser ## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;; 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | permissions | Array&lt;string&gt; | Yes| Permissions to request.|
**Return value**
- Return value | Type| Description|
| 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) => { this.context.requestPermissionsFromUser(permissions).then((data) => {
...@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## setMissionLabel ## AbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void; 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | 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) => { this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
}); });
``` ```
## setMissionLabel ## AbilityContext.setMissionLabel
setMissionLabel(label: string): Promise&lt;void&gt; 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | label | string | Yes| Label of the ability to set.|
- Return value **Return value**
| Type| Description|
| 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) => { this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
......
...@@ -10,38 +10,39 @@ Provides ability running information. ...@@ -10,38 +10,39 @@ Provides ability running information.
## Usage ## 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'; import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => { abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data)); console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
}); });
``` ```
## Attributes ## 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.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID. |
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name. |
| startTime | number | Yes| No| Ability start time.| | startTime | number | Yes| No| Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.| | abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state. |
## abilityManager.AbilityState ## abilityManager.AbilityState
Enumerates the ability states. 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.| | INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state.| | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state.| | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state.| | FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state.| | BACKGROUNDING | 12 | The ability is in the backgrounding state. |
...@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance. ...@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance.
``` ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
...@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage { ...@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage {
## Attributes ## 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**.| | currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.| | config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.|
...@@ -4,26 +4,29 @@ ...@@ -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. > 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 ## Modules to Import
``` ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
``` ```
## AbilityStage.onCreate
## onCreate
onCreate(): void onCreate(): void
Called when the application is created. Called when the application is created.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
``` ```js
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
console.log("MyAbilityStage.onCreate is called") console.log("MyAbilityStage.onCreate is called")
...@@ -32,25 +35,29 @@ Called when the application is created. ...@@ -32,25 +35,29 @@ Called when the application is created.
``` ```
## onAcceptWant ## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string; onAcceptWant(want: Want): string;
Called when a specified ability is started. Called when a specified ability is started.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**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.| | 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|
| 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.| | 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 { class MyAbilityStage extends AbilityStage {
onAcceptWant(want) { onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called"); console.log("MyAbilityStage.onAcceptWant called");
...@@ -60,23 +67,33 @@ Called when a specified ability is started. ...@@ -60,23 +67,33 @@ Called when a specified ability is started.
``` ```
## onConfigurationUpdated ## AbilityStage.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void; onConfigurationUpdated(config: Configuration): void;
Called when the global configuration is updated. Called when the global configuration is updated.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**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.| | 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 { class MyAbilityStage extends AbilityStage {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, language:' + config.language); 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. ...@@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module.
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module. ...@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module.
| eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.| | eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.|
## createBundleContext ## Context.createBundleContext
createBundleContext(bundleName: string): Context; createBundleContext(bundleName: string): Context;
Creates an application context. Creates an application context.
- **Parameters** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.| | bundleName | string | Yes| Application bundle name.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Context | Context of the application created.| | Context | Context of the application created.|
- Example **Example**
``` ```js
let test = "com.example.test"; let test = "com.example.test";
let context = this.context.createBundleContext(test); let context = this.context.createBundleContext(test);
``` ```
## getApplicationContext ## Context.getApplicationContext
getApplicationContext(): Context; getApplicationContext(): Context;
Obtains the context of this application. Obtains the context of this application.
- Return value **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Context | Context obtained.| | Context | Context obtained.|
- Example **Example**
``` ```js
// This part is mandatory. // This part is mandatory.
let context = this.context.getApplicationContext(); let context = this.context.getApplicationContext();
``` ```
# appManager # appManager
> ![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. > 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. Implements application management.
...@@ -10,50 +10,159 @@ Implements application management. ...@@ -10,50 +10,159 @@ Implements application management.
## Modules to Import ## Modules to Import
``` ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
``` ```
## isRunningInStabilityTest ## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void 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|
| 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'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest((err, flag) => { 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; 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|
| 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'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest().then((flag) => { app.isRunningInStabilityTest().then((flag) => {
console.log('success:' + JSON.stringfy(flag)); console.log('success:' + JSON.stringfy(flag));
)).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(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. ...@@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running.
## Modules to Import ## Modules to Import
``` ```js
import Configuration from '@ohos.application.Configuration'; import Configuration from '@ohos.application.Configuration';
``` ```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application.| | 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**.| | 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**.| | direction<sup>9+</sup> | 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).| | 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 | number | Yes| No| ID of the display where the application is located.| | 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 ...@@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi
## Modules to Import ## Modules to Import
``` ```js
import ConfigurationConstant from '@ohos.application.ConfigurationConstant'; 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_NOT_SET | -1 | Unspecified color mode.|
| COLOR_MODE_DARK | 0 | Dark mode.| | COLOR_MODE_DARK | 0 | Dark mode.|
| COLOR_MODE_LIGHT | 1 | Light 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_NOT_SET<sup>9+</sup> | -1 | Unspecified direction.|
| DIRECTION_VERTICAL | 0 | Vertical direction.| | DIRECTION_VERTICAL<sup>9+</sup> | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL | 1 | Horizontal 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_NOT_SET<sup>9+</sup> | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.| | SCREEN_DENSITY_SDPI<sup>9+</sup> | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.| | SCREEN_DENSITY_MDPI<sup>9+</sup> | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.| | SCREEN_DENSITY_LDPI<sup>9+</sup> | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.| | SCREEN_DENSITY_XLDPI<sup>9+</sup> | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.| | SCREEN_DENSITY_XXLDPI<sup>9+</sup> | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.| | SCREEN_DENSITY_XXXLDPI<sup>9+</sup> | 640 | The screen resolution is xxxldpi.|
...@@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering. ...@@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering.
## Usage ## 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' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onForeground() { onForeground() {
...@@ -24,25 +24,24 @@ export default class MainAbility extends Ability { ...@@ -24,25 +24,24 @@ export default class MainAbility extends Ability {
``` ```
## on ## EventHub.on
on(event: string, callback: Function): void; on(event: string, callback: Function): void;
Subscribes to an event. Subscribes to an event.
**System capability**: **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| callback | Function | Yes| Callback invoked when the event is triggered.| | callback | Function | Yes| Callback invoked when the event is triggered.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## off ## EventHub.off
off(event: string, callback?: Function): void; 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|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.| | callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## emit ## EventHub.emit
emit(event: string, ...args: Object[]): void; emit(event: string, ...args: Object[]): void;
Triggers an event. Triggers an event.
**System capability**: **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.| | ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
......
# ExtensionContext # 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. > 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**. ...@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**.
| Name| Type| Readable| Writable| Description| | 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 # 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. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData ...@@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData
Creates a **FormBindingData** object. Creates a **FormBindingData** object.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| 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.|
| 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| | Type | Description |
| ----------------------------------- | --------------------------------------- | | ----------------------------------- | --------------------------------------- |
| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.| | [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.|
**Example**
- Example ```js
```
let obj = {"temperature": "21°"}; let obj = {"temperature": "21°"};
let formBindingDataObj = formBindingData.createFormBindingData(obj); let formBindingDataObj = formBindingData.createFormBindingData(obj);
``` ```
## FormBindingData ## formBindingData.FormBindingData
data: Object
Describes a **FormBindingData** 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 # FormExtension
> ![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. > 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. Provides **FormExtension** APIs.
...@@ -17,9 +17,9 @@ None ...@@ -17,9 +17,9 @@ None
## Attributes ## 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 ## onCreate
...@@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData ...@@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData
Called to notify the widget provider that a **Form** instance (widget) has been created. 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.| | [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 { export default class MyFormExtension extends FormExtension {
onCreate(want) { onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName); console.log('FormExtension onCreate, want:' + want.abilityName);
...@@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been
} }
``` ```
## onCastToNormal ## FormExtension.onCastToNormal
onCastToNormal(formId: string): void onCastToNormal(formId: string): void
Called to notify the widget provider that a temporary widget has been converted to a normal one. Called to notify the widget provider that a temporary widget has been converted to a normal one.
- 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 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 { export default class MyFormExtension extends FormExtension {
...@@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted ...@@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted
} }
``` ```
## onUpdate ## FormExtension.onUpdate
onUpdate(formId: string): void 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. 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 { export default class MyFormExtension extends FormExtension {
onUpdate(formId) { onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + 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 ...@@ -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 onVisibilityChange(newStatus: { [key: string]: number }): void
Called to notify the widget provider of the change of visibility. Called to notify the widget provider of the change of visibility.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | 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 { export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) { onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus); console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
...@@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility. ...@@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility.
} }
``` ```
## onEvent ## FormExtension.onEvent
onEvent(formId: string, message: string): void onEvent(formId: string, message: string): void
Called to instruct the widget provider to receive and process the widget event. Called to instruct the widget provider to receive and process the widget event.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- | | ------- | ------ | ---- | ---------------------- |
| formId | string | Yes| ID of the widget that requests the event.| | formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes| Event message.| | message | string | Yes | Event message. |
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onEvent(formId, message) { onEvent(formId, message) {
console.log('FormExtension onEvent, formId:' + formId + ", message:" + 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. ...@@ -160,24 +170,50 @@ Called to instruct the widget provider to receive and process the widget event.
} }
``` ```
## onDestroy ## FormExtension.onDestroy
onDestroy(formId: string): void onDestroy(formId: string): void
Called to notify the widget provider that a **Form** instance (widget) has been destroyed. 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 { export default class MyFormExtension extends FormExtension {
onDestroy(formId) { onDestroy(formId) {
console.log('FormExtension onDestroy, formId:' + 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 # 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. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**. Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
## updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
Updates a widget. This method uses a callback to return the result. 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.| | 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.| | 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.| | 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"}); let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{ this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data); console.log('FormExtension context updateForm, data:' + data);
}); });
``` ```
## updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void> updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>
Updates a widget. This method uses a promise to return the result. 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.| | 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.| | 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.| | 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"}); let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
......
...@@ -9,7 +9,9 @@ Provides the permission request result. ...@@ -9,7 +9,9 @@ Provides the permission request result.
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested. <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. <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. |
...@@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance. ...@@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance.
``` ```js
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInfos((error,data) => { appManager.getProcessRunningInfos((error,data) => {
console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data)); console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data));
...@@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => { ...@@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => {
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | 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 ...@@ -9,25 +9,22 @@ Implements the context that provides the capabilities and APIs of **ServiceExten
## startAbility ## startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; 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 capability**: SystemCapability.Ability.AbilityRuntime.Core
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | 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.| | 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 = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbility ## ServiceExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;; 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| | 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.| | 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| | 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 = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelf ## ServiceExtensionContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void; 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| | 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) => { this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## terminateSelf ## ServiceExtensionContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;; 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| | 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) => { this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## connectAbility ## ServiceExtensionContext.connectAbility
connectAbility(want: Want, options: ConnectOptions): number; connectAbility(want: Want, options: ConnectOptions): number;
Connects this ability to a Service ability. 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| | 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.| | 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.| | 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| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | A number, based on which the connection will be interrupted.| | number | A number, based on which the connection will be interrupted.|
- Example **Example**
```
```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## disconnectAbility ## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | 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. this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## disconnectAbility ## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number): Promise&lt;void&gt;; 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | connection | number | Yes| Number returned after **connectAbility** is called.|
- Return value **Return value**
| Type| Description| | 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. this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core
Defines the **ConnectOptions** data structure. Defines the **ConnectOptions** data structure.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Description| | 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| | 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.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onFailed(code:&nbsp;number) | Called when the connection fails.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | onFailed(code:&nbsp;number) | Called when the connection fails.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册