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 obtainedBluetoothHeadsethas a connected bluetooth device. If true, register aBroadcastReceiverwith anIntentFilterthat has the actionsandroid.intent.action.MEDIA_BUTTON,android.media.ACTION_SCO_AUDIO_STATE_UPDATEDandandroid.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGEDand 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.