得意犹堪夸世俗,诏黄新湿字如鸦。这篇文章主要讲述Android M获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"
图案"
,"
密码"
相关的知识,希望能为你提供帮助。
ENV: android M 6.0.1
import android.os.UserHandle;
import com.android.internal.widget.LockPatternUtils;
import android.app.admin.DevicePolicyManager;
LockPatternUtils mLockPatternUtils = new LockPatternUtils(mContext);
int userId = UserHandle.myUserId();
boolean lockScreenDisabled = mLockPatternUtils.isLockScreenDisabled(userId);
boolean security = mLockPatternUtils.isSecure(userId);
boolean isLockPasswordEnabled = mLockPatternUtils.isLockPasswordEnabled(userId);
boolean isLockPatternEnabled = mLockPatternUtils.isLockPatternEnabled(userId);
final int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality(userId);
Log.d(TAG, "lockScreenDisabled = " + lockScreenDisabled);
Log.d(TAG, "security = " + security);
Log.d(TAG, "isLockPasswordEnabled = " + isLockPasswordEnabled);
Log.d(TAG, "isLockPatternEnabled = " + isLockPatternEnabled);
Log.d(TAG, "quality = " + quality);
switch (quality) {
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
if (mLockPatternUtils.isLockPasswordEnabled(userId)) {
Log.d(TAG, "PIN码 安全模式");
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
if (mLockPatternUtils.isLockPasswordEnabled(userId)) {
Log.d(TAG, "密码 安全模式");
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
if (mLockPatternUtils.isLockPatternEnabled(userId)) {
Log.d(TAG, "图案 安全模式");
}
break;
}
打印Log
[email
protected]:~$ adb logcat -s LockPatternUtilsHelp
--------- beginning of system
--------- beginning of main
//图案
11-02 14:36:22.721
4896
4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:36:22.721
4896
4896 D LockPatternUtilsHelp: security = true
11-02 14:36:22.721
4896
4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:22.721
4896
4896 D LockPatternUtilsHelp: isLockPatternEnabled = true
11-02 14:36:22.722
4896
4896 D LockPatternUtilsHelp: quality = 65536
11-02 14:36:22.722
4896
4896 D LockPatternUtilsHelp: 图案 安全模式
//PIN码
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: security = true
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: isLockPasswordEnabled = true
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: quality = 131072
11-02 14:37:34.748
4896
4896 D LockPatternUtilsHelp: PIN码 安全模式
// 密码
11-02 14:38:10.930
4896
4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:38:10.930
4896
4896 D LockPatternUtilsHelp: security = true
11-02 14:38:10.930
4896
4896 D LockPatternUtilsHelp: isLockPasswordEnabled = true
11-02 14:38:10.930
4896
4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:38:10.930
4896
4896 D LockPatternUtilsHelp: quality = 327680
11-02 14:38:10.931
4896
4896 D LockPatternUtilsHelp: 密码 安全模式
// 滑动
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: lockScreenDisabled = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: security = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: quality = 0
// 无
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: lockScreenDisabled = true
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: security = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: isLockPasswordEnabled = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: isLockPatternEnabled = false
11-02 14:36:58.968
4896
4896 D LockPatternUtilsHelp: quality = 0
【Android M获取屏幕锁定的相关信息(“无”,“滑动”,“PIN码”,"
图案"
,"
密码"
)】一 如何判断当前锁定方式是否为"无"?
通过LockPatternUtils类的isLockScreenDisabled判断
二 如何判断当前锁定方式是否为"滑动"?
通过LockPatternUtils类的! isSecure方法和! isLockScreenDisabled方法判断
三 如何判断当前锁定方式是否为"安全密码"锁屏?
通过LockPatternUtils类的isSecure方法和getKeyguardStoredPasswordQuality方法判断
PS:LockPatternUtils类为平台内部类,第三方应用层无法获取该类,可考虑通过反射调用亦可考虑其他方式判断
推荐阅读
- mybatis mapper xml文件配置resultmap时,id行和result行有什么区别()
- Android LruCache类分析
- android 闹钟设置问题
- Android 图片缓存处理
- 我的Android进阶之旅------>怎样将Activity变为半透明的对话框()
- Android N 7.1.1 ActivityManagerService 获取cpu状态
- Android语音播报后台播报语音识别
- Hybrid App开发之jQuery选择器
- [转]App架构设计经验谈(接口的设计)