cordova-plugin-android-permissions
cordova-plugin-android-permissions copied to clipboard
requestPermission fires error callback without any reason
Hello guys, I'm tring to manage location permissions on my PhoneGap app using this plugin. The problem is that I don't understand why error is being fired.
First, when I'm opening my app after my first install, requestPermission is being called so the grant location permission popup opens on the screen, the problem is that after some ms, the error callback is fired by the requestPermission and I don't know understand why error (and why there's no error message) should be fired before even denying nor granting the permission. I've also tried to do what this guy suggested in #84 but didn't work.
error.error is 'Unknown error.'
This is what I'm doing:
function noPermissionGranted() {
alert('This app requires your location to be used');
navigator.app.exitApp();
}
document.addEventListener('deviceready', e => {
cordova.plugins.permissions.checkPermission(cordova.plugins.permissions.ACCESS_FINE_LOCATION, checkStatus => {
if (!checkStatus.hasPermission) {
cordova.plugins.permissions.requestPermission(cordova.plugins.permissions.ACCESS_FINE_LOCATION, requestStatus => {
console.log('hasPermission: ' + requestStatus.hasPermission);
if (!requestStatus.hasPermission) {
noPermissionGranted();
} else {
replace('/');
}
}, (error) => {
console.log(error.error);
console.log(error.message);
noPermissionGranted();
});
}
});
});
And this is my config.xml android:
<platform name="android">
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="market:*" />
<config-file after="uses-permission" parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>
</platform>
I've tried the app using API level 28 and it works (29 doesn't).
I'm having the same issue. I tried isolating it down just asking for one permission at a time but it seems to error regardless. https://github.com/NeoLSN/cordova-plugin-android-permissions/issues/88#issuecomment-765817058