Ionic v3 - Camera Permission

I am trying to request camera and location permissions when the app starts. The location permission works fine, but the camera permission comes back with a status of “always_denied”. Here’s what the code looks like:

  requestCameraPermissions(): Promise<boolean> {
    return new Promise(resolve => {
      if (this.platform.is('android')) {
        this.andPerms.requestPermission(this.andPerms.PERMISSION.CAMERA).then((result) => {
          console.log('Android Perm Request Result:',  result);
          resolve(result.hasPermission);
        });
      } else {
      this.diag.requestRuntimePermission(this.diag.permission.CAMERA).then((authorization) => {
        //this.diag.requestCameraAuthorization().then((authorization) => {
        console.log(`Camera request result: ${authorization}`);
        // resolve the promise to true or false based on whether it was granted
        resolve(authorization === this.diag.permissionStatus.GRANTED);
      });
    }
    });
  }

The result I get back from the android permissions response is always:

Perm Request Result: Object {hasPermission: false}

When I tried the diagnostics approach, “authorization” is always “DENIED_ALWAYS”.

Here’s my ionic info:

Ionic:

ionic (Ionic CLI) : 4.1.2 (C:\Users\HinesRemote\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 7.1.0
Cordova Platforms : android 6.3.0, browser 5.0.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 7 other plugins)

System:

Android SDK Tools : 26.1.1 (C:\android\sdk)
NodeJS : v8.11.2 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10

This is occurring on the Android Emulator and I’m currently trying to see what happens on an iOS simulator. I’ll update with that info when it runs. My Mac is a little lightweight so sometimes it’s really slow.

But otherwise any ideas?

Maybe you are missing the permission request for the camera inside the config.xml?

Take a look here:

Let me know, if it could help you.

Cheers
Unkn0wn0x

Hmmm. I will check but when I use the Camera.getPicture method, it asks for permission, I press Allow and then I’m able to use the camera. Even after that, when I re-run the code above, I get the same results: denied_always or hasPermission is false. So I’m guessing I have the permissions since I’m able to use the camera functionality. I used the normal “ionic cordova plugin add cordova-plugin-camera” command to install.

Yep, that was the answer. I had the plugin installed but it didn’t put the permission in the androidmanifest.xml. So first thing I tried was just manually adding it in the config.xml and it worked. Now I’m going to try to add the usage descriptions and see if it gets added automatically. Thanks so much Unkn0wn0x!!!

I’m glad I could help you. :slight_smile:

Cheers