I am developing a calling app. So i need to pick/hangup call from bluetooth device too . But i just can not get the key press event from bluetooth headset. I have tried with Broadcast and audio manager but only getting play/pause, pre and next button callbacks .
public class MediaButtonIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
KeyEvent event = (KeyEvent) intent .getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
}
if (event.getAction() == KeyEvent.ACTION_DOWN) {
//context.sendBroadcast(new Intent(Intents.ACTION_PLAYER_PAUSE));
}
}
}
}
menifest is
<receiver android:name=".net.MediaButtonIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
I need to get the event only when my activity is alive so i have use onKeyDown and dispatchKeyEvent methods of activity too but nothing seems to work. its giving me same result and previous. There must be a way cause System phone app is getting this event starting the dialer. Pls Suggest me some useful way to do it .