在Android设备中,我们可以将三种类型的锁定为模式,PIN和密码。以编程方式更改PIN码
在我的应用程序中,我想要在程序中更改/重置PIN。
我接受用户的4位数字,该用户将被设置为该设备的新PIN。
是否可以重置此PIN或违反Android安全政策?
谢谢。
在Android设备中,我们可以将三种类型的锁定为模式,PIN和密码。以编程方式更改PIN码
在我的应用程序中,我想要在程序中更改/重置PIN。
我接受用户的4位数字,该用户将被设置为该设备的新PIN。
是否可以重置此PIN或违反Android安全政策?
谢谢。
您可以使用Device Admin API来完成。在Android给你的设施,使你自己的密码逻辑(甚至更多..)。 Read about how to implement password policy.
注:您可以在<sdk>/samples/android-<version>/
得到的示例代码。 <version>
数字对应于平台的API级别。
最好的方法来使用reflection.using反射你可以设置你的设备密码为none,刷卡,pin,密码。 继承人的代码来帮助你。确保你有管理员权限。这个代码将改变你的设备密码swipe.For引脚在resetpassword方法给一些价值,而不是“”空字符串。没有只是不做任何与设备政策manaager和是确保你的应用程序是系统应用,即系统签署
try
{
try{
Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils");
Constructor lockPatternUtilsConstructor =
lockPatternUtilsCls.getConstructor(new Class[]{Context.class});
lockPatternUtilsConstructor.setAccessible(true);
Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(ChangeDeviceLockMode.this);
Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class);
clearLockMethod.setAccessible(true);
clearLockMethod.invoke(lockPatternUtils, true);
Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class);
setLockScreenDisabledMethod.setAccessible(true);
setLockScreenDisabledMethod.invoke(lockPatternUtils, false);
}catch(Exception e){
System.err.println("An InvocationTargetException was caught!");
Throwable cause = e.getCause();
}
devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 0);
boolean result = devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
}
catch(Exception ex)
{
ex.printStackTrace();
}
嗨,你能告诉我们现在有没有办法像现在的deviceamin API改变Android的牛轧糖更改密码。 – Piyush
@piyush没有更改密码相关的API。他们也应该在牛轧糖中工作。 –
它改变为Android 7请看看.https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String,int) – Piyush