android中强制解除锁屏即按开关机键就进入桌面

来源:互联网 发布:java能开发单片机吗 编辑:程序博客网 时间:2024/05/01 02:41
try{
            Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils");
            Constructor lockPatternUtilsConstructor =
                    lockPatternUtilsCls.getConstructor(new Class[]{Context.class});
            Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(this);


            Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class);
            Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class);


            clearLockMethod.invoke(lockPatternUtils, false);
            setLockScreenDisabledMethod.invoke(lockPatternUtils, true);
        }catch (Exception e){
            e.printStackTrace();
        }
原创粉丝点击