Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I uninstall my app , Can we remove my folder which is created through my app?

Tags:

android

I am facing this problem that, when I uninstall my app folder still available in the sdcard path,

What should I do to remove it ?

please suggest something to make it happen ...

like image 238
Akarsh M Avatar asked Apr 13 '13 13:04

Akarsh M


2 Answers

What should I do to remove it ?

Use getExternalFilesDir() and/or getExternalCacheDir() for your files on external storage ("sdcard"). Those directories are automatically removed when your app is uninstalled.

Beyond this, nothing else is possible, as you do not get control when your app is removed.

like image 121
CommonsWare Avatar answered Sep 26 '22 18:09

CommonsWare


Unfortunately, in simple words, the answer is: no, you can't.

Reasons:

  1. You need to broadcast, that you can listen when you app is Uninstalled. but the application which is going to be uninstall won't get any broadcast for its uninstall.

  2. If you created any folders on a device's external storage there is no way for you to call code when the user uninstall your app.

Suggestions and solutions:

  1. Only way to do that is If you use getExternalCacheDir(), then only folders auto deleted when uninstalling the application.

  2. If you are targeting API Level 8 or higher, you can use Context#getExternalFilesDir() for your external files and those will be removed on uninstall.

like image 21
Pankaj Arora Avatar answered Sep 22 '22 18:09

Pankaj Arora