在Android设备中,我们可以有三种类型的锁屏方式:图案锁、PIN码锁和密码锁。
在我的应用程序中,我想通过编程方式更改/重置PIN码。
我将从用户那里接受4位数字,并将其设置为该设备的新PIN码。
是否可以重置此PIN码或者这是违反Android安全策略的行为?
谢谢您。
在我的应用程序中,我想通过编程方式更改/重置PIN码。
我将从用户那里接受4位数字,并将其设置为该设备的新PIN码。
是否可以重置此PIN码或者这是违反Android安全策略的行为?
谢谢您。
<sdk>/samples/android-<version>/
获取示例代码。<version>
数字对应平台的 API 级别。使用反射是最好的方法。使用反射,您可以将设备密码设置为无、滑动、PIN、密码。 以下是帮助您的代码。确保您拥有管理员权限。此代码将更改您的设备密码为滑动。在resetpassword方法中,对于pin,请给出一些值而不是空字符串""。对于无操作设备策略管理器,确保您的应用程序是系统应用程序,即系统签名。
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();
}