0

I am using the following codes in my app to keep my device screen from timing out/shutting off. I have used right permissions in my Manifest.

Screen Keep On:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Screen Off:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Those codes work if the app is running. However, when I close the app the flags seem to clear automatically leaving my device to timeout as normal. I want to keep screen on even if the app is closed. I've tried looking into Wakeful Receiver service but I can't seem to get it to work right. Also, I noticed Wakeful Receiver was depreciated in API 26. Any ideas? Thanks in advance!

Pouya Heydari
  • 2,496
  • 26
  • 39
  • "I want to keep screen on even if the app is closed." - why? this seems like a duplication of the screen time-out system setting. – leonardkraemer Dec 09 '18 at 13:39
  • leonardkraemer it's not a duplicate. That question you linked doesn't explain to me how to keep my device on at all times when the app is closed. That one just shows me how to do it with the app open which I already know how to do. Thanks! –  Dec 09 '18 at 13:43
  • check this: https://stackoverflow.com/questions/10748861/how-to-change-screen-timeout-programmatically – leonardkraemer Dec 09 '18 at 16:34

0 Answers0