Detecting bluetooth 'call' button press

2019-05-15 01:27发布

问题:

I have a bluetooth headset which is able to communicate with my phone. It has one large 'call' button which answers/ends calls.

I am trying to make an app which will be able to intercept when the call button is pressed. I have tried using an intent filter:

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

but the call button does not appear to be classified as a media_button

any ideas on how I can achieve this? I would just like to know when the call button is pressed

回答1:

try

android.intent.action.CALL_BUTTON

http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL_BUTTON

I'm not sure about it.. I think it fires for all call buttons, including any physical call buttons on the phone and buttons on the headsets .etc.



回答2:

If the button is currently bringing up the Voice Dialer (mine does), you want ACTION_VOICE_COMMAND. Add the following to your intent filter:

<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />