title: How to pass volume key events to DialogFragment
body: <p>I spent hours to get this simple use case working: when I press the volume hardware buttons, I want to open a DialogFragment. The dialog contains a SeekBar, which should set according the button pressed.</p>
  
  <p>I have several problems here.</p>
  
  <p><strong>First</strong>, I don't know how to pass the KeyEvents to the fragment. I created a BroadcastReceiver and registered it via <code>AudioManager.registerMediaButtonEventReceiver</code>. Additionally, I put the Receiver in the <code>AndroidManifest.xml</code>:</p>
  
  <pre><code>    &lt;receiver android:name=".fragment.ActionbarFragment$MediaButtonEventReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MEDIA_BUTTON"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>But this receiver does only work if I use the following intent filter:</p>
  
  <pre><code>        &lt;intent-filter&gt;
              &lt;action android:name="android.media.VOLUME_CHANGED_ACTION"/&gt;
          &lt;/intent-filter&gt;
  </code></pre>
  
  <p>When I look into the AudioManager.VOLUME_CHANGED_ACTION, you'll find the following comment:</p>
  
  <pre><code> * @hide Broadcast intent when the volume for a particular stream type changes.
   * Includes the stream, the new volume and previous volumes.
   * Notes:
   *  - for internal platform use only, do not make public,
   *  - never used for "remote" volume changes
  </code></pre>
  
  <p>So, it's likely to brake some day and I'd like to avoid this intent. What's the alternative? How do I pass the key events from the hardware buttons to the fragment correctly?</p>
  
  <p><strong>Second</strong>, when the DialogFragment is open, the default Android VolumePanel is shown though I have overridden <code>onKeyDown</code>:</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      return true;
  }
  </code></pre>
  
  <p>As far as I know, fragments don't have their own onKeyDown, so I was wondering why the VolumePanel is shown, when I press the hardware buttons.</p>