如何在Java中以编程方式禁用有线耳机

编程入门 行业动态 更新时间:2024-10-25 12:27:25
本文介绍了如何在Java中以编程方式禁用有线耳机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请在这里参考我的问题.这个问题是对它的扩展:

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中以编程方式禁用有线耳机

本文发布于:2023-11-28 13:25:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中以   耳机   方式   如何在   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!