问题描述
我试图找到一种临时禁用模式锁屏幕的方法.我不希望锁完全禁用,但是用户不需要一直重新输入他的模式.
我的想法是编写一项服务,该服务在某些用户活动之后禁用模式,并在一段时间后重新启用它. (甚至更多)
市场上有类似的应用程序(即Autolock或togglePattern),因此必须有一个解决方案.
我知道我可以通过使用:
完全防止锁定getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
或
KeyguardLock.disableKeyguard()
但这不是我追求的.
我在设置活动使用的Android源中看到了类com.android.internal.widget.LockPatternUtils,但是(至少据我所知)的"正常"应用程序无法访问此类.
您有任何建议吗?
推荐答案
您是否尝试查看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); }
您也许可以在代码中做类似的事情.
其他推荐答案
截至2.0(API级别5),您可以使用此窗口标志来防止显示窗口时显示锁定屏幕:
/android/view/windowmanager.layoutparams.html#flag_show_show_when_locked
您也可以使用此标志来允许显示窗口时允许非安全钥匙守卫:
/android/view/windowmanager.layoutparams.html#flag_dismiss_keyguard
请注意,这些不允许您绕过应用程序环境之外的锁定屏幕,这是有意的设计决定.
还有一个较旧的API,可以让您以与唤醒锁相似的方式隐藏锁定屏幕:
http:http:http://开发人员. android.com/reference/android/app/keyguardmanager.html#newkeyguardlock(java.lang.string)
在较新的平台上不建议使用此API,因为犯错并导致不良行为非常容易(屏幕在用户期望期望时不会锁定),并且基本上不可能在未锁定的活动之间进行清洁过渡状态.例如,这是显示锁定屏幕时最初用于隐藏锁定屏幕的API,但截至2.0,它已切换到新的清洁窗口标志.同样适用于闹钟等.
问题描述
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)
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)
or
KeyguardLock.disableKeyguard()
But that is not what I'm after.
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.
Do you have any suggestions?
推荐答案
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:
You can also use this flag to allow a non-secure keyguard to be dismissed when your window is displayed:
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:
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.