如何检测耳机的按钮双击在HTC的手机与广播接收器? [英] How to detect headset button double click in HTC phones with broadcast receiver?

查看:165
本文介绍了如何检测耳机的按钮双击在HTC的手机与广播接收器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个耳机按钮控制器,并使用广播接收器,用于检测耳机按钮presses。

I'm developing a headset button controller and use a broadcast receiver for detecting headset button presses.

((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

的onReceive 方法:

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 < 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();

}

和它工作正常。
这个问题在HTC Android手机不能接收双击。当你双击耳机按钮默认情况下它拨打您的最后一次通话,我不能检测我的应用程序双击。
有没有什么方法来禁用与Android API的这个动作?

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?

我想我的广播接收器的优先级设置为大量,并没有奏效。
即使我试图把一个假/无效呼叫手机的通话记录,但我不能这样做。
任何想法,我怎么能解决这个问题?

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?

推荐答案

解决方案是如此简单。优先级设置到大整数(2147483647),而不是由谷歌(1000)定义的最大价值,清单文件解决了这个问题,而手机不通过双击和广播接收器拨打最后一个号码检测耳机按钮双击。

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.

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

这篇关于如何检测耳机的按钮双击在HTC的手机与广播接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆