891ecfd1创建于 2025年11月5日历史提交

Requesting User Authorization for the Second Time

If an application requests user authorization via a dialog box using requestPermissionsFromUser() and the user denies it, the application cannot show the same dialog box again with this API. The user needs to manually grant the permission in Settings.

The path in Settings is as follows:

Privacy > Permission manager > Permission type (such as Location) > App

Alternatively, start the permission settings dialog box by using requestPermissionOnSetting() and guide the user to grant the permission.

Figure 1 Requesting user authorization for the second time

en_image_location

The following sample code shows how to open the dialog box again to request ohos.permission.APPROXIMATELY_LOCATION.

import { abilityAccessCtrl, Context, common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// ···
          let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
          let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext;
          atManager.requestPermissionOnSetting(context, ['ohos.permission.APPROXIMATELY_LOCATION']).then((data: Array<abilityAccessCtrl.GrantStatus>) => {
            console.info(`requestPermissionOnSetting success, result: ${data}`);
          }).catch((err: BusinessError) => {
            console.error(`requestPermissionOnSetting fail, code: ${err.code}, message: ${err.message}`);
          });