Cordova multiple permissions

cordova storage permission
cordova plugin-android-permissions ionic
cordova app permissions
cordova internet permission
phonegap not asking for permissions
cordova plugins email permission get_accounts
failed to install cordova plugin android permissions
cordova diagnostic plugin

I need a way to request all permissions at the same time as runtime.

I'm using this plugin https://github.com/NeoLSN/cordova-plugin-android-permissions, but when run the app is running it request me only one permission...one of three at random. And again when I accept the READ_PHONE_STATE permission it is required to restart application for read phone state, in particular incoming number.

The code:

var permissions = cordova.plugins.permissions;
                var list = [
                permissions.READ_SMS,
                permissions.READ_PHONE_STATE,
                permissions.PROCESS_OUTGOING_CALLS
            ];
            permissions.hasPermission(list, checkPermissionCallback, null);
            function checkPermissionCallback(status) {
                if (!status.hasPermission) {

                    permissions.requestPermission(permissions.READ_PHONE_STATE, function (status) {
                        if (!status.hasPermission)
                            error1();
                    }, error1);
                    permissions.requestPermission(permissions.READ_SMS, function (status) {
                        if (!status.hasPermission)
                            error2();
                    }, error2);
                    permissions.requestPermission(permissions.PROCESS_OUTGOING_CALLS, function (status) {
                        if (!status.hasPermission)
                            error3();
                    }, error3);

                }
                function error1() {
                    console.warn('STATE permission is not turned on');
                }
                function error2() {
                    console.warn('SMS permission is not turned on');
                }
                function error3() {
                    console.warn('CALLS permission is not turned on');
                }
            }

Thanks all in advance!

Try Cordova diagnostic plugin.

This plugin has a requestRuntimePermission(). From the docs:

requestRuntimePermissions(): Requests app to be granted authorisation for multiple runtime permissions.

Example:

cordova.plugins.diagnostic.requestRuntimePermissions(function(statuses){
    for (var permission in statuses){
        switch(statuses[permission]){
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                console.log("Permission to use "+permission+" has not been requested yet");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED:
                console.log("Permission denied to use "+permission+" - ask again?");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                console.log("Permission permanently denied to use "+permission+" - guess we won't be using it then!");
                break;
        }
    }
}, function(error){
    console.error("The following error occurred: "+error);
},[
    cordova.plugins.diagnostic.permission.ACCESS_FINE_LOCATION,
    cordova.plugins.diagnostic.permission.ACCESS_COARSE_LOCATION
]);

Need example on how to use for multiple permissions at a time , The documentation needs an example on how to use this for multiple to AlexisCaffa/cordova-plugin-android-permission that referenced this  Android permission Cordova plugin. This plugin is designed for supporting Android new permissions checking mechanism. Since Android 6.0, the Android permissions checking mechanism has been changed. In the past, the permissions were granted by users when they decide to install the app.

I made a solution that works with the cordova-plugin-android-permission you asked for.

The solutions is currently made with AngularJS using ES5, but it can be rewritten to typescript or ES6. You call this promise function when you need one or more permissions and it returns when all permissions have been/already have been accepted.

var getPermissions = function() {
  var defer = $q.defer();

  var permissions = cordova.plugins.permissions;

  var list = [
    permissions.CAMERA,
    permissions.RECORD_AUDIO,
    permissions.WRITE_EXTERNAL_STORAGE
  ];
  var acceptedCount = 0;

  list.forEach(element => {
    permissions.checkPermission(element, function(status) {
      if (status.hasPermission) {
        acceptedCount++;
        console.warn("getPermissions: checkPermission: Current acceptedCount: ", acceptedCount);
        if (acceptedCount === list.length) {
          console.warn("getPermissions: checkPermission: All permissions accepted - continue");
          defer.resolve();
        }
      } else permissions.requestPermission(element, function() {
        console.warn("getPermissions: requestPermission: All permissions accepted - continue");
        defer.resolve();
      }, null);
    }, null);
  });

  return defer.promise;
};

checkPermission or hasPermission with multiple permissions · Issue , readme, there is a example for multiple permission : var list = [ permissions. addProperty(returnObj, KEY_RESULT_PERMISSION, cordova. The plugin's JavaScript interface uses the cordova.exec method as follows: exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]); This marshals a request from the WebView to the Android native side, effectively calling the action method on the service class, with additional arguments passed in the args array.

The solutions made with promise ES6:

checkAppPermissions: function () {
    return new Promise(function (resolve) {
        let permissions = cordova.plugins.permissions;
        let permissionList = [
            permissions.CAMERA,
            permissions.RECORD_AUDIO,
            permissions.WRITE_EXTERNAL_STORAGE
        ];
        let acceptedCount = 0;
        permissionList.forEach(perm => {
            permissions.checkPermission(perm, function (status) {
                if (status.hasPermission) {
                    acceptedCount++;
                    console.log('checkAppPermission: checkPermission: Current acceptedCount: ', acceptedCount);
                    if (acceptedCount === permissionList.length) {
                        console.log('checkAppPermission: checkPermission: All permissions accepted.');
                        resolve();
                    }
                } else permissions.requestPermission(perm, function () {
                    console.log('checkAppPermission: requestPermission: All permissions accepted.');
                    resolve();
                }, null);
            }, null);
        });
    });
},

cordova-plugin-android-permissions, Miss any of our Open RFC calls?Watch the recordings here! » cordova-plugin-​android-permissions. 1.0.2 • Public • Published 8 months ago. I think that it is something wrong in the plugin because when I request a single permission is OK but when I request multiple permissions only show a dialog with one permission, status.hasPermission is false and then redirect to errorCallback. The plugin not show a dialoglike this when I request multiple permissions: 👍

Android Plugins, cnpm install cordova-plugin-wininsoft-android-permissions var permissions = cordova.plugins.permissions; permissions. Example multiple permissions. Android permission Cordova plugin. This plugin is designed for supporting Android new permissions checking mechanism. Since Android 6.0, the Android permissions checking mechanism has been changed. In the past, the permissions were granted by users when they decide to install the app.

Package, PhoneGap works across multiple platforms, chief among them iOS, Android, Granting Permissions Once your setup is complete, you can add all the files to the  To debug, build a native Android app from your Cordova project then connect Chrome DevTools to the remote Webview on the device. – DaveAlden Jun 27 '17 at 6:47 | show 5 more comments

The Modern Web: Multi-device Web Development with HTML5, CSS3, and , This plugin is designed to support Android new permissions checking mechanism. ionic cordova plugin add cordova-plugin-android-permissions npm install  ionic cordova platform rm android ionic cordova platform rm ios ionic cordova plugin rm phonegap-plugin-barcodescanner rm -r plugins rm -r node_modules rm package-lock.json Next remove the phonegap-plugin-barcodescanner of the package.json. Run: npm install ionic cordova platform add android Next do a new build: ionic cordova run android

Comments
  • It work perfectly! Thank you so much! Only problem is when I start the app for the first time it request me only position permission, because I use geolocation plugin, and other 3 permissions are requested at second start of app. How I do solve this problem?
  • Solved!Thank you so much again! But now I have another problem... At first start of app I accept the five permissions (READ_SMS, READ_PHONE_STATE, PROCESS_OUTGOING_CALLS, ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION) but READ_PHONE_STATE when I recive a phone call it not return me a incoming phone number, when i restart the app it work perfectly. How i solve it?
  • Hello. Glad it worked! I suggest you to post a new question about your new problem with the relevant part of your code. This way will be easiest help you. Thanks!