Win universal app 如何防止UWP 10上的屏幕锁定

Win universal app 如何防止UWP 10上的屏幕锁定,win-universal-app,Win Universal App,如果用户在一段时间内没有与手机进行交互,我想防止手机锁定。 在win8电话开发中,我使用了PhoneApplicationService.UserIdleDetectionMode属性。不幸的是,我找不到任何与win 10 universal应用程序相似的东西。 有什么建议吗?您希望在Windows 10中使用该选项。简单答案 阶级 详细答案 使用显示请求保持显示器打开会消耗大量电力。使用显示请求时,请使用这些指导原则以获得最佳应用程序行为 仅在需要时使用显示请求,即在预期没有用户输入但显示器应

如果用户在一段时间内没有与手机进行交互,我想防止手机锁定。 在win8电话开发中,我使用了PhoneApplicationService.UserIdleDetectionMode属性。不幸的是,我找不到任何与win 10 universal应用程序相似的东西。 有什么建议吗?

您希望在Windows 10中使用该选项。

简单答案 阶级

详细答案 使用显示请求保持显示器打开会消耗大量电力。使用显示请求时,请使用这些指导原则以获得最佳应用程序行为

仅在需要时使用显示请求,即在预期没有用户输入但显示器应保持打开的时间。例如,在全屏演示或用户正在阅读电子书时

一旦不再需要,立即释放每个显示请求

应用程序挂起时释放所有显示请求。如果仍要求显示器保持打开状态,应用程序可以在重新激活时创建新的显示请求

请求继续显示 释放保持显示打开的请求 参考-


希望它能帮助别人

请注意,您希望像在较长的代码段中一样保留对DisplayRequest对象的引用,否则,如果在带有var DisplayRequest的代码段中使用局部变量,则不会产生任何效果。
var displayRequest = new DisplayRequest();
displayRequest.RequestActive(); //to request keep display on
displayRequest.RequestRelease(); //to release request of keep display on
private void Activate_Click(object sender, RoutedEventArgs e) 
{ 
    if (g_DisplayRequest == null) 
    { 
        g_DisplayRequest = new DisplayRequest(); 
    }
    if (g_DisplayRequest != null) 
    { 
        // This call activates a display-required request. If successful,  
        // the screen is guaranteed not to turn off automatically due to user inactivity. 
        g_DisplayRequest.RequestActive(); 
        drCount += 1; 
    } 
}
private void Release_Click(object sender, RoutedEventArgs e) 
{ 
    // This call de-activates the display-required request. If successful, the screen 
    // might be turned off automatically due to a user inactivity, depending on the 
    // power policy settings of the system. The requestRelease method throws an exception  
    // if it is called before a successful requestActive call on this object. 
    if (g_DisplayRequest != null) 
    {
        g_DisplayRequest.RequestRelease(); 
        drCount -= 1; 
    }
}