How to detect the button press on a bluethooth headset
<p>I have been trying to achive this for 2 days now and i cant seem to find the right answer.
I have been searching for answer on internet and have found this but they dont seem to help me:</p>

<p><a href="http://android.amberfog.com/?p=415" rel="nofollow">http://android.amberfog.com/?p=415</a></p>

<p><a href="http://stackoverflow.com/questions/6287116/android-registering-a-headset-button-click-with-broadcastreceiver">Android - registering a headset button click with BroadcastReceiver</a></p>

<p><a href="http://code.google.com/p/android/issues/detail?id=4963" rel="nofollow">http://code.google.com/p/android/issues/detail?id=4963</a></p>

<p>No matter what i try when i press the button on my head set the phone display the volume level control instead of being catch by my application and do something. If anyone may give  me few tips i will be very thankfull. Here is some of the code:</p>

<pre><code>public class MediaButtonIntentReceiver extends BroadcastReceiver {

public MediaButtonIntentReceiver() {
    super();
}

@Override
public void onReceive(Context context, Intent intent) {
    Log.i("test1'", "test2");
    String intentAction = intent.getAction();
    if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        return;
    }
    KeyEvent event = (KeyEvent) intent
            .getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (event == null) {
        Log.i("test3'", "test4");
        return;
    }
    int action = event.getAction();
    if (action == KeyEvent.ACTION_DOWN) {
        // do something
        Log.i("test5'", "test6");
    }
    abortBroadcast();
}
}





public class MainActivity extends Activity {

private static final String TAG = "BTAudioActivity";

private MediaPlayer mPlayer = null;
private AudioManager amanager = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    amanager = (AudioManager) getSystemService(AUDIO_SERVICE);
    amanager.setBluetoothScoOn(true);
    amanager.startBluetoothSco();
    amanager.setMode(2);

    mPlayer = new MediaPlayer();

    try {
        mPlayer.setDataSource(new FileInputStream("/sdcard/sample.wav")
                .getFD());
        mPlayer.prepare();
        mPlayer.setVolume(8,8);

        mPlayer.start();


    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }




}
    @Override
protected void onResume() {
    // TODO Auto-generated method stub
MediaButtonIntentReceiver mMediaButtonReceiver = new MediaButtonIntentReceiver();
IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
mediaFilter.setPriority(1000);
registerReceiver(mMediaButtonReceiver, mediaFilter);
    super.onResume();
}

@Override
public void onDestroy() {
    mPlayer.stop();
    amanager.setMode(2);
    amanager.setBluetoothScoOn(false);
    super.onDestroy();
}
    }
</code></pre>
