2

while installing app on phone i am creating directory using new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myfoldername/Filename.db");

But now i want to delete folder i.e. myfoldername from SD card, while app is getting uninstalled. I read deletion through broadcastreceiver but still i unable to delete folder from SD card.

Community
  • 1
  • 1
inj3ct0r
  • 197
  • 1
  • 3
  • 13

1 Answers1

4

That is not possible. Your app does not get control at uninstall time.

You should switch to putting your files on external storage in getExternalFilesDir() and/or getExternalCacheDir() (methods on Context, such as your Activity). Those directories, along with your internal storage, are all removed automatically upon an uninstall.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • my app doesn't have fixed location ,i mean if sd card is not present then it creates folder on internal storage .So how to handle that – inj3ct0r Jan 13 '15 at 18:11
  • @inj3ct0r: Internal storage (e.g., `getFilesDir()`) is automatically deleted on uninstall. You do not need to do anything. Note that your original question is not about [internal storage](http://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html), but instead is about [external storage](http://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). None of this has anything to do with [removable storage](http://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html). – CommonsWare Jan 13 '15 at 18:13