[英]Set Android owner password programmatically
Assuming that I have root permissions is there any way to programmatically set the Owner password/pin without any user interaction?假设我有 root 权限,有没有办法在没有任何用户交互的情况下以编程方式设置所有者密码/pin? The API level I have to work with is 17 or 18.
我必须使用的 API 级别是 17 或 18。
Device Admin Code设备管理员代码
Add this in your xml folder:将此添加到您的 xml 文件夹中:
device_admin.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>
These are the different policies you can have in your app.这些是您可以在您的应用程序中使用的不同策略。 Uncomment whichever you need.
取消注释任何你需要的。 Reset password and force lock are the once you want.
重置密码和强制锁定是您想要的一次。
Inside your activity:在您的活动中:
DevicePolicyManager mDPM;
ComponentName mAdminName;
.......
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mAdminName = new ComponentName(this, MyAdminReceiver.class);
Use this code to check whether your app has Device admin capabilities, if not direct user to the respective page.使用此代码检查您的应用程序是否具有设备管理功能,如果没有将用户定向到相应页面。
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);
}
Finally to lock your phone :最后锁定您的手机:
//Reset Password
mDPM.resetPassword(newPassword, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
//Lock Phone
mDPM.lockNow();
DONE完毕
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.