PHP
·
发表于 5年以前
·
阅读量:8391
public static void wakeUpAndUnlock(Context context){
KeyguardManager km= (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock kl = km.newKeyguardLock( "unLock" );
//解锁
kl.disableKeyguard();
//获取电源管理器对象
PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE\_CAUSES\_WAKEUP | PowerManager.SCREEN\_DIM\_WAKE_LOCK, "bright" );
//点亮屏幕
wl.acquire();
//释放
wl.release();
}
<uses-permission android:name= "android.permission.WAKE_LOCK" />
<uses-permission android:name= "android.permission.DISABLE_KEYGUARD" />