我想防止手机在用户不与手机进行交互一段时间后自动锁定。 在win8手机开发中,我使用了PhoneApplicationService.UserIdleDetectionMode属性。不幸的是,对于win10通用应用程序,我找不到类似的东西。 有什么建议吗?
我想防止手机在用户不与手机进行交互一段时间后自动锁定。 在win8手机开发中,我使用了PhoneApplicationService.UserIdleDetectionMode属性。不幸的是,对于win10通用应用程序,我找不到类似的东西。 有什么建议吗?
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;
}
}
参考资料 - 防止通用Windows平台锁屏
希望它能帮助到某些人!