问题描述
我有我的code使用AudioManager的 isWiredHeadsetOn()
方法,只要我使用随我的手机耳机工作。如果我使用了一副耳机不带内置麦克风, isWiredHeadsetOn()
返回false,我想是不够公平的,但不是我想要的!有没有一种方法同时检测耳机和耳机?
I've got my code working using the isWiredHeadsetOn()
method in AudioManager as long as I use the headset that came with my phone. If I use a pair of headphones without an inbuilt microphone, isWiredHeadsetOn()
returns false, which I suppose is fair enough, but isn't what I want! Is there a way to detect both headsets and headphones?
推荐答案
最好的办法是使用广播接收机ACTION_HEADSET_PLUG。然后你得到事件耳机连接或断开时。
The best way is to use a broadcast receiver for ACTION_HEADSET_PLUG. Then you get events when the headset is connected or disconnected.
我认为它应该工作蓝牙设备,但我不是100%肯定是诚实的。
I think it should work for bluetooth devices but am not 100% sure to be honest.
这篇关于安卓:检测耳机以及耳机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!