androidwakelockscreen-lock

How to keep Android screen on after an action


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?


Solution

  • 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.