我正在尝试将一个按钮添加到我的应用程序中,以将其从设备管理员中删除,并且正在使用下面的代码,但我的应用程序却崩溃了。
代码: -
单击按钮: -
{
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)
就像您一样:
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.removeActiveAdmin(mDeviceAdminReceiver);
但是您需要将这些过滤器添加到AndroidManifest.xml中的接收器:
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
</intent-filter>
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "Admin rights are beeing requested to be disabled for the app called: '" + context.getString(R.string.app_name) + "'.";
}
用启用设备管理(devicePolicyManager)编写了一个应用程序并安装了。但是,当我想卸载它时,此消息的返回失败