Please refer my question here. This question is an extension to that:
How to check and redirect audio between wired headset and speaker phone?
I was able to partially solve my problem by including the permissions
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
in my Android Manifest for that same piece of code. Now, I am able to enable and disable the phone speakers, but I am not able to turn off my wired headset connection programmatically, when the wired headset is still physically connected to the phone.
Can someone please help me here? Is there a specific intent I can use to disable and enable the wired headset connection?