如何在执行操作后保持 Android 屏幕常亮
我可以发誓有一行简单的代码可以实现这一点,但我现在找不到它。
在我的应用程序中,我使用一块定制硬件进行输入。我接收事件(在 BLE 上),但不是按键或鼠标操作。我想做的是,每个操作都应该保持屏幕唤醒,就像我触摸了屏幕一样(因此,无论当前超时如何重置)
要明确 - 我不想使用,
android:keepScreenOn="true"
因为这会使屏幕永久打开。我也不想运行一堆唤醒锁 - 我几乎可以肯定有一个简单的命令可以重置屏幕超时 - 它是什么?
I could have sworn there's a simple line of code for this, but I can't find it right now.
In my app I am using a piece of custom hardware for input. I receive events (on BLE) but not as keypresses or mouse actions. What I want to do is that each action should keep the screen awake just as if I had touched the screen (so, whatever the current timeout is gets reset)
To be clear - I do NOT want to use
android:keepScreenOn="true"
since that leaves the screen permanently on. I also don't want to be running a bunch of wakelocks - I'm almost certain there is a simple command to reset the screen timeout - what is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想使用 Wakelock,可以使用以下选项:
更严格的选项,要求您的应用是设备管理员 ,就是使用 DevicePolicyManager 设置锁定的最长时间,理想情况下保存以前的值并在用户输入完成后恢复。
If you don't want to use Wakelock, some options:
A more severe option, which requires your app to be a device admin, is to use DevicePolicyManager to set the maximum time to lock, ideally saving previous value and restoring after user input is complete.