[Android Permissions]: 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:

are you testing on which device? version?
can you try official one code which is in docs

The code I shared above is almost the same as the official docs. 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.

@almawhoob0,

I’m facing the same error with a OnePlus device. Did this ever get resolved?

Thanks.

is it working in other devices?

Actually no. I just checked and it’s not working on my Samsung Tablet either. It used to work. I have newer versions of all libraries, but otherwise the code should be the same. Using “ionic run” to launch the app on device.

I figured it out, I think. The permissions didn’t work because the cordova plugin i was using, did not add the proper user-permission requirements to AndroidManifest.xml. So it never got to even asking for pemissions.

means? i don’t understand this.