• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Requesting User Authorization for the Second Time
2
3<!--Kit: Ability Kit-->
4<!--Subsystem: Security-->
5<!--Owner: @xia-bubai-->
6<!--SE: @linshuqing; @hehehe-li-->
7<!--TSE: @leiyuqian-->
8
9If an application [requests user authorization](request-user-authorization.md) via a dialog box using [requestPermissionsFromUser()](../../reference/apis-ability-kit/js-apis-abilityAccessCtrl.md#requestpermissionsfromuser9) 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**.
10
11The path in **Settings** is as follows:
12<!--RP1-->
13**Privacy** > **Permission manager** > *Permission type (such as **Location***) > *App*
14<!--RP1End-->
15
16Alternatively, start the permission settings dialog box by using [requestPermissionOnSetting()](../../reference/apis-ability-kit/js-apis-abilityAccessCtrl.md#requestpermissiononsetting12) and guide the user to grant the permission.
17
18**Figure 1** Requesting user authorization for the second time
19
20<!--RP2-->
21![en_image_location](figures/en_image_location_second.png)
22<!--RP2End-->
23
24The following sample code shows how to open the dialog box again to request ohos.permission.APPROXIMATELY_LOCATION.
25
26```ts
27import { abilityAccessCtrl, Context, common } from '@kit.AbilityKit';
28import { BusinessError } from '@kit.BasicServicesKit';
29
30let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
31let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext;
32atManager.requestPermissionOnSetting(context, ['ohos.permission.APPROXIMATELY_LOCATION']).then((data: Array<abilityAccessCtrl.GrantStatus>) => {
33  console.info('data:' + JSON.stringify(data));
34}).catch((err: BusinessError) => {
35  console.error('data:' + JSON.stringify(err));
36});
37```
38