I wrote an android application to receive Bluetooth headset event, but onReceive() is not getting invoked
<p>I wrote an android application to receive Bluetooth headset event, but onReceive() is not getting invoked.though I am not sure if the ACTION_MEDIA_BUTTON is used as an event or would be it other than this event.
<hr />
sample code to implemenent receiver:</p>

<pre><code>import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

public class MediaButtonIntentReceiver extends BroadcastReceiver {

private static final String TAG = "MediaButtonIntentReceiver";
public MediaButtonIntentReceiver() {
    super();
    }


@Override
public void onReceive(Context context, Intent intent) {//OnReceive

    String intentAction = intent.getAction(); //getAction()
    Log.d(TAG, "onReceive called");
    if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
                return;
    }
    KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (event == null) {
                return;
    }
    int action = event.getAction();
       if (action == KeyEvent.ACTION_DOWN) {
    // do something
                Toast.makeText(context, "BUTTON PRESSED!", Toast.LENGTH_SHORT).show(); 
    }
    abortBroadcast();
}
}
</code></pre>

<p><hr /><br>
Activity looks likes this :    </p>

<pre><code>public class myactivity extends Activity {
    private static final String TAG ="Bluetooth_priority";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) { //onCreate 
        super.onCreate(savedInstanceState);
        Log.d(TAG, "Oncreate called");
        setContentView(R.layout.main);
        IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
        MediaButtonIntentReceiver r = new MediaButtonIntentReceiver();
        filter.setPriority(1000); // set teh priority
        registerReceiver(r, filter); //register
    }
}
</code></pre>

<p><hr /><br>
Manifest.xml looks like this :</p>

<pre><code>&lt;receiver android:name="MediaButtonIntentReceiver"&gt;
        &lt;intent-filter android:priority="1000"&gt;
            &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
        &lt;/intent-filter&gt;
</code></pre>

<p>Incase anyone know about this, please reply.Even setting the priority to 2147483647, it doesn't work.</p>
