title: How to detect headset button double click in HTC phones with broadcast receiver?
body: <p>I'm developing a headset button controller and use a broadcast receiver for detecting headset button presses.</p>
  
  <pre><code>((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
  </code></pre>
  
  <p><code>onReceive</code> method:</p>
  
  <pre><code>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:
          if (action == KeyEvent.ACTION_DOWN) {
              long time = SystemClock.uptimeMillis();
              // double click
              if (time - sLastClickTime &lt; DOUBLE_CLICK_DELAY)
                  // do something
                  Toast.makeText(context, "BUTTON PRESSED DOUBLE!",
                          Toast.LENGTH_SHORT).show();
              // single click
              else {
                  // do something
                  Toast.makeText(context, "BUTTON PRESSED!",
                          Toast.LENGTH_SHORT).show();
              }
              sLastClickTime = time;
          }
          break;
      }
      abortBroadcast();
  
  }
  </code></pre>
  
  <p>and it works fine.
  The problem is in HTC android phones It can't receive double click. When you double click headset button it dials your last call by default and I can't detect double click in my app.
  Is there any way to disable this action with android APIs?</p>
  
  <p>I tried setting my broadcast receiver's priority to a large number and it didn't work.
  Even I tried to placing a fake/invalid call in phone's call log but I couldn't do that.
  Any Idea how can I solve this problem?</p>