做的事情,如果它检测到耳机插入 [英] Doing something if it detects that headphones are plugged in
问题描述
我想使它所以如果耳机在设备中插入事情发生,如出现一个通知图标。 (我已经通知图标的东西做的),但我似乎无法找到一个方法来做到这一点。我想这样的事情
I'm wanting to make it so if headphones are plugged in the device something happens such as a notification icon appears. (I already have the notification icon stuff done) But I can't seem to find a way to make it happen. I'm wanting something like this
if headphones_plugged_in {
do this
}
我发现这个网上
AudioManager.isWiredHeadsetOn()
我只是不知道我怎么会使用它。我已经在清单中添加正确的权限呢!如果你能引导我或链接我的东西这将是巨大的。谢谢!
I just don't know how I would use that. I already added the right permissions in the manifest too! If you could guide me or link me to something it would be great. Thank You!
推荐答案
添加<接收>
在清单监听的在 ACTION_HEADSET_PLUG
播出。
文档显示意图
,你可以用它来看看耳机的(状态
)等额外堵塞
Add a <receiver>
in your manifest that listens for the ACTION_HEADSET_PLUG
broadcast.
The documentation shows Intent
extras that you can use to find out if the headset is plugged in (state
), etc.
这篇关于做的事情,如果它检测到耳机插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!