以编程方式设置Android所有者密码
假设我有根权限,有没有办法在没有任何用户交互的情况下通过编程设置所有者密码/pin?我必须使用的API级别是17或18。设备管理代码以编程方式设置Android所有者密码,android,Android,假设我有根权限,有没有办法在没有任何用户交互的情况下通过编程设置所有者密码/pin?我必须使用的API级别是17或18。设备管理代码 将其添加到xml文件夹中: device_admin.xml <?xml version="1.0" encoding="utf-8"?> <device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> &
将其添加到xml文件夹中: device_admin.xml
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<!--<limit-password />-->
<!--<watch-login />-->
<reset-password />
<force-lock />
<wipe-data />
<!-- <expire-password />
<encrypted-storage />-->
<!--<disable-camera />-->
<!--<disable-keyguard-features />-->
</uses-policies>
使用此代码检查您的应用程序是否具有设备管理功能,如果没有,请将用户引导到相应的页面
if (!mDPM.isAdminActive(mAdminName)) {
// try to become active – must happen here in this activity, to get result
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
mAdminName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Your Explanation for requesting these Admin Capabilities.");
startActivityForResult(intent, REQUEST_ENABLE);
}
最后,要锁定您的手机:
//Reset Password
mDPM.resetPassword(newPassword, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
//Lock Phone
mDPM.lockNow();
完成查找android的“设备管理员”或设备策略管理器。通过应用程序中的一些代码,如果用户以设备管理员身份激活应用程序,则应用程序可以更改设备密码********这不需要您的设备根目录。**********谢谢,我试试看
//Reset Password
mDPM.resetPassword(newPassword, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
//Lock Phone
mDPM.lockNow();