title: How to self uninstall an app?
body: <p>The problem is this -- my app gets admin rights, to get them, from UI POV is quite easy. However once app has those rights, it is cumbersome to uninstall it (user has to first revoke those admin rights; and if not, when uninstalling there is no info what is going wrong with uninstall -- at least at Ace 2 Android 2.3).</p>
  
  <p>Thus it would be useful, to have a uninstall feature in app -- it would revoke admin rights first, and then follow normal uninstall.</p>
  
  <p>Another approach would be to be notified app is about to be uninstalled, however AFAIK it is not possible -- see: <a href="http://code.google.com/p/android/issues/detail?can=2&amp;q=33315&amp;colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&amp;id=33315" rel="noreferrer">http://code.google.com/p/android/issues/detail?can=2&amp;q=33315&amp;colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&amp;id=33315</a></p>
  
  <p>So far I came up only with workaround -- to save user a problem add a button "clear for uninstall" with status info if app is ready to be uninstalled. But then user has to make another step of uninstalling my app. Troublesome anyway.</p>
  
  <p>So -- how to uninstall self? </p>
  
  <h2>Solution</h2>
  
  <p>Just in sake to keep the code on SO site:</p>
  
  <pre><code>Uri packageURI = Uri.parse("package:"+MyMainActivity.class.getPackage().getName());
  Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
  startActivity(uninstallIntent);
  </code></pre>
  
  <p>the code is copied from <a href="http://android.amberfog.com/?p=98" rel="noreferrer">Android Tales Blog</a>.</p>