在超级隐私模式下,应用申请位置、相机和麦克风权限,结果无响应或提示未开启/无权限,未能给出有效引导。


设备开启了超级隐私模式,应用未对此情况做检测,也未能通过适当的方式来提醒用户开启全局开关。
添加校验全局开关是否开启的逻辑,调用requestGlobalSwitch()方法提醒用户重新开启。
具体开发可以参考如下代码,更详细代码参考功能被禁用处理方式文档的示例代码。
- import { abilityAccessCtrl, common } from '@kit.AbilityKit';
- import { geoLocationManager } from '@kit.LocationKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- @Entry
- @Component
- struct LocationTogglePage {
- private context = this.getUIContext().getHostContext() as common.UIAbilityContext;
-
- // 以位置权限为例
- isLocationToggle() {
- let atManager = abilityAccessCtrl.createAtManager();
- // 判断位置服务是否开启
- let isLocationEnabled = geoLocationManager.isLocationEnabled();
- if (!isLocationEnabled) {
- // 拉起弹窗提醒用户关闭超级隐私模式
- atManager.requestGlobalSwitch(this.context, abilityAccessCtrl.SwitchType.LOCATION).then((data: boolean) => {
- if (data) {
- // 已关闭,获取位置权限
- } else {
- // 依旧未关闭
- }
- }).catch((err: BusinessError) => {
- console.error(`requestGlobalSwitch failed, code is ${err.code}, message is ${err.message}`);
- });
- }
- }
- build() {
- Column() {
- Button('位置开关')
- .onClick(() => {
- this.isLocationToggle();
- })
- .margin({top: 40})
- }
- .height('100%')
- .width('100%')
- }
- }