问题描述
我已经写了Andoid应用程序,使用硬件音量按钮用于其他用途。
I've written an Andoid app that uses the hardware Volume buttons for another purpose.
它工作正常,如果应用程序正在运行,可见,但是当我关闭屏幕或让它超时,按钮的点击不进入我的处理程序。
It works fine if the app is running and visible, but when I turn the screen off or let it time out, the button clicks don't get into my handlers.
有谁知道是否有一种方法来检测这些按钮的点击,当屏幕处于关闭状态?
Does anyone know if there is a way to detect these button clicks when the screen is off?
推荐答案
要保持检测这样的事情,当屏幕处于关闭状态的唯一方法是获得一个WakeLock,使屏幕关掉了,还是让你的应用程序功能。然而,这水渠电池寿命相当多,应该只使用在绝对必要的。
The only way to keep detecting things like this when the screen is off is to acquire a WakeLock that will allow the screen to turn off, and still let your app function. However, this drains the battery life quite a bit, and should only be used when absolutely necessary.
在这种情况下,您将需要一个 PARTIAL_WAKE_LOCK 。
In this case, you will need a PARTIAL_WAKE_LOCK.
这篇关于检测硬件音量按钮点击当屏幕关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!