Android 防止应用程序/屏幕超时
我有一个 Android(版本 1.5)应用程序,按下按钮时需要不断运行。 因此,当按下 Button
时,我希望手机保持开机状态,不希望屏幕或 CPU 超时。
当按下另一个 Button
时,我希望手机恢复正常并根据用户设置超时。
I have an Android (version 1.5) application which needs to be constantly running when a button is pressed. So, when a Button
is pressed I would like the phone to remain on and not want the screen or CPU to time-out.
When another Button
is pressed I would like the phone to be back to normal and time-out as per user settings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:根据 Steve Pomeroy 的建议,这可能是更好的方法。
可以使用需要的
WakeLock
以下权限:以下是获取和释放
WakeLock
:根据您的要求,您可能可以使用不同类型的
唤醒锁
。Update: As suggested by Steve Pomeroy, this might be a better way to do it.
You can use a
WakeLock
that requires the following permission:Here is how you aquire and release a
WakeLock
:Depending on your requirements you might be able to use a different type of
WakeLock
.您应该考虑此处提出的解决方案,而不是使用唤醒锁: 强制屏幕打开
它更容易使用并且不会意外浪费用户的电池。
Instead of using a wakelock, you should consider the solution proposed here: Force Screen On
It is much easier to use and doesn't have the potential of accidentally wasting the user's batteries.