Listen to own application uninstall event on Android

前端 未结 3 1232
鱼传尺愫
鱼传尺愫 2020-11-28 08:35

As far as I know, apps can\'t get intents for their own uninstallation:

  • ACTION_PACKAGE_FULLY_REMOVED
  • ACTION_PACKAGE_REMOVED

But how doe

相关标签:
3条回答
  • 2020-11-28 09:22

    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.

    0 讨论(0)
  • 2020-11-28 09:22

    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.

    0 讨论(0)
  • 2020-11-28 09:25

    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. :)

    0 讨论(0)
提交回复
热议问题