Listen to own application uninstall event on Android

感情迁移 提交于 2019-11-26 22:12:00
aarontang

Here is a way you can get uninstall event of your own app.

Using inotify in native code. For example: You can using inotify_add_watch to monitor your application's data cache folder like: /data/data/your-package-name/cache.
When your application gets uninstalled, you can get the folder's delete event.

Another key point is that inotify should run in a seperate process from your own application.
You can invoke fork() to do this.

I've already verified the logic. :)

sergej shafarenka

This is a security issue in Andorid, which is already reported to Google Team and fixed in Android 4.4. Here is my explanation of how it can work.

Smile2Life

When the user go to app manager in phone setting, and click on your app, you receive a broadcast that contain your app name in extras, if the user click uninstall btn, the com.android.uninstaller.UnistallerActivity must be launched.

If you get an intent and your app name in extras, that mean that the user clicked on your app in "app manager", use PackageManager to start an activity watcher and get the top visible activity and his package, if the user click uninstall button you get UnistallerActivity as top activity there you can popup a survey on the web browser or do what do you want do there.

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