Accepting a Call via Bluetooth Headset VoIP
Asked Answered
C

1

15

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?

Comedian answered 1/8, 2018 at 10:20 Comment(3)
good question. but i worked on accepting call automatically in android , i was able to reject call automatically through telephony interface but not found solution for accept callCrocker
So do I, you can listen to SCO status and end call on disconnecting, but how to replicate the same for answering the call still a mysteryComedian
I tried many days , but i learned one thing that android gives permission to reject call , but accept call permission is system permission , and android will give system permission only to system appsCrocker
R
2

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.

Radferd answered 7/8, 2018 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.