Search code examples
windows-phone-8windows-runtimewindows-phone-8.1

How to prevent screen from locking in WP 8.1?


I am building a Windows Phone 8.1 app, and I need to prevent the screen from locking. Is it possible? If yes, how. If no, is there any workaround?


Solution

  • You can use DisplayRequest class:

    Apps that show video or run for extended periods without user input can request that the display remain on by calling DisplayRequest::RequestActive. When a display request is activated, the device's display remains on while the app is visible. When the user moves the app out of the foreground, the system deactivates the app's display requests and reactivates them when the app returns to the foreground.

    Once you call yourDisplayRequest.RequestActive() and it's successfull then the screen is guaranteed not to turn off automatically due to user.

    Also remember to call yourDisplayRequest.RequestRelease() once you leave the app (suspending event).

    More complete example you will get at MSDN.