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.

Does not fire failure or success callback when requestPermission() is called

See original GitHub issue

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" />
`

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
prof3ssorSt3v3commented, Mar 28, 2019

cordova platform add android@x.x.x Just replace the x.x.x with the version you want.

If you update Cordova you will automatically get the latest version of cordova-android when calling cordova platform add android

1reaction
prof3ssorSt3v3commented, Mar 28, 2019

It is often an issue of sequencing with these plugins. I have my students building apps using Google maps, geolocation, and other plugins. They have to get the sequence right so everything works properly. My demo app will crash if you rapidly click on the buttons to make multiple requestPermission calls at the same time. I would recommend updating your cordova-android version too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ActivityCompat.requestPermissions not showing dialog box
Here's an example of using requestPermissions() : First, define the permission (as you did in your post) in the manifest, otherwise, your request...
Read more >
Notification.requestPermission cannot be called on load events
The function calls something with a callback and puts the notification event in the callback so that the user is notified when the...
Read more >
Request app permissions - Android Developers
The permissions dialog shown by the system when you call requestPermissions() says what permission your app wants, but doesn't say why.
Read more >
BackgroundGeolocation | React Native Background Geolocation
BackgroundGeolocation.start(function() { console.log("- Start success"); }); } });; example ... Do not execute any API method which will require accessing ...
Read more >
Android Plugin Development Guide - Apache Cordova
Plugins are not instantiated until they are first referenced by a call from ... If the various checks pass, the callbackContext.success() passes the ......
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