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).
Thus it would be useful, to have a uninstall feature in app -- it would revoke admin rights first, and then follow normal uninstall.
Another approach would be to be notified app is about to be uninstalled, however AFAIK it is not possible -- see: http://code.google.com/p/android/issues/detail?can=2&q=33315&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&id=33315
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.
So -- how to uninstall self?
Just in sake to keep the code on SO site:
Uri packageURI = Uri.parse("package:"+MyMainActivity.class.getPackage().getName());
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
the code is copied from Android Tales Blog.
Take a look on these couple of questions (they are related to installation/uninstallation)
Implicit intent to uninstall application?
install / uninstall APKs programmatically (PackageManager vs Intents)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With