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;
}
精彩评论