[英]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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.