Android:以编程方式从设备管理器中删除我的应用程序?

前端之家收集整理的这篇文章主要介绍了Android:以编程方式从设备管理器中删除我的应用程序?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试添加一个按钮到我的应用程序从设备管理器中删除它,并使用下面的代码,但我的应用程序只是崩溃.

码:-

按钮点击: –

{
    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) + "'.";
}
原文链接:https://www.f2er.com/android/310985.html

猜你在找的Android相关文章