机器人 - 获取音量键长的点击音量、机器人

2023-09-04 05:18:23 作者:怀中的垂耳兔和你

有人能告诉我如何获得一个长按(2秒为例)上的音量了硬件密钥一个code例子吗?

Can someone please show me a code example about how to get a long click (2 sec for example) on the volume up hardware key?

感谢:)

修改

这是我想要捕获长按与类是服务。我怎样才能做到这一点?

The class that i want to capture the long click with is a Service. How can i do that?

推荐答案

如果你只需要捕获长的点击,这个答案可能会有所帮助:

If you just need to capture long clicks, this answer might be helpful:

http://stackoverflow.com/a/5269673/1401257

编辑:

我从来没有试过有一个服务中的一个关键监听器,但谷歌从一点点帮助,我发现这一点:的体积变化监听器?

I have never tried to have a key listener inside a service, but with a little help from Google I found this: Volume change listener?

看来,正常的关键事件只能从活动进行处理。我没有时间去尝试了这一点我自己,但捕捉长期的点击有可能的答案从链接和卢克斯的回答结合起来。 据我了解有关BroadcastReceivers,你想创建一个接收器,该通知服务每当有人点击音量按钮。

It seems that normal key events can only be handled from Activities. I do not have time to try this out myself, but for capturing long clicks it might be possible to combine the answer from the link and Lukes answer. From what I understand about BroadcastReceivers, you would want to create a receiver, that notify the Service whenever someone click the volume buttons.