提交 775d8def 编写于 作者: Z zhangyafei.echo

IssueNo:#I4ZOCL

Description:Add permission request description.
Sig:SIG_ApplicationFramework
Feature or BugFix: Feature
Binary Source: No
Signed-off-by: Nzhangyafei.echo <zhangyafei12@huawei.com>
Change-Id: Ia7d47c6bf28a0b5737b351147a9a328ea9ccb7d3
上级 ad8fa98b
...@@ -199,7 +199,16 @@ function getRemoteDeviceId() { ...@@ -199,7 +199,16 @@ function getRemoteDeviceId() {
``` ```
### 应用向用户申请授权 ### 应用向用户申请授权
应用需要某些权限如存储、位置信息、访问日历时,需要向用户申请授权。具体示例代码如下: 应用需要某些权限如存储、位置信息、访问日历时,需要向用户申请授权。明确需要申请的权限后,在`module.json`中添加待申请的权限,同时通过接口`requestPermissionsFromUser`以动态弹窗的方式向用户申请授权。以访问日历为例,具体示例代码如下:
module.json的修改:
```json
"requestPermissions": [
{
"name": "ohos.permission.READ_CALENDAR"
}
]
```
通过动态弹窗向用户申请授权:
```ts ```ts
let context = this.context let context = this.context
let permissions: Array<string> = ['ohos.permission.READ_CALENDAR'] let permissions: Array<string> = ['ohos.permission.READ_CALENDAR']
......
...@@ -187,7 +187,7 @@ function getRemoteDeviceId() { ...@@ -187,7 +187,7 @@ function getRemoteDeviceId() {
在跨设备场景下,需要向用户申请数据同步的权限。具体示例代码如下: 在跨设备场景下,需要向用户申请数据同步的权限。具体示例代码如下:
```ts ```ts
let context = this.context let context = this.context
let permissions = ohos.permission.DISTRIBUTED_DATASYNC let permissions: Array<string> = ['ohos.permission.DISTRIBUTED_DATASYNC']
context.requestPermissionsFromUser(permissions).then((data) => { context.requestPermissionsFromUser(permissions).then((data) => {
console.log("Succeed to request permission from user with data: "+ JSON.stringify(data)) console.log("Succeed to request permission from user with data: "+ JSON.stringify(data))
}).catch((error) => { }).catch((error) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册