Detect Headset buttons double click and Long press(click) Android
I am trying the bellow code
public class MediaButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("----onReceive--", " ");
if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
Log.e("----jack out--", " ");
if (intent.getExtras().getInt("state") == 1)// if plugged
Toast.makeText(context, "earphones plugged", Toast.LENGTH_LONG)
.show();
else
Toast.makeText(context, "earphones un-plugged",
Toast.LENGTH_LONG).show();
}
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
Toast.makeText(context, "button pressed", Toast.LENGTH_LONG).show();
// key=intent.getExtras().getString("EXTRA_KEY_EVENT");
}
abortBroadcast();
}
It detects the headset button click correctly
However how can we detect long click and double click for headset