简体   繁体   English

使用反射设置设备屏幕锁定解锁

[英]set device screen lock unlock using reflection

I am using reflection to unlock my device screen setting keyguard as disabled.my android version is 4.4.2.while invoking i get exception as java.lang.reflect.InvocationTargetException and cause as java.lang.SecurityException: LockSettingsWrite: Neither user 10096 nor current process has android.permission.ACCESS_KEYGUARD_SECURE_STORAGE. 我正在使用反射解锁我的设备屏幕设置键盘保护为禁用。我的Android版本是4.4.2.while调用我得到异常作为java.lang.reflect.InvocationTargetException和原因作为java.lang.SecurityException:LockSettingsWrite:既没有用户10096也没有当前进程有android.permission.ACCESS_KEYGUARD_SECURE_STORAGE。

i am sharing my code please tell me how to rectify this exception 我正在分享我的代码,请告诉我如何纠正这个异常

try{
   Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils");
   Constructor lockPatternUtilsConstructor = lockPatternUtilsCls.getConstructor(new Class[]{Context.class});
   Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(ChangeDeviceLockMode.this);

   Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class);
   clearLockMethod.setAccessible(true);
   Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class);
   setLockScreenDisabledMethod.setAccessible(true);
   clearLockMethod.invoke(lockPatternUtils, false);
   setLockScreenDisabledMethod.invoke(lockPatternUtils, true);     
   Toast.makeText(ChangeDeviceLockMode.this,"none", Toast.LENGTH_LONG).show();  
}catch(Exception e){
   System.err.println("An InvocationTargetException was caught!");
   Throwable cause = e.getCause();

   Toast.makeText(ChangeDeviceLockMode.this,"none"+e, Toast.LENGTH_LONG).show();  
}
Toast.makeText(ChangeDeviceLockMode.this,"Yupiee!!! Password changed successfully to swipe", Toast.LENGTH_LONG).show();  
}

Why this error Occurs in KitKat: 为什么在KitKat中发生此错误:

In KitKat Android moved the security databases away from the application data area (/data/data) to the system data area (/data/system). 在KitKat中,Android将安全数据库从应用程序数据区(/ data / data)移到系统数据区(/ data / system)。

Ref 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM