问题
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?
回答1:
I looked for a solution online and found something
private class MusicIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
audioManager.setSpeakerphoneOn(true);
break;
case 1:
audioManager.setSpeakerphoneOn(false);
break;
default:
audioManager.setSpeakerphoneOn(true);
}
}
}
}
Hope it helps
If you want to visit the site , here is the link
来源:https://stackoverflow.com/questions/20949769/how-to-disable-the-wired-headset-programmatically-in-java