Checking if permissions have been granted already by user in Android : <p>I have defined all the dangerous permissions in a String array as below:</p>

<pre><code>String[] perms = {Manifest.permission.READ_CONTACTS,
                      Manifest.permission.READ_PHONE_STATE,
                      Manifest.permission.CALL_PHONE,
                      Manifest.permission.MODIFY_PHONE_STATE};
</code></pre>

<p>Then to check if they have been granted I run this:</p>

<pre><code>for (int i = 0; i &lt; perms.length; i++) {
        if(ContextCompat.checkSelfPermission(this,perms[i])!=PackageManager.PERMISSION_GRANTED)
        {
            ActivityCompat.requestPermissions(this,perms, permsRequestCode);
            break;
        }
    }
</code></pre>

<p>For some reason this does not work. It asks for permission once, and then if I manually disable it from settings, it brings up the dialog box more than once.</p>

<p>How do I fix this?</p>
