MarcoS
MarcoS

Reputation: 17711

How do I force screen on (if it's sleeping), in my Activity?

I am writing an Android alarm-like app. I want to let the user to choose if to always keep the screen on for the whole application duration, or if she want it to go to sleep according to her device power manager settings.

The first scenario is correctly handled with this code:

getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

But - in the second scenario - when the screen has been swichted off by power manager, I can play a sound via AudioManager, but I can't force the screen to switch on...

I'm using Build.VERSION.SDK = 10 and testing on a Samsung device with Android 2.3.4.

Upvotes: 0

Views: 783

Answers (1)

Rikonator
Rikonator

Reputation: 1860

You can maintain a WakeLock, and acquire the WakeLock when you want to turn the screen on.

You can check out WakeLock here.

Upvotes: 1

Related Questions