Arthas
Arthas

Reputation: 145

Android RunTime Permission not granting other permission in the same group

If i request two Permissions from same Group(Ex READ_CONTACTS , WRITE_CONTACTS) one after another the permission dialog asks the user to accept the permission from same group twice, however the documentation mentions if i accept a permission from same group, android automatically grants rest of the permissions in that group.

ex code:

ActivityCompat.requestPermissions((Activity) currentContext,
            new String[]{Manifest.permission.READ_CONTACT},
            MY_PERMISSIONS_REQUEST); 

as it should work a dialog appears requesting the permission, however it appears again if i call the following code

ActivityCompat.requestPermissions((Activity) currentContext,
            new String[]{Manifest.permission.WRITE_CONTACT},
            MY_PERMISSIONS_REQUEST); 

so a dialog for permissions from same group appears twice. Is there a way where i can show only single dialog for permission of same group if i request them in the above fashion ie individually and not together?

Upvotes: 0

Views: 551

Answers (1)

Yoleth
Yoleth

Reputation: 1272

The documentation says :

The dialog box shown by the system describes the permission group your app needs access to; it does not list the specific permission. For example, if you request the READ_CONTACTS permission, the system dialog box just says your app needs access to the device's contacts. The user only needs to grant permission once for each permission group. If your app requests any other permissions in that group (that are listed in your app manifest), the system automatically grants them. When you request the permission, the system calls your onRequestPermissionsResult() callback method and passes PERMISSION_GRANTED, the same way it would if the user had explicitly granted your request through the system dialog box.

That mean that only one alert will be shown for group but you have to request each permissions of this group.

So you should request several permissions in same time :

ActivityCompat.requestPermissions((Activity) currentContext,
            new String[]{Manifest.permission.READ_CONTACT, Manifest.permission.WRITE_CONTACT},
            MY_PERMISSIONS_REQUEST); 

EDIT

To check if permission is already granted you have to use :

if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {
 // ...
}

Upvotes: 2

Related Questions