In Android java, how do I catch long press on Blue

2019-02-26 21:08发布

How do I catch (intercept) a long Bluetooth device call button press (android)?

2条回答
聊天终结者
2楼-- · 2019-02-26 21:28

You mean the Intent.ACTION_CALL_BUTTON action but than for a long press? That doesn't exist, Android offers only a limited amount of standard actions and long press on physical buttons is not included.

Although if it is possible when your own activity is open, by overriding the onKeyLongPress method in your activity class.

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_CALL) {
        // do your stuff here
        return true;
    }
    return false;
}
查看更多
干净又极端
3楼-- · 2019-02-26 21:31

You're looking for is android.intent.action.VOICE_COMMAND, and it's an Activity intent, not a Receiver intent. You need the following in your manifest:

<activity android:name="LongPressActivity">
    <intent-filter>
        <action android:name="android.intent.action.VOICE_COMMAND"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

The problem arises once your activity starts. Most of the APIs used in the Voice Command application are hidden, so you have to jump through flaming hoops to access them. Either use reflection, or see this series of articles.

查看更多
登录 后发表回答