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



问题是有线耳机似乎优先级高于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"应用程序)。

        Class reflectedAS = null;
        reflectedAS = Class.forName("android.media.AudioSystem");

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

AudioSystem的源代码:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/media/AudioSystem.java#AudioSystem

不要指望它能在所有版本的Android上工作,或者在未来的版本中支持

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

最新更新