How to prevent screen lock on UWP 10

I want to prevent the phone from being locked if the user does not interact with the phone for a while. In developing win8 phones, I used the PhoneApplicationService.UserIdleDetectionMode property. Unfortunately, I cannot find anything like this for the universal win 10. application. Any suggestions?

+4
source share
2 answers

Simple answer

DisplayRequest class

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

Detailed response

Using display queries to store on the display consumes a lot of power. Use these guidelines for better application behavior when using view requests.

  • , , , . , .

  • , .

  • , . - , , , .

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

- Windows

, -!

+14

DisplayRequest Windows 10.

+5

Source: https://habr.com/ru/post/1613952/


All Articles