If headset was plugged an icon of headset is appeared in status bar.
How to hide headset icon in status bar ? I know that is possible in application https://play.google.com/store/apps/details?id=com.ligq.ikey&hl=ru
AudioManager has private method which is accessible using reflection.
AudioManager manager = (AudioManager) aContext.getSystemService(Context.AUDIO_SERVICE);
try {
int deviceType = AudioSystem.DEVICE_OUT_WIRED_HEADSET;
// turn off headset
int state = 0;
Class<?> cl = Class.forName("android.media.AudioManager");
Method method = cl.getMethod("setWiredDeviceConnectionState", new Class[] {
Integer.TYPE, Integer.TYPE, String.class });
method.invoke(manager, new Object[] { deviceType, state, "device" });
} catch (Exception e) {
iLog.error("disableHeadset, exception {}", ExceptionUtils.getStackTrace(e));
}
All voice passes to earpiece instead headset