提交 71d56381 编写于 作者: G Gloria

Update docs against 8751+8711+8895

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 b3cc15a8
...@@ -108,7 +108,9 @@ To create Page abilities for an application in the stage model, you must impleme ...@@ -108,7 +108,9 @@ To create Page abilities for an application in the stage model, you must impleme
} }
``` ```
### Obtaining AbilityStage and Ability Configurations ### Obtaining AbilityStage and Ability Configurations
Both the `AbilityStage` and `Ability` classes have the `context` attribute. An application can obtain the context of an `Ability` instance through `this.context` to obtain the configuration details. The following example shows how an application obtains the bundle code directory, HAP file name, ability name, and system language through the `context` attribute in the `AbilityStage` class. The sample code is as follows: Both the `AbilityStage` and `Ability` classes have the `context` attribute. An application can obtain the context of an `Ability` instance through `this.context` to obtain the configuration details.
The following example shows how an application obtains the bundle code directory, HAP file name, ability name, and system language through the `context` attribute in the `AbilityStage` class. The sample code is as follows:
```ts ```ts
import AbilityStage from "@ohos.application.AbilityStage" import AbilityStage from "@ohos.application.AbilityStage"
...@@ -123,7 +125,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -123,7 +125,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("MyAbilityStage hap module mainAbilityName" + currentHapModuleInfo.mainAbilityName) console.log("MyAbilityStage hap module mainAbilityName" + currentHapModuleInfo.mainAbilityName)
let config = this.context.config let config = this.context.config
console.log("MainAbility config language" + config.language) console.log("MyAbilityStage config language" + config.language)
} }
} }
``` ```
...@@ -142,7 +144,7 @@ export default class MainAbility extends Ability { ...@@ -142,7 +144,7 @@ export default class MainAbility extends Ability {
console.log("MainAbility ability name" + abilityInfo.name) console.log("MainAbility ability name" + abilityInfo.name)
let config = this.context.config let config = this.context.config
console.log("MainAbility config language" + config.language) console.log("MyAbilityStage config language" + config.language)
} }
} }
``` ```
......
...@@ -78,7 +78,7 @@ Starts an ability with start options specified. This API uses an asynchronous ca ...@@ -78,7 +78,7 @@ Starts an ability with start options specified. This API uses an asynchronous ca
| 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 ```js
var want = { var want = {
"deviceId": "", "deviceId": "",
...@@ -127,7 +127,7 @@ Starts an ability. This API uses a promise to return the result. ...@@ -127,7 +127,7 @@ Starts an ability. This API uses a promise to return the result.
windowMode: 0, windowMode: 0,
}; };
this.context.startAbility(want, options) this.context.startAbility(want, options)
.then((data) => { .then(() => {
console.log('Operation successful.') console.log('Operation successful.')
}).catch((error) => { }).catch((error) => {
console.log('Operation failed.'); console.log('Operation failed.');
...@@ -407,8 +407,8 @@ Starts a new Service Extension ability. This API uses a promise to return the re ...@@ -407,8 +407,8 @@ Starts a new Service Extension ability. This API uses a promise to return the re
"abilityName": "MainAbility" "abilityName": "MainAbility"
}; };
this.context.startServiceExtensionAbility(want) this.context.startServiceExtensionAbility(want)
.then((data) => { .then(() => {
console.log('---------- startServiceExtensionAbility success, data: -----------', data); console.log('---------- startServiceExtensionAbility success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err); console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
...@@ -477,8 +477,8 @@ Starts a new Service Extension ability with the account ID specified. This API u ...@@ -477,8 +477,8 @@ Starts a new Service Extension ability with the account ID specified. This API u
}; };
var accountId = 100; var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId) this.context.startServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => { .then(() => {
console.log('---------- startServiceExtensionAbilityWithAccount success, data: -----------', data); console.log('---------- startServiceExtensionAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err); console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
...@@ -539,8 +539,8 @@ Stops a Service Extension ability in the same application. This API uses a promi ...@@ -539,8 +539,8 @@ Stops a Service Extension ability in the same application. This API uses a promi
"abilityName": "MainAbility" "abilityName": "MainAbility"
}; };
this.context.stopServiceExtensionAbility(want) this.context.stopServiceExtensionAbility(want)
.then((data) => { .then(() => {
console.log('---------- stopServiceExtensionAbility success, data: -----------', data); console.log('---------- stopServiceExtensionAbility success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err); console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
...@@ -610,8 +610,8 @@ Stops a Service Extension ability in the same application with the account ID sp ...@@ -610,8 +610,8 @@ Stops a Service Extension ability in the same application with the account ID sp
}; };
var accountId = 100; var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId) this.context.stopServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => { .then(() => {
console.log('---------- stopServiceExtensionAbilityWithAccount success, data: -----------', data); console.log('---------- stopServiceExtensionAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err); console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
...@@ -658,8 +658,8 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -658,8 +658,8 @@ Terminates this ability. This API uses a promise to return the result.
**Example** **Example**
```js ```js
this.context.terminateSelf().then((data) => { this.context.terminateSelf().then(() => {
console.log('success:' + JSON.stringify(data)); console.log('success');
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
...@@ -836,11 +836,11 @@ Disconnects a connection. This API uses a promise to return the result. ...@@ -836,11 +836,11 @@ Disconnects a connection. This API uses a promise to return the result.
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
```js ```js
var connectionNumber = 0; var connectionNumber = 0;
this.context.disconnectAbility(connectionNumber).then((data) => { this.context.disconnectAbility(connectionNumber).then(() => {
console.log('disconnectAbility success, data: ', data); console.log('disconnectAbility success');
}).catch((err) => { }).catch((err) => {
console.log('disconnectAbility fail, err: ', err); console.log('disconnectAbility fail, err: ', err);
}); });
...@@ -893,7 +893,7 @@ Obtains the caller interface of the specified ability, and if the specified abil ...@@ -893,7 +893,7 @@ Obtains the caller interface of the specified ability, and if the specified abil
| Promise&lt;Caller&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 ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var caller; var caller;
...@@ -1020,8 +1020,8 @@ Starts an ability with the account ID specified. This API uses a promise to retu ...@@ -1020,8 +1020,8 @@ Starts an ability with the account ID specified. This API uses a promise to retu
windowMode: 0, windowMode: 0,
}; };
this.context.startAbilityWithAccount(want, accountId, options) this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => { .then(() => {
console.log('---------- startAbilityWithAccount success, data: -----------', data); console.log('---------- startAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err); console.log('---------- startAbilityWithAccount fail, err: -----------', err);
...@@ -1044,13 +1044,13 @@ Requests permissions from the user by displaying a dialog box. This API uses an ...@@ -1044,13 +1044,13 @@ Requests permissions from the user by displaying a dialog box. This API uses an
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
var permissions=['com.example.permission'] var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions,(result) => { this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
}); });
``` ```
...@@ -1075,7 +1075,7 @@ Requests permissions from the user by displaying a dialog box. This API uses a p ...@@ -1075,7 +1075,7 @@ Requests permissions from the user by displaying a dialog box. This API uses a p
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result.| | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
var permissions=['com.example.permission'] var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions).then((data) => { this.context.requestPermissionsFromUser(permissions).then((data) => {
...@@ -1103,7 +1103,7 @@ Sets a label for this ability in the mission. This API uses an asynchronous call ...@@ -1103,7 +1103,7 @@ Sets a label for this ability in the mission. This API uses an asynchronous call
| 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 ```js
this.context.setMissionLabel("test",(result) => { this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
...@@ -1132,10 +1132,10 @@ Sets a label for this ability in the mission. This API uses a promise to return ...@@ -1132,10 +1132,10 @@ Sets a label for this ability in the mission. This API uses a promise to return
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
this.context.setMissionLabel("test").then((data) => { this.context.setMissionLabel("test").then(() => {
console.log('success:' + JSON.stringify(data)); console.log('success');
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
...@@ -1158,7 +1158,7 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call ...@@ -1158,7 +1158,7 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
var imagePixelMap; var imagePixelMap;
...@@ -1205,7 +1205,7 @@ Sets an icon for this ability in the mission. This API uses a promise to return ...@@ -1205,7 +1205,7 @@ Sets an icon for this ability in the mission. This API uses a promise to return
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
var imagePixelMap; var imagePixelMap;
...@@ -1224,8 +1224,8 @@ Sets an icon for this ability in the mission. This API uses a promise to return ...@@ -1224,8 +1224,8 @@ Sets an icon for this ability in the mission. This API uses a promise to return
console.log('--------- createPixelMap fail, err: ---------', err) console.log('--------- createPixelMap fail, err: ---------', err)
}); });
this.context.setMissionIcon(imagePixelMap) this.context.setMissionIcon(imagePixelMap)
.then((data) => { .then(() => {
console.log('-------------- setMissionIcon success, data: -------------', data); console.log('-------------- setMissionIcon success -------------');
}) })
.catch((err) => { .catch((err) => {
console.log('-------------- setMissionIcon fail, err: -------------', err); console.log('-------------- setMissionIcon fail, err: -------------', err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册