I want my app to do some specific actions when user long clicks (press and hold) headset button. I use a BroadcastReceiver
for MEDIA_BUTTON
and it works fine in phones who doesn't run Google now app for sound actions for long press. But in the phones that automatically run Google now my app is just being ignored. How can I disable Google now and detect headset button long click. here is onReceive
method in my BroadcastReceiver
class.
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
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();
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_HEADSETHOOK:
/**
* for long click
*/
if (action == KeyEvent.ACTION_DOWN) {
if (!isDown) {
isDown = true;
handler.postDelayed(l, LONG_CLICK_DELAY);
}
}
if (action == KeyEvent.ACTION_UP) {
/**
* for long click
*/
if (isDown)
isDown = false;
}
break;
}
abortBroadcast();
}