如何防止屏幕锁定在UWP 10上

时间:2015-10-31 10:37:29

标签: win-universal-app

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

2 个答案:

答案 0 :(得分:14)

简单回答

DisplayRequest上课

var displayRequest = new DisplayRequest();
displayRequest.RequestActive(); //to request keep display on
displayRequest.RequestRelease(); //to release request of keep display on

详细答案

使用显示请求来保持显示器消耗大量功率。使用显示请求时,请使用这些指南以获得最佳应用行为。

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

  2. 在不再需要时立即释放每个显示请求。

  3. 暂停应用时释放所有显示请求。如果显示仍然需要保持打开状态,则应用程序可以在重新激活时创建新的显示请求。

  4. 要求继续显示

    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; 
        }
    } 
    

    参考文献 - Prevent the screen from locking on Universal Windows Platform

    希望有人帮助!!

答案 1 :(得分:5)

您需要Windows 10中的this