是否可以同时在蓝牙设备和电话扬声器上收听语音呼叫?

时间:2018-10-31 22:40:16

标签: android bluetooth

我希望能够在蓝牙设备正在记录电话时通过电话拨打电话,所以我想知道是否可以将电话的语音流复制到另一个设备(蓝牙)而普通的电话扬声器和麦克风正在工作。

1 个答案:

答案 0 :(得分:0)

您可以参考AudioManager并实现以下代码。

am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

registerReceiver(new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
Log.d(TAG, "Audio SCO state: " + state);

if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) { 
    /* 
     * Now the connection has been established to the bluetooth device. 
     * Record audio or whatever (on another thread).With AudioRecord you can record with an object created like this:
     * new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
     * AudioFormat.ENCODING_PCM_16BIT, audioBufferSize);
     * After finishing, don't forget to unregister this receiver and
     * to stop the bluetooth connection with am.stopBluetoothSco();
     */
    unregisterReceiver(this);
}

}
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));

Log.d(TAG, "starting bluetooth");
am.startBluetoothSco();

原始讨论可以在here中找到。