Android 6.0 not request contact permission

Hi all I have some trouble with ionic and Android M. I need to access to the account saved on the device(like facebook and google). I use cordova-plugin-contact and cordova-device-accout.
All it work on the old version of android but on the >=6.0 the permission alert not work. it is possible to enable permission only in settings of the devices.
in AndroidManifest.xml i add all permission :

    uses-permission android:name="android.permission.READ_CONTACTS" 
    uses-permission android:name="android.permission.WRITE_CONTACTS"
    uses-permission android:name="android.permission.GET_ACCOUNTS" 

thanks in advance

So looking a the plugin, they should already be add those permission already

I tried this out, and indeed the plugins were auto adding the permission upon installing them.

Yes the plugin add all the permission but when i try it on a device the app not show the runtime permission popup.
Infact in settings of the devices the app have the contact permission disabled and it work only when i turn on the permission.
Is there a way to force the open of runtime permission popup for grant the contact permission?

Hmm, I’m not sure to be honest.

Are you saying that the user has the app installed and then is disabling permissions?

yes the app has disabled the contact permission by dafault and it note request the runtime permission.

Ideal case, Plugins should implement the runtime checks for permissions needed on 6.0 and above. For now you can use this plugin to check if you have access to permissions required before calling methods from contacts plugin.

Well the problem is not with the plugin but with the Android 6 security patch update.
According to it the user has to give the permission for all the installed apps manually by going to Settings > Apps > [Name of the app] > Permissions.

Even though the permissions are added in the manifest but it would not appear to be actually granted for Android 6.x
It would work flawlessly for iOS and other android devices.

Yeah. it doesn’t solve your problem but you now know what the problem actually is.
Hope it helped.

Try
<preference name="android-targetSdkVersion" value="22"/>

This worked for me.

Amazing and sad at the time, but that is how we solved the same problem. The question is how long is going to last this issue…

Rollback: if you have the app in google play with sdk version 23, you CAN’T do this :-/

I have solved this issues by keeping the targetSdkVersion to 23 and then using the https://github.com/dpa99c/cordova-diagnostic-plugin.
Make sure you have xcode 8+

Yeah! We are trying that plugin and it seems it is working for android. We have a iOS issue though, not building using XCode 7 EVEN after removing the plugin :-S. Mind this point, maybe you are right on using XCode 8… but I’m pretty afraid about the bugs/wrong feats it could have. We will go on investigating about it, as it is (pretty) weird.

BTW, no permission issues in iOS as in Android.

@telekosmos: If that is the case you make the checking and setting of the permission in separate functions and in the desired controller:

$scope.$on('$ionicView.enter', function() {
    var isAndroid = ionic.Platform.isAndroid();
    if (isAndroid) {
                $scope.getCallPermission();
     }
});

$scope.getCallPermission(); is a function to check the permission :

$scope.getCallPermission = function() {
            cordova.plugins.diagnostic.getPermissionAuthorizationStatus(function(status) {
                switch (status) {
                    case cordova.plugins.diagnostic.runtimePermissionStatus.GRANTED:
                        break;
                    case cordova.plugins.diagnostic.runtimePermissionStatus.NOT_REQUESTED:
                        $scope.setPhonePermission();
                        break;
                    case cordova.plugins.diagnostic.runtimePermissionStatus.DENIED:
                        $scope.setPhonePermission();
                        break;
                    case cordova.plugins.diagnostic.runtimePermissionStatus.DENIED_ALWAYS:
                        $scope.setPhonePermission();
                        break;
                }
            }, function(error) {}, cordova.plugins.diagnostic.runtimePermission.CALL_PHONE);
        };

$scope.setPhonePermission is a function to set the permission for phone calls:

$scope.setPhonePermission = function() {
            cordova.plugins.diagnostic.requestRuntimePermission(function(status) {
                switch (status) {
                    case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                        break;
                    case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                        break;
                    case cordova.plugins.diagnostic.permissionStatus.DENIED:
                        break;
                    case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                        break;
                }
            }, function(error) {}, cordova.plugins.diagnostic.runtimePermission.CALL_PHONE);
        };
1 Like

Hi again
Thanks for the snippet, we can pay a review to our code in the case we can improve it, but I guess more or less our code is pretty much the same.

Our previous issue was “deeper”, in the end we ended up removing and adding ios platform as it seemed something must stay (hard) in cache, xcode or something, rejecting to do a right build once and again. Replacing the platform and the plugins, installing the proper diagnostics 3.1.x plugin worked.

Hey guys! @Abhay1415, @telekosmos
Have you tried the cordova diagnostic plugin on older android versions or I have to choose between API 16-22 and API 22+?

Hi @Meruem!
If your build on playstore is having version 16-22, things will be fine for all the versions, If you have updated the version to 23 and submitted a build on playstore, you can’t roll back.
You will have to use cordova diagnostic plugin to support Android 6 version.

could you please tell me how do you use it URGENT !!
Thanks in advance

please do through: https://github.com/dpa99c/cordova-diagnostic-plugin

this plugin solves the issue
https://www.npmjs.com/package/cordova-plugin-android-permissions