From 775d8defc3082936fae16acd615ac311f004ac45 Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Sat, 26 Mar 2022 15:33:19 +0800 Subject: [PATCH] IssueNo:#I4ZOCL Description:Add permission request description. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: Ia7d47c6bf28a0b5737b351147a9a328ea9ccb7d3 --- zh-cn/application-dev/ability/stage-ability.md | 11 ++++++++++- zh-cn/application-dev/ability/stage-call.md | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/zh-cn/application-dev/ability/stage-ability.md b/zh-cn/application-dev/ability/stage-ability.md index 6d3015790b..dafb7e4337 100644 --- a/zh-cn/application-dev/ability/stage-ability.md +++ b/zh-cn/application-dev/ability/stage-ability.md @@ -199,7 +199,16 @@ function getRemoteDeviceId() { ``` ### 应用向用户申请授权 -应用需要某些权限如存储、位置信息、访问日历时,需要向用户申请授权。具体示例代码如下: +应用需要某些权限如存储、位置信息、访问日历时,需要向用户申请授权。明确需要申请的权限后,在`module.json`中添加待申请的权限,同时通过接口`requestPermissionsFromUser`以动态弹窗的方式向用户申请授权。以访问日历为例,具体示例代码如下: +module.json的修改: +```json +"requestPermissions": [ + { + "name": "ohos.permission.READ_CALENDAR" + } +] +``` +通过动态弹窗向用户申请授权: ```ts let context = this.context let permissions: Array = ['ohos.permission.READ_CALENDAR'] diff --git a/zh-cn/application-dev/ability/stage-call.md b/zh-cn/application-dev/ability/stage-call.md index bf8d23810f..72821e4911 100644 --- a/zh-cn/application-dev/ability/stage-call.md +++ b/zh-cn/application-dev/ability/stage-call.md @@ -187,7 +187,7 @@ function getRemoteDeviceId() { 在跨设备场景下,需要向用户申请数据同步的权限。具体示例代码如下: ```ts let context = this.context -let permissions = ohos.permission.DISTRIBUTED_DATASYNC +let permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC'] context.requestPermissionsFromUser(permissions).then((data) => { console.log("Succeed to request permission from user with data: "+ JSON.stringify(data)) }).catch((error) => { -- GitLab