开发者

In Android java, how do I catch long press on Bluetooth device call button?

开发者 https://www.devze.com 2023-04-13 07:18 出处:网络
How do I catch (interc开发者_StackOverflowept) a long Bluetooth device call button press (android)?You\'re looking for is android.intent.action.VOICE_COMMAND, and it\'s an Activity intent, not a Recei

How do I catch (interc开发者_StackOverflowept) a long Bluetooth device call button press (android)?


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.


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消