简体   繁体   中英

Detect if my app is uninstalled

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!

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 .

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM