如何捕获服务中的关键事件?关键、事件

由网友(别给我一枪你喊疼)分享简介:我希望能够捕捉到我写一个服务中的重要事件。我可以在活动内做到这一点没有问题,但我所有的attemps得到这个工作在一个服务都失败了。我想捕捉(全球)最关键的是BACK按钮,但如果这是不可能的任何(硬件)按钮HTC Desire的报价将是美好的。I want to be able to capture key even...

我希望能够捕捉到我写一个服务中的重要事件。我可以在活动内做到这一点没有问题,但我所有的attemps得到这个工作在一个服务都失败了。我想捕捉(全球)最关键的是BACK按钮,但如果这是不可能的任何(硬件)按钮HTC Desire的报价将是美好的。

I want to be able to capture key events inside a service I am writing. I can do this inside an activity without problems, but all my attemps to get this working in a service have failed. The key I wanted to capture (globally) is the BACK button, but if this is not possible any (hardware) button a HTC Desire offers would be OK.

推荐答案

是的,Android的活动只接收的KeyEvents 具有焦点时。

Yes, Android's activities only receives KeyEvents when they have focus.

到全球捕获后退按钮preSS是建立一个的 InputMethod 这样你就可以截获硬键事件。 请记住,使用你自己的 InputMethod 不会允许你使用自定义键盘如 Swiftkey 的实例。

The only way to "globally" capture a back button press is creating an InputMethod so you can intercept hard key events. Remember that using your own InputMethod will not allow you to use custom keyboards like Swiftkey for instance.

你有没有尝试达成HTC在这个问题上?

Did you try to reach HTC on this issue?

阅读全文

相关推荐

最新文章