Matth56
Matth56

Reputation: 71

Cordova camera permission is DENIED_ALWAYS

I'm building an app with Cordova/angularjs, I'm checking the camera permission like this : `

getCameraAuthorization: function() {
            var deferred = $q.defer();
            cordova.plugins.diagnostic.getCameraAuthorizationStatus(function(status) {
                status = unifyPermissionStatus.bind(this)(status);
                if (status === this.permissionStatus.NOT_REQUESTED) {
                    cordova.plugins.diagnostic.requestCameraAuthorization(function(status) {
                        deferred.resolve(unifyPermissionStatus.bind(this)(status));
                    }.bind(this), function(error) {
                        logger.error('The following error occurred: ' + error);
                        deferred.reject({ error: 1, message: error });
                    }, { externalStorage: false });
                } else {
                    deferred.resolve(status);
                }
            }.bind(this), function(error) {
                logger.error('The following error occurred: ' + error);
                deferred.reject({ error: 1, message: error });
            }, { externalStorage: false });
            return deferred.promise;
        }

`

And it used to work, but not anymore. Now the status I get is 'DENIED_ALWAYS'. It may have been since I passed the project to cordova 8.0 (my only lead here).

Anyone have an idea about what happened ?

Thanks.

Upvotes: 3

Views: 2551

Answers (1)

Matth56
Matth56

Reputation: 71

The problem in my case was that the permission

<uses-permission android:name="android.permission.CAMERA" />

was not added to the androidManifest.xml. So I added a plugin that add permission to the manifest in my config.xml :

<plugin name="cordova-custom-config" spec="../plugins-git/cordova-custom-config-5.0.2" />

And then :

<platform name="android">
    <custom-config-file target="AndroidManifest.xml" parent="/*" mode="merge">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
    </custom-config-file>
</platform>

Upvotes: 1

Related Questions