简体   繁体   中英

Permission not being called on runtime

I've implemented the permission android.permission.CALL_PHONE . The problem is, when doing tests, the permission is not being asked once it has been canceled.

That is, if I request it at runtime and I say that IF I want to allow calls, it works perfectly, but if I say that I do NOT want to allow calls, I can not get it to be asked again at the next opening of the application.

Would there be any way for the application to request the permission again? If not, is there any way to send the user to the application information to accept it from there?

Thank you.

Short Answer - You cannot ask Permission again if user denied and ticked Never Ask again.

But you can show some meaningful message and ask user to enable permission for your app manually. More you can redirect user to App Permission page under android settings.

You can check whether user has denied it earlier or not using shouldShowRequestPermissionRationale .

You can read more on permissions https://developer.android.com/training/permissions/requesting

I use following codebase to implement permission check

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION) {
        // Permission check if the user granted/denied them you may want to group the rationale in a single dialog        
        for (int i = 0, len = permissions.length; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
            // denied the permission
                boolean showRationale = shouldShowRequestPermissionRationale( permission );
                if (! showRationale) {
                    // User ticked "never ask again"
                    // Show some meaningful message 
                } else if (Manifest.permission.WRITE_CONTACTS.equals(permission)) {
                    showRationale(permission, R.string.permission_denied_contacts);
                    // NOT ticked "never ask again"
                } else if ( /* possibly check more permissions...*/ ) {
                }
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM