Max The Cat Max The Cat - 6 months ago 123
Android Question

Broadcast receiver highest priority not working

I'm doing an application using ACTION_MEDIA_BUTTON handler, but it appears it is always intercepted by MX Player or Apollo and I get no Intent

I've tried both 1000 and 2147483647 priority set in tag and directly after constructor with setPriority

Applications works when no MX Player or Apollo is present

I've also tried using Headset Interceptor app from google play, I tried to deny events to MX Player with Autostarts application - nothing helps

in onCreate:

IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
filter.addAction(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(1000);
registerReceiver(receiver, filter);


in Receiver

@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
// NEVER REACHES HERE WHEN MX PLAYER PRESENT. WORKS IF NOT


in manifest

<receiver
android:name="BCreceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
</receiver>

Answer

To capture headset button one should register receiver in media too in onCreate in Activity

AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), BCreceiver.class.getName()));