权限
获取应用已申明的权限清单
ymx.getDeclaredPermissions() .then(res => { alert(JSON.stringify(res)); }); 复制
ymx.getDeclaredPermissions() .then(res => { alert(JSON.stringify(res)); });
指定的权限是否存在于权限清单中
ymx.hasPermissionDeclared({ permission: 'ohos.permission.LOCATION'}).then(res => { alert(JSON.stringify(res));}); 复制
ymx.hasPermissionDeclared({ permission: 'ohos.permission.LOCATION'}).then(res => { alert(JSON.stringify(res));});
是否已获得指定的权限
// 鸿蒙定位ymx.hasPermissionGranted({ permission: 'ohos.permission.LOCATION'}).then(res => { alert(res.granted ? '已授权' : '未授权');}); 复制
// 鸿蒙定位ymx.hasPermissionGranted({ permission: 'ohos.permission.LOCATION'}).then(res => { alert(res.granted ? '已授权' : '未授权');});
打开权限设置界面,手动授权。
// 鸿蒙ymx.openPermissionSetting({ permissions: ['ohos.permission.APPROXIMATELY_LOCATION']}).then(res => { alert(JSON.stringify(res));}).catch(err => { alert(err.message);}); 复制
// 鸿蒙ymx.openPermissionSetting({ permissions: ['ohos.permission.APPROXIMATELY_LOCATION']}).then(res => { alert(JSON.stringify(res));}).catch(err => { alert(err.message);});
请求单个权限
是否已同意授权
// 鸿蒙定位大致范围ymx.requestPermission({ permission: 'ohos.permission.APPROXIMATELY_LOCATION'}).then(res => { alert(res.granted ? '已授权' : '未授权');}); 复制
// 鸿蒙定位大致范围ymx.requestPermission({ permission: 'ohos.permission.APPROXIMATELY_LOCATION'}).then(res => { alert(res.granted ? '已授权' : '未授权');});
请求多个权限
权限组
权限组参数的授权结果
// 鸿蒙ymx.requestPermissions({ permissions: ['ohos.permission.LOCATION', 'ohos.permission.APPROXIMATELY_LOCATION'], openSettingIfDenied: true}).then(res => { alert(JSON.stringify(res));}); 复制
// 鸿蒙ymx.requestPermissions({ permissions: ['ohos.permission.LOCATION', 'ohos.permission.APPROXIMATELY_LOCATION'], openSettingIfDenied: true}).then(res => { alert(JSON.stringify(res));});
权限