当前位置: 动力学知识库 > 问答 > 编程问答 >

bluetooth - 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();
分享给朋友:
您可能感兴趣的文章:
随机阅读: