Reputation: 279
Is it possible to have a code that detect if my app has been uninstalled and upon uninstalling, all the relevant folders that my app has created will be deleted automatically?
Thanks!
Upvotes: 4
Views: 7765
Reputation: 279
Thanks for all your solutions! At least I know now my app cannot detect an uninstall.
But I have solved the problem of removing all the relevant folders that my app has created by placing relevant folders in: context.getExternalFilesDir(null).getAbsolutePath()
Everytime Android uninstall ur app, it will delete everything in the /mnt/sdcard/Android/data/com.yourapp.com
folder. context.getExternalFilesDir(null).getAbsolutePath();
put ur folders inside the /mnt/sdcard/Android/data/com.yourapp.com
folder.
Upvotes: 0
Reputation: 45080
Regarding being able to detect the Uninstallation, I'm afraid its not possible.
Whenever an application package is removed(App is Uninstalled), ACTION_PACKAGE_REMOVED intent will be sent out to all receivers EXCEPT for your own.
From the docs:-
Broadcast Action: An existing application package has been removed from the device. The data contains the name of the package. The package that is being installed does not receive this Intent.
This is confirmed here.
Upvotes: 5
Reputation: 208
No dear you cant check that your application is going to uninstall.
But you can create your folder in your cache dir so that when your application will be deleted all folders and files automatically will be deleted.
Please check it. http://developer.android.com/guide/topics/data/data-storage.html
Upvotes: 1