title: Android request ACCESS_NOTIFICATION_POLICY and mute phone
body: <p>I am a beginner Android developer and I have an interesting question at hand. I am trying to mute the phone with </p>
  
  <pre><code>AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
  audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
  </code></pre>
  
  <p>But I am getting the following error</p>
  
  <pre><code>java.lang.SecurityException: Not allowed to change Do Not Disturb state
  </code></pre>
  
  <p>Now I do not understand this, as I am using EasyPermissions (<a href="https://github.com/googlesamples/easypermissions" rel="noreferrer">https://github.com/googlesamples/easypermissions</a>) and requesting the permission</p>
  
  <pre><code>Manifest.permission.ACCESS_NOTIFICATION_POLICY
  </code></pre>
  
  <p>But it does not ask me to allow anything on app startup. I figured this is because ACCESS_NOTIFICATION_POLICY is a non dangerous permission and thus granted at installation time, for which I also added it to my manifest.xml as thus</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /&gt;
  </code></pre>
  
  <p>But it is still not working, my app is crashing because it throws the "Not allowed to change to Do Not Disturb state" error. Wierdly I found that I can request to go to the "Do Not Disturb access" screen with the following code</p>
  
  <pre><code>Intent intent = new Intent(
                      android.provider.Settings
                              .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
   startActivity(intent);
  </code></pre>
  
  <p>What am I doing wrong here? Why cannot I request this permissions as a normal permission? Do I really have to go through the intent to allow my app to mute the phone?</p>