提交 f765baee 编写于 作者: W wusongqing

updated docs against 5114

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 25306f71
# Context Module # Context Module
> **NOTE**<br/> > **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. >
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the FA model.
## Modules to Import ## Modules to Import
...@@ -834,7 +836,7 @@ Obtains information of the current ability. This API uses an asynchronous callba ...@@ -834,7 +836,7 @@ Obtains information of the current ability. This API uses an asynchronous callba
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- | | -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<[AbilityInfo](#abilityInfo)> | Yes |Callback used to return the ability information.| | callback | AsyncCallback\<[AbilityInfo](#abilityInfo)> | Yes | Callback used to return the ability information.|
**Example** **Example**
...@@ -886,7 +888,7 @@ Obtains the context of the application. ...@@ -886,7 +888,7 @@ Obtains the context of the application.
| Type | Description | | Type | Description |
| --------- |------ | | --------- |------ |
| Context |Application context.| | Context | Application context.|
**Example** **Example**
...@@ -928,14 +930,14 @@ Describes the HAP module information. ...@@ -928,14 +930,14 @@ Describes the HAP module information.
| labelId | number | Yes | No | Module label ID. | | labelId | number | Yes | No | Module label ID. |
| iconId | number | Yes | No | Module icon ID. | | iconId | number | Yes | No | Module icon ID. |
| backgroundImg | string | Yes | No | Module background image. | | backgroundImg | string | Yes | No | Module background image. |
| supportedModes | number | Yes | No | Modes supported by the module. | | supportedModes | number | Yes | No | Running modes supported by the module. |
| reqCapabilities | Array<string> | Yes | No | Capabilities required for module running.| | reqCapabilities | Array<string> | Yes | No | Capabilities required for module running.|
| deviceTypes | Array<string> | Yes | No | An array of supported device types.| | deviceTypes | Array<string> | Yes | No | Device types supported by the module.|
| abilityInfo | Array<AbilityInfo> | Yes | No | Ability information. | | abilityInfo | Array<AbilityInfo> | Yes | No | Ability information. |
| moduleName | string | Yes | No | Module name. | | moduleName | string | Yes | No | Module name. |
| mainAbilityName | string | Yes | No | Name of the entrance ability. | | mainAbilityName | string | Yes | No | Name of the main ability. |
| installationFree | boolean | Yes | No | When installation-free is supported. | | installationFree | boolean | Yes | No | Whether installation-free is supported. |
| mainElementName | string | Yes| No| Information about the entry ability.| | mainElementName | string | Yes| No| Information about the main ability.|
## AppVersionInfo<sup>7+</sup> ## AppVersionInfo<sup>7+</sup>
......
# AbilityContext # AbilityContext
> **NOTE**<br/> > **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
Implements the ability context. This module is inherited from **Context**. Implements the ability context. This module is inherited from **Context**.
...@@ -55,7 +57,7 @@ Starts an ability. This API uses a callback to return the result. ...@@ -55,7 +57,7 @@ Starts an ability. This API uses a callback to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
this.context.startAbility(want, (error) => { this.context.startAbility(want, (error) => {
console.log("error.code = " + error.code) console.log("error.code = " + error.code)
...@@ -85,7 +87,7 @@ Starts an ability. This API uses a callback to return the result. ...@@ -85,7 +87,7 @@ Starts an ability. This API uses a callback to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -123,7 +125,7 @@ Starts an ability. This API uses a promise to return the result. ...@@ -123,7 +125,7 @@ Starts an ability. This API uses a promise to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -374,7 +376,7 @@ Obtains the caller interface of the specified ability, and if the specified abil ...@@ -374,7 +376,7 @@ Obtains the caller interface of the specified ability, and if the specified abil
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
......
# Ability # Ability
> **NOTE**<br> > **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
Manages the ability lifecycle and context. Manages the ability lifecycle and context.
...@@ -347,7 +349,7 @@ Sends sequenceable data to the target ability. ...@@ -347,7 +349,7 @@ Sends sequenceable data to the target ability.
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -420,7 +422,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data ...@@ -420,7 +422,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -459,7 +461,7 @@ Releases the caller interface of the target ability. ...@@ -459,7 +461,7 @@ Releases the caller interface of the target ability.
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -500,7 +502,7 @@ Registers a callback that is invoked when the stub on the target ability is disc ...@@ -500,7 +502,7 @@ Registers a callback that is invoked when the stub on the target ability is disc
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
......
...@@ -923,7 +923,7 @@ Enumerates operation types of the Data ability. ...@@ -923,7 +923,7 @@ Enumerates operation types of the Data ability.
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
| Name | Name | Description | | Name | Value | Description |
| ------------------------------------ | ---------- | ---------------------------------------- | | ------------------------------------ | ---------- | ---------------------------------------- |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. | | FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. |
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI. | | FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI. |
......
# ServiceExtensionContext # ServiceExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
Implements the context that provides the capabilities and APIs of **ServiceExtension**. This class is inherited from **ExtensionContext**. Implements the context that provides the capabilities and APIs of **ServiceExtension**. This class is inherited from **ExtensionContext**.
## Modules to Import
```
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
```
## startAbility ## startAbility
...@@ -25,13 +31,18 @@ Starts an ability. This API uses a callback to return the result. ...@@ -25,13 +31,18 @@ Starts an ability. This API uses a callback to return the result.
**Example** **Example**
```js ```js
let want = { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
"bundleName": "com.example.myapp", class MainAbility extends ExtensionContext {
"abilityName": "com.example.myapp.MyAbility" onWindowStageCreate(windowStage) {
}; let want = {
this.context.startAbility(want, (err) => { "bundleName": "com.example.myapp",
console.log('startAbility result:' + JSON.stringfy(err)); "abilityName": "MyAbility"};
}); this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -58,15 +69,22 @@ Starts an ability. This API uses a promise to return the result. ...@@ -58,15 +69,22 @@ Starts an ability. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let want = { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
"bundleName": "com.example.myapp", class MainAbility extends ExtensionContext {
"abilityName": "com.example.myapp.MyAbility" onWindowStageCreate(windowStage) {
}; let want = {
this.context.startAbility(want).then((data) => { "bundleName": "com.example.myapp",
console.log('success:' + JSON.stringfy(data)); "abilityName": "MyAbility"
}).catch((error) => { };
console.log('failed:' + JSON.stringfy(error)); this.context.startAbility(want).then((data) => {
}); console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
...@@ -87,9 +105,16 @@ Terminates this ability. This API uses a callback to return the result. ...@@ -87,9 +105,16 @@ Terminates this ability. This API uses a callback to return the result.
**Example** **Example**
```js ```js
this.context.terminateSelf((err) => { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('terminateSelf result:' + JSON.stringfy(err)); class MainAbility extends ExtensionContext {
}); onWindowStageCreate(windowStage) {
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -110,11 +135,17 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -110,11 +135,17 @@ Terminates this ability. This API uses a promise to return the result.
**Example** **Example**
```js ```js
this.context.terminateSelf(want).then((data) => { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('success:' + JSON.stringfy(data)); class MainAbility extends ExtensionContext {
}).catch((error) => { onWindowStageCreate(windowStage) {
console.log('failed:' + JSON.stringfy(error)); this.context.terminateSelf().then((data) => {
}); console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
...@@ -144,7 +175,7 @@ Connects this ability to a Service ability. ...@@ -144,7 +175,7 @@ Connects this ability to a Service ability.
```js ```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "MyAbility"
}; };
let options = { let options = {
onConnect: function(elementName, proxy) {}, onConnect: function(elementName, proxy) {},
...@@ -173,9 +204,18 @@ Disconnects this ability from the Service ability. This API uses a callback to r ...@@ -173,9 +204,18 @@ Disconnects this ability from the Service ability. This API uses a callback to r
**Example** **Example**
```js ```js
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility. import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('terminateSelf result:' + JSON.stringfy(err)); class MainAbility extends ExtensionContext {
}); onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection, (err) => {
// connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -202,11 +242,18 @@ Disconnects this ability from the Service ability. This API uses a promise to re ...@@ -202,11 +242,18 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**Example** **Example**
```js ```js
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility. import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('success:' + JSON.stringfy(data)); class MainAbility extends ExtensionContext {
}).catch((error) => { onWindowStageCreate(windowStage) {
console.log('failed:' + JSON.stringfy(error)); let connection=1
}); this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册