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

时间:2016-05-04 05:49:50

标签: android reflection keyguard

我正在使用反射将我的设备屏幕设置键盘锁解锁为禁用。我的android版本是4.4.2。而调用我得到异常为 java.lang.reflect.InvocationTargetException 并导致为 java.lang.SecurityException:LockSettingsWrite:用户10096和当前进程都没有android.permission.ACCESS_KEYGUARD_SECURE_STORAGE。

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

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();  
}

1 个答案:

答案 0 :(得分:0)

为什么KitKat中出现此错误:

  

在KitKat中,Android将安全数据库从应用程序数据区(/ data / data)移到系统数据区(/ data / system)。

Ref

相关问题