提交 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
}
```
### 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
import AbilityStage from "@ohos.application.AbilityStage"
......@@ -123,7 +125,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("MyAbilityStage hap module mainAbilityName" + currentHapModuleInfo.mainAbilityName)
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 {
console.log("MainAbility ability name" + abilityInfo.name)
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
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
......@@ -127,7 +127,7 @@ Starts an ability. This API uses a promise to return the result.
windowMode: 0,
};
this.context.startAbility(want, options)
.then((data) => {
.then(() => {
console.log('Operation successful.')
}).catch((error) => {
console.log('Operation failed.');
......@@ -407,8 +407,8 @@ Starts a new Service Extension ability. This API uses a promise to return the re
"abilityName": "MainAbility"
};
this.context.startServiceExtensionAbility(want)
.then((data) => {
console.log('---------- startServiceExtensionAbility success, data: -----------', data);
.then(() => {
console.log('---------- startServiceExtensionAbility success -----------');
})
.catch((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
};
var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- startServiceExtensionAbilityWithAccount success, data: -----------', data);
.then(() => {
console.log('---------- startServiceExtensionAbilityWithAccount success -----------');
})
.catch((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
"abilityName": "MainAbility"
};
this.context.stopServiceExtensionAbility(want)
.then((data) => {
console.log('---------- stopServiceExtensionAbility success, data: -----------', data);
.then(() => {
console.log('---------- stopServiceExtensionAbility success -----------');
})
.catch((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
};
var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- stopServiceExtensionAbilityWithAccount success, data: -----------', data);
.then(() => {
console.log('---------- stopServiceExtensionAbilityWithAccount success -----------');
})
.catch((err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
......@@ -658,8 +658,8 @@ Terminates this ability. This API uses a promise to return the result.
**Example**
```js
this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.terminateSelf().then(() => {
console.log('success');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
......@@ -836,11 +836,11 @@ Disconnects a connection. This API uses a promise to return the result.
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var connectionNumber = 0;
this.context.disconnectAbility(connectionNumber).then((data) => {
console.log('disconnectAbility success, data: ', data);
this.context.disconnectAbility(connectionNumber).then(() => {
console.log('disconnectAbility success');
}).catch((err) => {
console.log('disconnectAbility fail, err: ', err);
});
......@@ -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.|
**Example**
```js
import Ability from '@ohos.application.Ability';
var caller;
......@@ -1020,8 +1020,8 @@ Starts an ability with the account ID specified. This API uses a promise to retu
windowMode: 0,
};
this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => {
console.log('---------- startAbilityWithAccount success, data: -----------', data);
.then(() => {
console.log('---------- startAbilityWithAccount success -----------');
})
.catch((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
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result.|
**Example**
```js
var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions,(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
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result.|
**Example**
```js
var permissions=['com.example.permission']
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
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
this.context.setMissionLabel("test",(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
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.setMissionLabel("test").then(() => {
console.log('success');
}).catch((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
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example**
```js
import image from '@ohos.multimedia.image'
var imagePixelMap;
......@@ -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.|
**Example**
```js
import image from '@ohos.multimedia.image'
var imagePixelMap;
......@@ -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)
});
this.context.setMissionIcon(imagePixelMap)
.then((data) => {
console.log('-------------- setMissionIcon success, data: -------------', data);
.then(() => {
console.log('-------------- setMissionIcon success -------------');
})
.catch((err) => {
console.log('-------------- setMissionIcon fail, err: -------------', err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册