harmony 鸿蒙Application Access Control Subsystem Changelog

  • 2023-10-30
  • 浏览 (294)

Application Access Control Subsystem Changelog

cl.access_token.1 Behavior Change When Location Permission Is Requested by requestPermissionsFromUser

Change Impact

Before the change, when requestPermissionsFromUser is called to request the location permission, an authorization dialog box will be displayed in either of the following cases:

After the change, the authorization dialog box cannot be displayed in the preceding two cases. When applying for the ohos.permission.LOCATION or ohos.permission.LOCATION_IN_BACKGROUND permission, the application must also apply for or have the ohos.permission.APPROXIMATELY_LOCATION permission.

Adaptation Guide

Refer to requestPermissionsFromUser when modifying EntryAbility.ets and importing GlobalThis.

import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';
import { GlobalThis } from '../utils/globalThis';

let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
    let context: common.UIAbilityContext = GlobalThis.getInstance().getContext('context');
    atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION', 'ohos.permission.LOCATION_IN_BACKGROUND']).then((data) => {
        console.info('data:' + JSON.stringify(data));
        console.info('data permissions:' + data.permissions);
        console.info('data authResults:' + data.authResults);
    }).catch((err: BusinessError) => {
        console.info('data:' + JSON.stringify(err));
    })
} catch(err) {
    console.log(`catch err->${JSON.stringify(err)}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Bundle Manager Subsystem Changelog

harmony 鸿蒙DFX Subsystem Changelog

harmony 鸿蒙Network Subsystem Changelog

0  赞