capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 172 forks source link

Trigger permissions dialog without navigating to app settings #117

Closed jahnavi310 closed 2 years ago

jahnavi310 commented 2 years ago

Hi there,

I have following function to ask the user for permissions:

async checkPermissionsForScanner(): Promise<boolean> {
    const status = await BarcodeScanner.checkPermission({ force: true });

    if (status.granted) {
      return true;
    } else {
      BarcodeScanner.openAppSettings();
      return false;
    }
  }

I want to be able to trigger the permissions again and not have the user navigate to the app settings, but having only await BarcodeScanner.checkPermission({ force: true }); does not seem to re-trigger the permissions dialog once the user has denied permissions.

Is there a way for me to achieve this?

Thanks in advance

thegnuu commented 2 years ago

Unfortunatley this is not possible. Once the user denied access the app won't be able to request it again without using the app settings. This is by OS definition.

The only way is to add a custom dialog, inform the user and redirect him to the settings...

jahnavi310 commented 2 years ago

@thegnuu - got it. So apparently in the case that the user denies permission once, the native request permission dialog will not open up. The user will have to be redirected or will have to on their own goto the settings screen and toggle the permissions, correct?

thegnuu commented 2 years ago

Exactly yes, on Android there is an "allow once" method as well, this should trigger the native dialog again after the initial request, but as far as I know there is an issue with the implementation right now.

But the check and redirection to the app settings if the permission is denied is a good idea anyways :)