如何在window phone控制屏幕常亮

在WindowPhone下禁用锁屏的事件

定义工具类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public ref class Device sealed
{
private:
Device(){ m_requestActivd = false; };
Windows::System::Display::DisplayRequest^ m_display_request;
bool m_requestActivd;
public:
void DisplayRequestActive()
{
if (m_requestActivd) //如果重复调用会抛出错误
{
return;
}
if (nullptr == m_display_request)
{
m_display_request = ref new Windows::System::Display::DisplayRequest();
}
m_display_request->RequestActive();
m_requestActivd = true;
}
void DisplayRequestRelease()
{
if (!m_requestActivd)
{
return;
}
if (nullptr != m_display_request)
{
m_display_request->RequestRelease();
m_requestActivd = false;
}
}
static property Device^ Instance
{
Device^ get()
{
static Device^ instance = ref new Device();
return instance;
}
}
}

使用

1
2
3
4
//屏幕常亮
Device::Instance->DisplayRequestActive();
//关闭屏幕常亮
Device::Instance->DisplayRequestRelease();

over~~