Android 从未调用DeviceAdminReceiver
我成功获得管理员权限,一切正常。唯一的问题是,DeviceAdminReceiver从未被调用。我正在尝试检查失败密码的数量Android 从未调用DeviceAdminReceiver,android,android-studio,Android,Android Studio,我成功获得管理员权限,一切正常。唯一的问题是,DeviceAdminReceiver从未被调用。我正在尝试检查失败密码的数量 public class MyAdminReceiver extends DeviceAdminReceiver { void showToast(Context context, CharSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } @Override p
public class MyAdminReceiver extends DeviceAdminReceiver {
void showToast(Context context, CharSequence msg) {
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onPasswordFailed(Context context, Intent intent) {
showToast(context, "Sample Device Admin: pw failed");
Log.d("Hello", "onPasswordFailed");
DevicePolicyManager mgr = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
int no = mgr.getCurrentFailedPasswordAttempts();
if (no >= 3) {
showToast(context, "3 failure");
mgr.resetPassword("111111", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
//mgr.lockNow();
}
}
@Override
public void onEnabled(Context context, Intent intent) {
showToast(context, "Sample Device Admin: enabled");
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "This is an optional message to warn the user about disabling.";
}
@Override
public void onDisabled(Context context, Intent intent) {
showToast(context, "Sample Device Admin: disabled");
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
showToast(context, "Sample Device Admin: pw changed");
}
@Override
public void onPasswordSucceeded(Context context, Intent intent) {
showToast(context, "Sample Device Admin: pw succeeded");
}
}
我也在我的舱单上声明了
<receiver
android:name=".MyAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
</receiver>
和设备管理
<?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 />
</uses-policies>
</device-admin>
谁能给我一个建议这是什么原因?
谢谢。可能会改变
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
到
res/xml/device\u admin的内容是什么?嗯,这看起来不错(除了你要求很多管理功能…)。上次我试过,效果很好。试试看,或者看看你的实现和你的想法是否有什么明显的不同。可能是重复的。请看我的答案。问题很可能是由于您使用了长度小于4的错误密码/PIN/模式。
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
<action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
</intent-filter>