title: Android: Programmatically remove my app from Device Administrator?
body: <p>I'm trying to add a button to my app to remove it from Device Administrator and am using the code below but my app just crashes.</p>
  
  <p>Code:-</p>
  
  <p>On Button Click:-</p>
  
  <pre><code>{
      ComponentName devAdminReceiver = new ComponentName(this, DemoDeviceAdminReceiver.class);
      DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
      dpm.removeActiveAdmin(devAdminReceiver);
  }
  </code></pre>
  
  <p>In the code above, DemoDeviceAdminReceiver is a class that extends DeviceAdminReceiver.</p>
  
  <p>Error log:-</p>
  
  <pre><code>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)
  </code></pre>