简体   繁体   English

如何检测Windows Phone 8.1中的屏幕被锁定/解锁?

[英]How can I detect the screen is locked/unlocked in Windows Phone 8.1?

I want to dispose camera and other resources when user locks the screen while using the app. 当用户在使用应用程序时锁定屏幕时,我想处置相机和其他资源。 Also want to reinitialize it when it's unlocked. 还想在解锁时重新初始化它。 My initial search gave me these results, which are for Windows Phone 8. How can I do same for Windows Phone 8.1? 最初的搜索为我提供了这些结果,这些结果适用于Windows Phone8。如何对Windows Phone 8.1进行相同操作?

Please note, I don't want to prevent the screen to get locked. 请注意,我不想阻止屏幕被锁定。 I just want to know which event is raised when screen is locked/unlocked. 我只想知道屏幕锁定/解锁时引发的事件。

Windows Phone 8 detect screen unlock Windows Phone 8检测屏幕解锁

ApplicationIdleDetectionMode for windows phone 8.1? Windows Phone 8.1的ApplicationIdleDetectionMode?

Idle detection for Windows Phone 8 Windows Phone 8的空闲检测

You can subscribe to Window.Current.VisibilityChanged: 您可以订阅Window.Current.VisibilityChanged:

Window.Current.VisibilityChanged += CurrentWindow_VisibilityChanged;

and then do: 然后执行:

private async void CurrentWindow_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
    if (e.Visible)
    {
        // window visible... 
    }
    else
    {
        // window not visible, dispose and do what else needs to be done :)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM