question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestPermission(..) never returns if request has been denied by the user

See original GitHub issue

I expect that a call of cordova.plugins.permissions.requestPermission will always trigger the success callback, even if a user decides that a permission shall not be granted.

Example:

cordova.plugins.permissions.requestPermission(
  cordova.plugins.permissions.CAMERA,
  // I expect this callback to be called, even if the user clicks "DENY".
  // Unfortunately this is not the case.
  p => console.log(`Permission granted: ${p.hasPermission}`),
  e => console.log("An error occured.", e)
);

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
santhu180485commented, Jan 7, 2017

@kristopolous , I am using this plugin and when I select the “Deny” option, the app just gets closed/crashed. Am I missing anything?

0reactions
Truelioncommented, Mar 27, 2019

cordova plugin does not fire a failure or success callback when requestPermission() is called on the very first install of the apk via USB cable or on emulator or from installing an APK build from disk. It does pop the dialog to request geo permissions fine, I grant it, but it never fires a callback. (?)

When i close the app and reopen, geolocation works, because i previously granted. But on very first install, callbacks for requestPermission() does nothing, so app is at standstill. Does anyone know what it could be? Tried on several phones, all identical behavior.

USING window.cordova.plugins:

requestCordovaPermissions() {
    var self = this;
    window.cordova.plugins.permissions.requestPermission(
        window.cordova.plugins.permissions.ACCESS_FINE_LOCATION,
        function(status) {// <-------never fired
            if (status.hasPermission) {
                alert("permission granted") _ //never seen, even if i granted_
            } else {
                alert("unable to get geo location permissions")
            }
        },
        function(e) {//<------ never fired
            alert("Error : " + e)
        }
    )
}


Snippet from AndroidManifest.xml:
`
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
`


config.xml:

`
<feature name="Geolocation">
        <param name="android-package" value="org.apache.cordova.GeoBroker" />
    </feature>
    <engine name="android" spec="^6.3.0" />
    <plugin name="cordova-plugin-android-permissions" spec="^1.0.0" />
    <plugin name="cordova-plugin-exclude-files" spec="^0.4.2" />
    <plugin name="cordova-plugin-fullscreen" spec="^1.2.0" />
    <plugin name="cordova-plugin-geolocation" spec="^4.0.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
`
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android M - check runtime permission - how to determine if the ...
This method returns true if the app has requested this permission previously and the user denied the request. That indicates that you should ......
Read more >
Method to detect if user has selected “Don't Ask Again” while ...
This method returns true if the user has previously denied the request. But if the user has selected “Dont' ask again” this method...
Read more >
permission_handler | Flutter Package - Pub.dev
Rather, developers have to ask the user for permissions while the app is running. This plugin provides a cross-platform (iOS, Android) API to...
Read more >
PermissionsAndroid - React Native
If a user has previously turned off a permission that you prompt for, ... the user allowed or denied the request or does...
Read more >
Using the Permissions API - MDN Web Docs
For example, it can query whether permission to use a particular API is granted or denied, and specifically request permission to use an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found