9

Is there a way to make an application uninstall itself? For example: I want to be able to click on an "Uninstall" button in my app and have the the app uninstall itself.

I can imagine that you can call a function of the firmware and delegate the action to it so the app gets uninstalled.

The reason I need this is that when the app is uninstalled I need to delete some files on the sdcard that were downloaded by the app.

Squig
  • 862
  • 6
  • 15
Hazneliel
  • 531
  • 1
  • 5
  • 16
  • possible duplicate of [install / uninstall APKs programmatically (PackageManager vs Intents)](http://stackoverflow.com/questions/6813322/install-uninstall-apks-programmatically-packagemanager-vs-intents) – Andrew Aylett Mar 29 '12 at 15:21

3 Answers3

18

You can Remove your App using Intent.ACTION_DELETE

try this it work for me

 Intent intent = new Intent(Intent.ACTION_DELETE);
     intent.setData(Uri.parse("package:" + this.getPackageName()));
     startActivity(intent);
Wajdi Hh
  • 785
  • 3
  • 9
3

No you simply can't. At least not for the phones that are not rooted. You can take the user to an Uninstall screen, but they would have to click on "Uninstall" to uninstall the app. For more information visit install/uninstall application programmatically.

Community
  • 1
  • 1
Rajkiran
  • 15,845
  • 24
  • 74
  • 114
0

Unfortunately, you cannot uninstall an app, or even detect that your app is being uninstalled. This is to preserve security and prevents malware from messing with things.

I suggest that instead of using the sd card to store files, you use internal storage. These files are deleted automatically when the app is uninstalled.

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

jsimpson
  • 391
  • 1
  • 5