检测耳机是否插入到Android设备或没有。 [英] Detecting whether a headset is plugged into an Android device or not.

查看:187
本文介绍了检测耳机是否插入到Android设备或没有。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定耳机是否已连接至Android设备或不?

How can I determine whether a headset is plugged into an Android device or not?

推荐答案

当你说耳机,你的意思是有线耳机?如果是这样,有一个意图检测是否一个​​被插入或拔出: ACTION_HEADSET_PLUG

When you say "headset", do you mean "wired headset"? If so, there's an intent to detect whether or not one is being plugged or unplugged: ACTION_HEADSET_PLUG.

要检查其状态,您可以使用 AudioManager.isWiredHeadsetOn(),尽管这可能返回false,如果还有一个蓝牙耳机和音频路由到替代

To check the status, you can use AudioManager.isWiredHeadsetOn(), although that may return false if there is also a bluetooth headset, and audio is routed to that instead.

这篇关于检测耳机是否插入到Android设备或没有。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆