Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting a Call via Bluetooth Headset VoIP

I am working on a VoIP-Android-App and The app needs to be able to accept/decline call thought Bluetooth headset.

But the problem is that after adding connection to SCO

    audioManager.startBluetoothSco()
    audioManager.isBluetoothScoOn = true

Once I click to the headset button I can hear a sound that usually comes when I accept call using telephony, so I assume that some android system component catch this signal and doesn't throw it further

What I've tried already:

1) Telephony State listener (It is always IDLE)

   val tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
   phoneStateListener = MyPhoneStateListener()
   tm.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)

2) MediaSession + silent noise + media button listener Doesn't work for the first click, second+ clicks handled correctly

3) MEDIA_BUTTON receiver doesn't work

I found a similar question on SO but without the answer how to make it work Accepting a Call via Bluetooth Headset

So is there anyway how I can intercept Bluetooth button click from Bluetooth Headset Service?

like image 409
Sergey Zabelnikov Avatar asked Aug 01 '18 10:08

Sergey Zabelnikov


People also ask

Do Bluetooth headsets work with VoIP?

The connection: VoIP headsets connect directly to your computer (softphone) or other VoIP devices (e.g. VoIP phone). There are two main types of connection – wired and wireless. Wireless VoIP headsets often rely on Bluetooth technology, just like many smartphone headsets.

Can you answer phone calls with Bluetooth headphones?

Before answering a phone call, change the audio route setting in Settings: swipe down to reveal the search field, search Call Audio Routing, and change the audio route to Bluetooth Headset. All incoming calls will be answered through the Bluetooth device even if you press the answer button on the iPhone.


1 Answers

Accepting a Call via Bluetooth Headset

Adding my answer from there to here too.

These events are handled internally in HeadsetStateMachine (under packages/apps/Bluetooth).

These events are forwarded to IBluetoothHeadsetPhone interface. The single application to which all the events are forwarded is defined at run-time by following binding code in HeadsetStateMachine.java. This is to allow phone manufacturers to forward them to custom phone application instead of default one in cases where default one is not used.

Intent intent = new Intent(IBluetoothHeadsetPhone.class.getName());
    intent.setComponent(intent.resolveSystemService(context.getPackageManager(), 0));
    if (intent.getComponent() == null || !context.bindService(intent, mConnection, 0)) {
        Log.e(TAG, "Could not bind to Bluetooth Headset Phone Service");
    }

To make the events get forwarded to your application instead of default phone application you would have to modify aosp code. You would need to intercept the events at one of HeadsetStateMachine , BluetoothHeadsetPhone proxy or the phone application.

Unfortunately what you are looking for is currently not possible without modifying aosp code. Some headsets like Plantronics have custom BT events which are forwarded to all applications - some of the existing VoIP applications support these custom intents to support at-least answering calls for some of the headsets.

like image 136
RocketRandom Avatar answered Oct 15 '22 15:10

RocketRandom