& ltuses-permission Android:name = " Android . permission . wake _ LOCK "/& gt;
& ltuses-permission Android:name = " Android . permission . disable _ key guard "/& gt;
復制代碼代碼如下:
//屏幕鎖定,喚醒相關
私有KeyguardManager km
私人KeyguardLock kl
private PowerManager pm
私有PowerManager。WakeLock wl
私有void wakeAndUnlock(布爾值b)
{
如果(b)
{
//獲取電源管理器對象
pm =(power manager)getsystem service(上下文。POWER _ SERVICE);
//獲取PowerManager。WakeLock對象,後面的參數|表示同時傳入兩個值,最後壹個是調試用的標簽。
wl = pm.newWakeLock(PowerManager。ACQUIRE _ CAUSES _ wake up | power managerSCREEN_BRIGHT_WAKE_LOCK,“亮”);
//點亮屏幕
wl . acquire();
//獲取鍵盤鎖管理器對象
km =(KeyguardManager)getsystem service(上下文。key guard _ SERVICE);
KL = km . newkeyguardlock(" unLock ");
//解鎖
KL . disable key guard();
}
其他
{
//鎖定屏幕
KL . reenablekeyguard();
//釋放喚醒鎖,關燈。
wl . release();
}
}