android关闭屏幕时不锁屏实现

所需权限:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

关闭系统锁屏服务:

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();//关闭系统锁屏

这样在屏幕关闭重新打开时就看不到锁屏界面了

--------------------------------------------------------------

如果要防止系统休眠:

所需权限:

<uses-permission android:name="android.permission.WAKE_LOCK"/>

代码实现:

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();
}

或者禁止系统自动关屏:

所需权限:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

代码实现:

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);
}

 

 

 


posted on 2016-12-15 15:17  guangdeshishe  阅读(6589)  评论(0编辑  收藏  举报

导航