cordova-plugin-android-permissions
cordova-plugin-android-permissions copied to clipboard
requestPermission throws an Unknown error
I am getting the following error when requesting the user permission:
{
"error": "requestPermission",
"message": "Unknown error."
}
Here's a code snippet for checking and requesting permission:
let PERMISSIONS_NEEDED = [
this.androidPermissions.PERMISSION.CAMERA,
this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE
];
this.androidPermissions.checkPermission(PERMISSIONS_NEEDED[0]).then((result) => {
// If no permission, request permission.
if (!result.hasPermission || result.hasPermission == false || result.hasPermission == "false") {
alert("REQUEST-PERMISSION");
this.androidPermissions.requestPermissions(PERMISSIONS_NEEDED).then((_) => {
alert("PERMISSION-GIVEN");
})
.catch(err => {
alert("REQUEST-PERMISSION-ERROR: " + JSON.stringify(err)); // <<<<<<<<<<<<<<<< error
});
}
// If permission is already granted, proceed normally.
else {
alert("ALREADY-HAVE-PERMISSION");
}
}
Additional Information:
- Using Ionic 3
-
Android Permissions
plugin has been installed as instructed on the Ionic Official Documentation
Update: The code works on regular Android and iOS devices.
I am only getting the issue with Zebra TC51 (Android 6) – the plugin successfully checks if device has permission or not but it fails to request permission (it was working fine few weeks ago). Additional test has been done on a similar TC device and it is working fine. So, this seems to be a device issue at this point.
I'm using a Samsung S9 running Android 10 and am encountering this issue as well. These are the permissions I'm asking for:
let requestedPermissions = [
this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION,
this.androidPermissions.PERMISSION.CAMERA,
this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE,
this.androidPermissions.PERMISSION.READ_PHONE_STATE
];
I am however bringing in Zebra printer Cordova plugin. I'm not sure if it's related to this or not. https://github.com/iParqDevelopers/zebralink
Also in case it helps. I'm currently only building and having the issue on Android.
$ ionic info
Ionic:
Ionic CLI : 6.12.3 (/Users/DQ/.nvm/versions/node/v10.20.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.5.2
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.2.1
@angular/cli : 10.2.1
@ionic/angular-toolkit : 2.3.3
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 16 other plugins)
Utility:
cordova-res (update available: 0.15.2) : 0.15.1
native-run (update available: 1.3.0) : 1.1.0
System:
Android SDK Tools : 26.1.1 (/Users/DQ/Library/Android/sdk)
ios-deploy : 1.11.0
ios-sim : ios-sim/9.0.0 darwin-x64 node-v10.20.0
NodeJS : v10.20.0 (/Users/DQ/.nvm/versions/node/v10.20.0/bin/node)
npm : 6.14.9
OS : macOS Catalina
Xcode : Xcode 12.3 Build version 12C33
I think I figured out what the issue was for me. I had code that prompts for this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE
permission in the app start-up as well as another place in app resume. Since both of these code area are run at app start-up it would cause the Unknown error
. Once I removed the secondary prompting for permissions everything works as expected.