How to choose a Hands-Free Profile Microphone (HFP)?

So, I have an application that, when connected to an HFP car, should use the car's microphone. It works fine without BT, it works fine with the BT headset, but not with the HFP - when it is connected to my BT car, it uses HFP speakers, but not a microphone.

What am I doing wrong? Is this 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(); } } 
+5
source share

Source: https://habr.com/ru/post/1273295/


All Articles