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

查看:37
本文介绍了检测耳机是否已插入 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天全站免登陆