通过蓝牙耳机VoIP接听电话 [英] Accepting a Call via Bluetooth Headset VoIP

查看:381
本文介绍了通过蓝牙耳机VoIP接听电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发VoIP-Android-App,该应用需要能够通过蓝牙耳机接听/拒绝通话.

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

但是问题是,在向SCO添加连接后

But the problem is that after adding connection to SCO

    audioManager.startBluetoothSco()
    audioManager.isBluetoothScoOn = true

单击耳机按钮后,我可以听到通常在使用电话接听电话时发出的声音,因此我假设某些android系统组件会捕获此信号,并且不会将其进一步抛出

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

我已经尝试过的内容:

1)电话状态侦听器(始终为IDLE)

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 +静音+媒体按钮侦听器 第一次点击无效,第二次+次点击正确处理

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

3)MEDIA_BUTTON接收器不起作用

3) MEDIA_BUTTON receiver doesn't work

我在SO上找到了类似的问题,但没有答案如何使之工作 通过蓝牙耳机接听电话

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

那么无论如何,我该如何拦截来自Bluetooth Headset Service的Bluetooth按钮单击?

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

推荐答案

通过蓝牙耳机接听电话

也从这里添加我的答案.

Adding my answer from there to here too.

这些事件在HeadsetStateMachine中内部处理(在package/apps/Bluetooth下).

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

这些事件转发到IBluetoothHeadsetPhone接口.将所有事件转发到的单个应用程序是在运行时通过遵循HeadsetStateMachine.java中的绑定代码来定义的.这是为了在不使用默认电话的情况下,允许电话制造商将其转发到自定义电话应用,而不是默认电话.

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");
    }

要使事件转发到您的应用程序而不是默认的电话应用程序,您必须修改aosp代码. 您需要在HeadsetStateMachine,BluetoothHeadsetPhone代理或电话应用程序之一处拦截事件.

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.

不幸的是,如果不修改aosp代码,当前无法找到所需的内容.诸如Plantronics之类的某些耳机具有自定义的BT事件,这些事件会转发到所有应用程序-一些现有的VoIP应用程序支持这些自定义的意图,以支持某些耳机的至少接听电话.

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.

这篇关于通过蓝牙耳机VoIP接听电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆