I have an application that uses android.speech.tts.TextToSpeech.speak() to read messages.
Messages should only be read on the connected Bluetooth headset . Therefore, before I call the talk method, I will check AudioManager.isBluetoothA2dpOn();
The implementation of the method of speech:
ttsOptions.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_VOICE_CALL); ttsOptions.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, 1.0f);
This behavior worked as expected for about a year, but recently it fails on Samsung devices only in such a way that it directs sound to the phone's speaker and the message is read out loud.
I was able to fix the routing problem with:
1. AudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
2. mAudioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
3. mAudioManager.startBluetoothSco();
4.Paste a short audio file
If I do these 4 steps, then the audio routing will be fixed and redirected to the Bluetooth headset.
Questions:
Why do Samsung devices send sound to the phone speaker instead of the Bluetooth device?
Any reliable way to check if sound will be routed to the headset instead of AudioManager.isBluetoothA2dpOn(); ?