In Android, how can I switch between a wired headset and an A2DP BT one?
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.
Thanks.
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();
精彩评论