Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically select between bluetooth and handset for media audio

I need to have a set of buttons that operate like the media output chooser in the JB dialer, that will select "headset" "speaker" and "phone handset". I can turn on and off the speaker fine, however switching between having the media output go between the standard handset and the bluetooth headset eludes me.

How can I build and option like the one in the dialer, that controls media output? I have looked at documentation for bluetooth and Audio controls and nothing seems to be working quite right (such as the setScoBluetooth etc.)

like image 407
Ashterothi Avatar asked Aug 22 '13 17:08

Ashterothi


People also ask

How do I separate phone volume and Bluetooth volume?

You can disable Android's Bluetooth absolute volume feature, which makes the phone's and a Bluetooth device's volume work together. Bluetooth Absolute Volume is enabled on an Android device by default. To disable it, turn on Developer options in the Settings app, then disable the feature in the System setting menu.

How do I switch between Bluetooth and phone speakers?

Tap the small button at the top right of the player notification tile. In the media player pop-up, you'll see a list of connected audio devices. Tap the one you want to switch to.


1 Answers

The implementation of routing policies is platform-specific and therefore might differ slightly between different products, but this is what I'd suggest:

If an A2DP-capable device is paired/connected "for media" use, it should be the default output device for MUSIC streams. So if you do nothing, the audio should be routed to the A2DP device.

To route the audio to the loudspeaker instead of the A2DP device, use the AudioManager's setBluetoothA2dpOn method with the argument false. This method has been marked as deprecated for a long time, but still exists and performs the advertized action last time I checked.

To route the audio to the earpiece, use the VOICE_CALL stream type, and use the AudioManager's setMode method to change the mode to MODE_IN_CALL. You might also want to disable bluetooth with setBluetoothScoOn(false).

like image 85
Michael Avatar answered Oct 11 '22 18:10

Michael