从代码中启用或禁用PatternLock屏幕 [英] Enable or disable the PatternLock screen from code
问题描述
我试图找到一种暂时禁用PatternLock屏幕的方法。我不想完全禁用锁,但用户不应该一直重新输入他的模式。
I have tried to find a way to disable the PatternLock screen temporarily. I don't want the lock to be disabled completely, but the user should not need to re-enter his pattern all the time.
我的想法是写一个服务它在一些用户活动后禁用模式,并在一段时间后重新启用它。 (甚至更多)
My idea is to write a service which disables the pattern after some user activity and re-enables it after a while. (and even more)
市场上有应用程序执行类似的操作(即AutoLock或TogglePattern),因此必须有解决方案。
There are apps on the market that do something like that (i.e. AutoLock or TogglePattern), so there must be a solution.
我知道我可以通过使用以下方式完全阻止锁:
I know that I can prevent a lock completely by using:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
或
KeyguardLock.disableKeyguard()
但这不是我在...之后。
But that is not what I'm after.
我在android中看到了类 com.android.internal.widget.LockPatternUtils
来源,它由设置活动使用,但是此类不是(至少在我知道的情况下)可以由正常应用程序访问。
I saw the class com.android.internal.widget.LockPatternUtils
in the android sources which is used by the settings activity, but this class is not (at least as far as I know) accessible by a "normal" application.
你有什么建议吗?
推荐答案
在代码 com.android.internal.widget.LockPatternUtils
并做它做什么?
它有东西这样:
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.
这篇关于从代码中启用或禁用PatternLock屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!