title: Do Not Disturb mode - always silent incoming calls
body: <p>I have an app with an integrated music player. I don't want the music to be interrupted by incoming calls.</p>
  
  <p>I use following function for that:</p>
  
  <pre><code>public static void updateDoNotDisturbMode(boolean enabled, boolean checkPrefs)
  {
      ...
      AudioManager audioManager = ((AudioManager) MainApp.get().getSystemService(Context.AUDIO_SERVICE));
      NotificationManager notificationManager = (NotificationManager) MainApp.get().getSystemService(Context.NOTIFICATION_SERVICE);
  
      // audioManager.setMode(AudioManager.MODE_IN_CALL);
      if (!enabled)
      {
          audioManager.setStreamSolo(AudioManager.STREAM_MUSIC, false);
          audioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, false);
          audioManager.setStreamMute(AudioManager.STREAM_RING, false);
          audioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
  
          ...
      }
      else
      {
          audioManager.setStreamSolo(AudioManager.STREAM_MUSIC, true);
          audioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, true);
          audioManager.setStreamMute(AudioManager.STREAM_RING, true);
          audioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
  
          ...
      }
  }
  </code></pre>
  
  <p><strong>what works</strong></p>
  
  <ul>
  <li>silent phone if no headphones are connected</li>
  <li>internal music player does play on without interruption if someone calls</li>
  <li>so without headphones connected, everything works perfectly fine</li>
  </ul>
  
  <p><strong>what does not work</strong></p>
  
  <ul>
  <li>if headphones are connected, the standard beep sound is interrupting my music player and is played in the headphones</li>
  </ul>
  
  <p><em>How can I avoid that incoming calls are interrupting my music player even if headphones are connected?</em></p>
  
  <p><strong>TARGET SDK</strong></p>
  
  <p>Only 4.2 and upwarts... (including 5)</p>