How To: Keep Windows 8 Device Screen On While User Away

27/12/2012

While working with a customer on GPS system for Windows Store app, an important question raised:

How we can prevent from Windows to turn off the screen due to user inactivity?

Normally, a Windows 8 device will dim the display (and eventually turn it off) to save battery life when the user is away.

Now for our system we need to keep the display on at all times, to do that call requestActive function to notify Windows that the app requires the display to remain on. Windows automatically deactivates your app’s active display requests when it is moved off screen, and re-activates them when your app comes back to the foreground. But you can also use API to release the request display by calling the requestRelease function.

var displayRequest = null;

function keepDisplayOn() {
   if displayRequest === null) {  
      displayRequest = new Windows.System.Display.DisplayRequest;
      displayRequest.requestActive();

//C# – displayRequest = new DisplayRequest();

//C# – displayRequest.RequestActive();
} } function releaseDisplayOn() { if displayRequest != null) { displayRequest.requestRelease(); displayRequest = null;

//C# – displayRequest.RequestRelease(); } }
Add comment
facebook linkedin twitter email

Leave a Reply