所以,我有一个应用程序,当连接到汽车的HFP时,需要使用汽车的麦克风。它在没有BT的情况下工作正常,它可以与BT耳机一起使用,但不适用于HFP - 当它连接到我的汽车的BT时它使用的是HFP扬声器而不是麦克风。
我做错了什么?这是Android的错误吗?
private static boolean isBluetoothHeadsetConnected() {
BluetoothAdapter mBluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
&&
mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) ==
BluetoothHeadset.STATE_CONNECTED;
}
private boolean checkBlueTooth() {
if (!isBluetoothHeadsetConnected()) {
return false;
}
return true;
}
private void useBluetooth() {
AudioManager audioManager;
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkBlueTooth()) {
start();
} else {
BroadcastReceiver scoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1) ==
AudioManager.SCO_AUDIO_STATE_CONNECTED) {
start();
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
this.registerReceiver(scoReceiver, intentFilter);
useBluetooth();
}
}