如果用户没有与手机互动一段时间,我想阻止手机锁定。 在win8手机开发中,我使用了PhoneApplicationService.UserIdleDetectionMode属性。不幸的是,我找不到任何相似的win 10通用应用程序。 有什么建议吗?
答案 0 :(得分:14)
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;
}
}
参考文献 - Prevent the screen from locking on Universal Windows Platform
希望有人帮助!!
答案 1 :(得分:5)
您需要Windows 10中的this。