How do I catch (intercept) a long Bluetooth device call button press (android)?
Asked
Active
Viewed 3,343 times
2 Answers
6
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.

R.daneel.olivaw
- 2,681
- 21
- 31

Dirk Bergstrom
- 2,905
- 2
- 23
- 15
-
Since Jelly Bean wouldn't Google Now intercept that intent instead of your own activity? – Geva Tal Sep 19 '13 at 13:25
2
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;
}

Mats Hofman
- 7,060
- 6
- 33
- 48
-
Thanks for getting back to me. Typically, when you press the Bluetooth headset and its call button for about 2 seconds, it gives a long beep. I've already seen some Android programs using this action instead of a single press on device's button, so I thought this is somewhere defined with its own action. Double press I could use as well, bit that usually auto dials last call. – jjj Oct 17 '11 at 11:33
-
Actually, looking at this KeyEvent.KEYCODE_CALL, are you sure it'll work with press of the call button on a Bluetooth headset device? I am not getting it to work, for some reason... – jjj Oct 17 '11 at 12:12
-
Maybe the Bluetooth headset triggers the `Intent.ACTION_CALL` or the `Intent.ACTION_DIAL`, maybe you can monitor double pressing by checking in your broadcast receiver if the button has been pressed again. – Mats Hofman Oct 17 '11 at 12:16
-
Hm, nothing of that sort. I have just found this article though.I will test and report: http://stackoverflow.com/questions/6287116/android-registering-a-headset-button-click-with-broadcastreceiver – jjj Oct 17 '11 at 13:51
-
It didn't help. I can't figure this out, spending literally days searching entire internet. Is there any authority on these types of things here on this board? – jjj Oct 18 '11 at 23:35