Overview
I'm currently working on an android app that supports VoIP calls (using webrtc). Everything's working perfectly, but now I'm trying to add support for bluetooth headsets. I want the calls to be answered/hangup automatically (without the user touching the device's screen) if:
- The user has a bluetooth headset connected to his device
- The Answer/Hangup button was pressed
Problem
I'm still struggling to make this work. I've read all related stack overflow questions (like this and this), but still no luck. What I've tried:
Obtain the bluetooth profile proxy using
bluetoothAdapter.getProfileProxy(context, serviceListener, BluetoothProfile.HEADSET)
.On the service listener (a
BluetoothProfile.ServiceListener
) check if the obtainedBluetoothHeadset
has a connected bluetooth device. If true, register aBroadcastReceiver
with anIntentFilter
that has the actionsandroid.intent.action.MEDIA_BUTTON
,android.media.ACTION_SCO_AUDIO_STATE_UPDATED
andandroid.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED
and callaudioManager.startBluetoothSco()
.
I'm only receiving broadcasts for the android.media.ACTION_SCO_AUDIO_STATE_UPDATED
action. What's wrong with my approach?
Any help would be appreciated.