Android 如何在插入有线耳机时切换到BT耳机

Android 如何在插入有线耳机时切换到BT耳机,android,bluetooth,headset,Android,Bluetooth,Headset,问题是有线耳机的优先级似乎高于BT耳机。所以这个片段并不能解决这个问题 AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); // also tried with AudioManager.MODE_IN_CALL audioMan

问题是有线耳机的优先级似乎高于BT耳机。所以这个片段并不能解决这个问题

AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE);    

audioManager.setMode(AudioManager.MODE_IN_CALL); // also tried with AudioManager.MODE_IN_CALL
audioManager.setBluetoothScoOn(true);
audioManager.startBluetoothSco();

MediaPlayer mMediaPlayer = MediaPlayer.create(AudioTests.this, R.raw.test_cbr);
mMediaPlayer.start();

虽然这是一种黑客行为,但直接反映在AudioSystem上可能会让您访问此功能。我还没有实现这一功能,但我知道有一些商业应用提供了这一功能(参见市场上的“SoundAbout”应用)

然后,有一个名为“setDeviceConnectionState”的函数,看起来它可以完成这个任务。如果我能做到这一点,我会更新答案,但我想为您提供一个起点(以及其他遇到此问题的人)

AudioSystem的源代码:

不要指望这在所有版本的Android上都能起作用,也不要指望它在未来的版本中得到支持


也就是说,不确定还有其他方法可以做到这一点。

Kiryl:你想通过蓝牙发送音频吗?
        Class reflectedAS = null;
        reflectedAS = Class.forName("android.media.AudioSystem");