So, I have an app which, when connected to car's HFP, needs to use the car's mic. It works fine without BT, it works fine with a BT headset, but not with HFP - when it is connected to my car's BT it uses HFP speakers but not the mic.
What am I doing wrong? Is it an Android bug?
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();
}
}