我正在尝试向我的应用程序添加一个按钮以将其从设备管理员中删除,并且正在使用下面的代码,但我的应用程序只是崩溃了。
代码:-
按钮点击:-
{
ComponentName devAdminReceiver = new ComponentName(this, DemoDeviceAdminReceiver.class);
DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.removeActiveAdmin(devAdminReceiver);
}
在上面的代码中,DemoDeviceAdminReceiver 是一个扩展 DeviceAdminReceiver 的类。
错误日志:-
10-28 15:26:09.295: E/AndroidRuntime(26101): FATAL EXCEPTION: main
10-28 15:26:09.295: E/AndroidRuntime(26101): java.lang.IllegalArgumentException: Unknown admin: ComponentInfo{com.dragonnis.intellicover/com.dragonnis.intellicover.DemoDeviceAdminReceiver}
10-28 15:26:09.295: E/AndroidRuntime(26101): at android.os.Parcel.readException(Parcel.java:1331)
10-28 15:26:09.295: E/AndroidRuntime(26101): at android.os.Parcel.readException(Parcel.java:1281)
10-28 15:26:09.295: E/AndroidRuntime(26101): at android.app.admin.IDevicePolicyManager$Stub$Proxy.removeActiveAdmin(IDevicePolicyManager.java:2940)
10-28 15:26:09.295: E/AndroidRuntime(26101): at android.app.admin.DevicePolicyManager.removeActiveAdmin(DevicePolicyManager.java:183)