0

I am creating an application, whose directory is getting created on sdcard ("/mnt/sdcard/testzapp")

I want when user uninstall application the directory is also deleted.
How can I do this?

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
Vishal Mokal
  • 792
  • 1
  • 5
  • 22
  • see this first http://stackoverflow.com/questions/6209730/is-it-possible-to-detect-android-app-uninstall – KOTIOS Aug 02 '13 at 09:42

2 Answers2

8

unfortunately - the answer is: you can't!.

there is indeed broadcast you can listen to when application uninstall - but your app won't get any broadcast for it own uninstall.

what you can do:

instead of creating folder on external storage (sdcard..) you can create your folder in the directory of your application with Context.getFilesDir(). this path is internally for your application, and uninstall of your application will delete this folder also.

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
2

May this help you:

Only way to do that is If you use getExternalCacheDir(), then only folders auto deleted when uninstalling the application... Refer this link: Click here

OR:

Save it in your Applications Private Folder (/data/data/yourappPackege). This folder will be removed when uninstalling the App.
You can get your private Folder with the Method getFilesDir() Other files can not be removed because your App does not "know" when it is being removed.

Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30