1

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?

Kibi
  • 1,860
  • 1
  • 29
  • 39

1 Answers1

1

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.

zen_of_kermit
  • 1,404
  • 2
  • 13
  • 19
  • Thank you, I'm going to accept this because its a good, complete answer. In the end, I'm going to actually do what I swore I would not and use the FLAG_KEEP_SCREEN_ON with a timer (shoot me now) – Kibi Apr 13 '22 at 08:28