Detect if my app is uninstalled

。_饼干妹妹 提交于 2019-12-06 04:36:36

问题


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!


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/15286678/detect-if-my-app-is-uninstalled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!