1、Android屏幕常亮/點亮 代碼如下:
//保持屏幕常亮
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOCK_TAG);
mWakeLock.acquire();
代碼如下:
//釋放屏幕常亮鎖
if(null != mWakeLock) {
mWakeLock.release();
}
2、Android屏幕解鎖和鎖定 代碼如下:
//屏幕解鎖
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(LOCK_TAG);
keyguardLock.disableKeyguard();
//屏幕鎖定
keyguardLock.reenableKeyguard();
3、相關權限 代碼如下:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />