Skip to content Skip to sidebar Skip to footer

How To Detect Headset Button Double Click In Htc Phones With Broadcast Receiver?

I'm developing a headset button controller and use a broadcast receiver for detecting headset button presses. ((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEv

Solution 1:

The solution was so simple. Setting priority to largest integer number (2147483647) instead of largest value defined by Google (1000), in manifest file solves the problem, and phone doesn't dial last number by double clicking and broadcast receiver detects the headset button double click.

<receiverandroid:name=".MediaButtonIntentReceiver"android:enabled="true" ><intent-filterandroid:priority="2147483647"><actionandroid:name="android.intent.action.MEDIA_BUTTON" /></intent-filter></receiver>

Solution 2:

Your solution didn't work for me also it is not best practice.

For others who are having same problem. This is what I used in my music player to handle headset control single and double click. This should work for all headsets.

staticfinallongCLICK_DELAY=500;
staticlonglastClick=0; // oldValuestaticlongcurrentClick= System.currentTimeMillis();

@OverridepublicvoidonReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {

            KeyEventkeyEvent= (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);

            if (keyEvent.getAction() != KeyEvent.ACTION_DOWN)return;

            lastClick = currentClick ;

            currentClick = System.currentTimeMillis();

            if(currentClick - lastClick < CLICK_DELAY ){

                 //This is double click

            } else { 

                 //This is single click

            }
        }

Post a Comment for "How To Detect Headset Button Double Click In Htc Phones With Broadcast Receiver?"