未验证 提交 d4b6290c 编写于 作者: Q ql 提交者: Gitee

update zh-cn/application-dev/ability/stage-ability.md.

Signed-off-by: Nql <qianli16@huawei.com>
上级 a980b05e
......@@ -163,6 +163,22 @@ context.startAbility(want, options).then((data) => {
})
```
### 跨设备启动Ability
应用可以通过`this.context`获取Ability实例的上下文,获取进而使用AbilityContext中的StartAbility相关接口跨设备启动Ability,所需的对端设备deviceId可通过DeviceManager获取。跨设备启动Ability需在组网认证,并指定对端设备deviceId,具体获取接口参照[DeviceManager](https://gitee.com/openharmony/device_manager/blob/master/README_zh.md)。具体示例代码如下:
```ts
let context = this.context
var want = {
"deviceId": "remoteDeviceId",
"bundleName": "com.example.MyApplication",
"abilityName": "MainAbility"
};
context.startAbility(want).then((data) => {
console.log("Succeed to start remote ability with data: " + JSON.stringify(data))
}).catch((error) => {
console.error("Failed to start remote ability with error: "+ JSON.stringify(error))
})
```
### 应用向用户申请授权
应用需要某些权限如存储、位置信息、访问日历时,需要向用户申请授权。具体示例代码如下:
```ts
......@@ -174,6 +190,16 @@ context.requestPermissionsFromUser(permissions).then((data) => {
console.log("Failed to request permission from user with error: "+ JSON.stringify(error))
})
```
在跨设备场景下,需要向用户申请数据同步的权限。具体示例代码如下:
```ts
let context = this.context
let permissions = ohos.permission.DISTRIBUTED_DATASYNC
context.requestPermissionsFromUser(permissions).then((data) => {
console.log("Succeed to request permission from user with data: "+ JSON.stringify(data))
}).catch((error) => {
console.log("Failed to request permission from user with error: "+ JSON.stringify(error))
})
```
### 系统环境变化通知给AbilityStage及Ability
全局配置,比如系统语言和颜色模式发生变化时,通过onConfigurationUpdated接口通知给AbilityStage和Ability。如下示例展示了AbilityStage的onConfigurationUpdated回调实现,系统语言和颜色模式发生变化时触发该回调。具体示例代码如下:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册