Enable or disable the PatternLock screen from code

牧云@^-^@ 提交于 2019-11-28 20:58:21
Malachi

Have you tried looking at the code for com.android.internal.widget.LockPatternUtils and doing what it does?

It has something like this:

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(
                    mContentResolver,
                    systemSettingKey,
                    enabled ? 1 : 0);
}

You might be able to do something similar in your code.

As of 2.0 (API level 5), you can use this window flag to prevent the lock screen from being displayed while your window is shown:

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SHOW_WHEN_LOCKED

You can also use this flag to allow a non-secure keyguard to be dismissed when your window is displayed:

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_DISMISS_KEYGUARD

Note that these do not allow you to bypass the lock screen outside of your application's environment, which is an intentional design decision.

There is also an older API that lets you hide the lock screen in a similar way to a wake lock:

http://developer.android.com/reference/android/app/KeyguardManager.html#newKeyguardLock(java.lang.String)

Use of this API is discouraged on newer platforms, because it is very easy to get wrong and cause bad behavior (the screen not locking when the user would expect it to), and basically impossible to have clean transitions between activities with unlocked states. For example, this is the API that the in-call screen originally used to hide the lock screen when it was displayed, but as of 2.0 it has switched to the new cleaner window flags. Likewise for the alarm clock etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!