Reputation: 21
How can I detect if the screen is locked in UWP apps?
When screen is locked, suspension of app occurs and I need to put some different code in case of locking screen.
Upvotes: 0
Views: 1660
Reputation: 11
You will find your answer here: https://developerinsider.co/prevent-the-screen-from-locking-on-uwp/
For those that are not looking for a link to another post that could, or could not, potentially be helpful here is the summary
The code you would use is
var displayRequest = new DisplayRequest();
displayRequest.RequestActive(); //to request keep display on
displayRequest.RequestRelease(); //to release request of keep display on
Things to keep in mind are
Upvotes: 1
Reputation: 1324
No, you can't exactly detect when a user activates the lockscreen, but you can detect changes in the lifecycle. This way you can detect when a user suspends your app.
For information about the lifecycle: https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle
Upvotes: 0