How to programmatically choose between Bluetooth and a handset for multimedia audio

I need to have a set of buttons that work as output choices in a JB dialer that selects a “headset,” “speaker,” and “handset.” I can turn the loudspeaker on and off, however switching between the fact that the media output is between a standard phone and a Bluetooth headset eludes me.

How can I build an option like the one in the dialer that controls the multimedia output? I looked through the documentation for bluetooth and audio controls, and nothing seems to work perfectly correctly (e.g. setScoBluetooth, etc.)

+6
source share
1 answer

The implementation of routing policies is platform dependent and therefore may vary slightly between different products, but this is what I suggest:

If an A2DP-enabled device is paired / connected "for multimedia use", it should be the default output device for MUSIC streams. Therefore, if you are not doing anything, the sound should be directed to the A2DP device.

To redirect sound to a speaker instead of an A2DP device, use the AudioManager method setBluetoothA2dpOn with false . This method has been marked as deprecated for a long time, but still exists and performs the advertising action the last time I checked.

To redirect the sound to the speaker, use the VOICE_CALL stream VOICE_CALL and use the AudioManager setMode method to change the mode to MODE_IN_CALL . You can also disable bluetooth with setBluetoothScoOn(false) .

+2
source

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


All Articles