title: MediaButtonIntentReceiver not working in Android 4.0+
body: <p>The goal is to intercept broadcasts from the headset, as well as bluetooth eventually, to respond to different types of clicks from the headset to alter the mediaplayer. This solution works fine for all versions prior to ICS.  Here is some of the code and things I have tried:</p>
  
  <pre><code>....
  private BroadcastReceiver mediaButtonReceiver = new MediaButtonIntentReceiver();
  ....
  public void onCreate() {
      ...
      IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
      mediaFilter.setPriority(2147483647); // this is bad...I know
      this.registerReceiver(mediaButtonReceiver, mediaFilter);
      ...
  }
  
  public class MediaButtonIntentReceiver extends BroadcastReceiver {
  
      private KeyEvent event;
  
      public MediaButtonIntentReceiver() {
          super();
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          String intentAction = intent.getAction();
          if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
              return;
          }
          event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
          if (event == null) {
              return;
          }
          try {
              int action = event.getAction();
  
              switch(action) {
  
                  case KeyEvent.ACTION_UP :
                      Log.d("TEST", "BUTTON UP");
                      break;
                  case KeyEvent.ACTION_DOWN :
                  case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE :
                      Log.d("TEST", "BUTTON DOWN");
                      break;
              }
          } catch (Exception e) {
              Log.d("TEST", "THIS IS NOT GOOD");
          }
          abortBroadcast();
      }
  }
  </code></pre>
  
  <p>To try to make this work, it sounds like 4.0+ requires something like this which didnt work:</p>
  
  <pre><code>((AudioManager)getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(new ComponentName(this, MediaButtonIntentReceiver.class));
  </code></pre>
  
  <p>I even tried to add it to the manifest, in addition to the above:</p>
  
  <pre><code>    &lt;receiver android:name=".MediaButtonIntentReceiver" android:enabled="true"&gt;
          &lt;intent-filter android:priority="2147483647" &gt;
              &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>Still no luck.  What am I missing here?  It's certainly a 4.0+/ICS/JellyBean issue...  This is being done in a service, not an activity.</p>