问题描述
请在这里参考我的问题.这个问题是对它的扩展:
Please refer my question here. This question is an extension to that:
我可以通过包含权限来部分解决我的问题
I was able to partially solve my problem by including the permissions
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
在我的Android清单中
使用同一段代码.现在,我可以启用和禁用电话扬声器,但是当有线耳机仍物理连接到电话时,我无法以编程方式关闭有线耳机的连接.
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?
推荐答案
我在网上寻找解决方案并发现了一些问题
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);
}
}
}
}
希望有帮助
如果您想访问该网站,请点击链接链接
If you want to visit the site , here is the link
这篇关于如何在Java中以编程方式禁用有线耳机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!