Broadcast receiver highest priority not working

Max The Cat picture Max The Cat · Sep 11, 2013 · Viewed 17.5k times · Source

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

Vipin Sharma picture Vipin Sharma · Dec 26, 2014

Refer to the line "The value must be greater than -1000 and less than 1000." from below link, highest priority is 999 not 1000.

http://developer.android.com/guide/topics/manifest/intent-filter-element.html