Skip to content

Instantly share code, notes, and snippets.

@viizki
Created March 20, 2015 07:15
Show Gist options
  • Save viizki/4ae39e25cb2448f24864 to your computer and use it in GitHub Desktop.
Save viizki/4ae39e25cb2448f24864 to your computer and use it in GitHub Desktop.
已插入耳机的情况下,仍然播放外音,而不使用耳机(如:打电话、播放音乐等)
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
try {
// setWiredDeviceConnectionState(int device, int state, String name);
Method method = AudioManager.class.getMethod("setWiredDeviceConnectionState", int.class, int.class, String.class);
method.invoke(audioManager, 4, 0, "headset");
} catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment