如何在执行操作后保持 Android 屏幕常亮

发布于 2025-01-16 06:59:08 字数 277 浏览 1 评论 0原文

我可以发誓有一行简单的代码可以实现这一点,但我现在找不到它。

在我的应用程序中,我使用一块定制硬件进行输入。我接收事件(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉薄对峙 2025-01-23 06:59:08

如果您不想使用 Wakelock,可以使用以下选项:

  • 使用 SnackBar 短暂显示弹出消息。
  • 使用 FCM触发高优先级消息通知。
  • 创建一个在 BLE 设备允许用户输入时运行的前台服务。或者以同样的方式使用 WorkManager

更严格的选项,要求您的应用是设备管理员 ,就是使用 DevicePolicyManager 设置锁定的最长时间,理想情况下保存以前的值并在用户输入完成后恢复。

If you don't want to use Wakelock, some options:

  • Use SnackBar to briefly display a pop-up message.
  • Use FCM to fire a high priority message notification.
  • Create a foreground service that runs while your BLE device is allowing user input. Or use WorkManager the same way.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文