Android的 - 检查耳机按钮点击 [英] Android - checking headset button click
本文介绍了Android的 - 检查耳机按钮点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能检查是否被点击我的耳机播放/暂停按钮? 从那以后,我可以实现一些方法,可以为我自己的行动改变的典型动作(播放/暂停)(关机等)?
How can I checked if play/pause button in my headset is clicked? After that can I implement some method that could change typical action (play/pause) for my own action (shut down etc.) ?
推荐答案
如果你想听听这个来自活动在前景中,使用的onkeydown()
和留意键code_MEDIA_PLAY_PAUSE
。
If you are trying to listen for this from an activity in the foreground, use onKeyDown()
and watch for KEYCODE_MEDIA_PLAY_PAUSE
.
使用一个的BroadcastReceiver
为 ACTION_MEDIA_BUTTON
如果你想监听此事件的背景(例如,服务播放音乐)。
Use a BroadcastReceiver
for ACTION_MEDIA_BUTTON
if you are trying to listen for this event from the background (e.g., a service playing music).
这篇关于Android的 - 检查耳机按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文