锁屏和亮屏控制

//判断是否锁屏 KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); boolean isLock = (mKeyguardManager.inKeyguardRestrictedInputMode(); if (isLock) { //锁屏 } else { //不锁屏 }

//如果为true,则表示屏幕“亮”了,否则屏幕“暗”了 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isLight = pm.isScreenOn(); if (isLight) { //亮 } else { //暗 }

//强制亮屏 private PowerManager.WakeLock mWakelock; mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "target"); mWakelock.acquire(); //强制亮屏 // mWakelock.release(); 释放控制

    推荐阅读