赞
踩
访问控制 / 权限查询和申请
关键代码段示例如下:
- //悬浮窗
- let dc = new DSComponents()
- let context = getContext(this) as common.UIAbilityContext;
- const permissions: Array<Permissions> = ['ohos.permission.SYSTEM_FLOAT_WINDOW'];
- abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, permissions).then(() => {
- try {
- dc.showSubWindow()
- } catch (err) {
- console.error("errCode:" + err.code + ",errMessage:" + err.message);
- }
- })
- //悬浮窗end
完整代码应该是在申请之前,先通过abilityAccessCtrl.createAtManager().checkAccessToken()查询是否已经具备该权限。
具体完整代码示例,请参考文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/request-user-authorization-0000001774279718#ZH-CN_TOPIC_0000001774279718__%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。