DCSIMG
How To: Keep Windows 8 Device Screen On While User Away - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

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

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(); } }
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Comments

How To: Keep Windows 8 Device Screen On While User Away - Shai Raiten's Blog said:

Pingback from  How To: Keep Windows 8 Device Screen On While User Away - Shai Raiten's Blog

# December 27, 2012 10:43 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: