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

Android 使用反射设置设备屏幕锁定解锁,android,reflection,keyguard,Android,Reflection,Keyguard,我正在使用反射解锁我的设备屏幕,将keyguard设置为禁用。我的android版本为4.4.2。调用时,我得到异常为java.lang.reflect.InvocationTargetException,并导致异常为java.lang.SecurityException:LockSettingsWrite:用户10096和当前进程均未激活android.permission.ACCESS\u KEYGUARD\u SECURE\u存储。 我正在分享我的代码,请告诉我如何纠正此异常 try{

我正在使用反射解锁我的设备屏幕,将keyguard设置为禁用。我的android版本为4.4.2。调用时,我得到异常为java.lang.reflect.InvocationTargetException,并导致异常为java.lang.SecurityException:LockSettingsWrite:用户10096和当前进程均未激活android.permission.ACCESS\u KEYGUARD\u SECURE\u存储。

我正在分享我的代码,请告诉我如何纠正此异常

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();  
}
KitKat中发生此错误的原因: 在KitKat中,Android将安全数据库从应用程序数据区(/data/data)移动到系统数据区(/data/system)

KitKat中发生此错误的原因: 在KitKat中,Android将安全数据库从应用程序数据区(/data/data)移动到系统数据区(/data/system)


你的代码在Jellybean中运行得很好吗???我没有试过,因为我的要求是针对Kitkat的。你的代码在Jellybean中运行得很好吗???我没有试过,因为我的要求是针对Kitkat的。非常感谢一个完美的答案。但是我不能投票支持你,因为我的声誉分数仍然是11。不过,谢谢这是一个非常完美的答案。但是我不能为你投赞成票,因为我的声誉分数仍然是11。但是非常感谢