In my app, I allow the user to switch the audio output between the internal handset speaker, the speakerphone, and a stereo BT (A2DP) headset. If a wired headset is plugged in, it's impossible to select the internal speaker or A2DP. Either way, the sound plays through the wired headset. Is there any way to force it to play through the BT headset?
Using API 5 and higher, all the methods that implicitly set the audio path are deprecated, so I can't figure out a way to do this. Any help would be appreciated.
if wired headset + BT headset is plugged in then it's possible to switch to internal speaker (if you mean android device speakers) or wired headset
AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); // true - switch to internal speakers; false - to wired headsets audioManager.setSpeakerphoneOn(true); mMediaPlayer = MediaPlayer.create(AudioTests.this, R.raw.test_cbr); mMediaPlayer.start();
But in this case it's problem to switch to BT headset. This code doesn't help to switch to
// instead of audioManager.setSpeakerphoneOn(true); audioManager.setMode(0); audioManager.setBluetoothScoOn(true); audioManager.startBluetoothSco();