4

I would like to know how to keep the screen permanently on from a service. Here is the scenario for the code: User plugs phone into power outlet, Broadcast receiver gets event, start a service that prevent the screen from timing out. User unplugs phone, service is killed and timeout restored.

I wanted to use wakelocks but the level that is needed is deprecated in API 13:

int SCREEN_BRIGHT_WAKE_LOCK This constant was deprecated in API level 13. Most applications should use FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.

FLAG_KEEP_SCREEN_ON cannot be used from a service from what I've read.

I don't want to modify the screen timeout number since if my service is destroyed or application uninstalled, I don't want the timeout to be stuck at a high number.

Also my application cannot get any system permission so anything requiring DEVICE_POWER permission, I can't use

Any idea? Thanks for any insight, Amish

ollo
  • 24,797
  • 14
  • 106
  • 155
axr 0284
  • 113
  • 1
  • 9

1 Answers1

1

deprecated doesn't mean you can't use it in for versions greater than 13. if you're minimum required version is let's say 8 (not confirmed), you have no other option. The wake lock is still available in api level 17.

Diogo Bento
  • 197
  • 2
  • 13