所需权限:
关闭系统锁屏服务:
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard();//关闭系统锁屏
这样在屏幕关闭重新打开时就看不到锁屏界面了
--------------------------------------------------------------
如果要防止系统休眠:
所需权限:
代码实现:
PowerManager pm = (PowerManager) this .getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "ZAK"); if (null != wakeLock) { wakeLock.acquire(); }
或者禁止系统自动关屏:
所需权限:
代码实现:
setLockPatternEnabled(false);
public void setLockPatternEnabled(boolean enabled) { setBoolean(android.provider.Settings.System.LOCK_PATTERN_ENABLED, enabled); } private void setBoolean(String systemSettingKey, boolean enabled) { android.provider.Settings.System.putInt(getContentResolver(), systemSettingKey, enabled ? 1 : 0); }