android 判断是否设置了锁屏密码 - 取悦

时间:2024-03-13 20:54:37

android 判断是否设置了锁屏密码

 

方式1:在小米note手机上测试,只能判断是否设置了图形解锁。

android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.LOCK_PATTERN_ENABLED)可以获得一个int值,0表示没有设置,1表示设置了。

方式2:只要rom没改变这个方法,可以使用,能正确判断手机是否设置了图形解锁、密码或混合密码解锁。

    private boolean isSecured() {
        boolean isSecured = false;
        String classPath = "com.android.internal.widget.LockPatternUtils";
        try {
            Class<?> lockPatternClass = Class.forName(classPath);
            Object lockPatternObject = lockPatternClass.getConstructor(Context.class).newInstance(getApplicationContext());
            Method method = lockPatternClass.getMethod("isSecure");
            isSecured = (Boolean) method.invoke(lockPatternObject);
        } catch (Exception e) {
            isSecured = false;
        }
        return isSecured;
    }

 

参考:http://blog.csdn.net/xiaoxi_qianlan/article/details/49049725