As far as I know, apps can't get intents for their own uninstallation:
ADB:
10-20 12:37:00.997: D/BackupManagerService(527): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:mobi.mgeek.TunnyBrowser flg=0x8000010 (has extras) }
10-20 12:37:00.997: V/BackupManagerService(527): removePackageParticipantsLocked: uid=10112 #1
10-20 12:37:01.007: D/dalvikvm(527): GC_EXPLICIT freed 2247K, 12% free 20128K/22868K, paused 3ms+10ms, total 212ms
10-20 12:37:01.107: D/dalvikvm(527): GC_FOR_ALLOC freed 1508K, 15% free 19649K/22868K, paused 60ms, total 60ms
10-20 12:37:01.137: D/AndroidRuntime(4028): Calling main entry com.android.commands.am.Am
10-20 12:37:01.137: D/dalvikvm(4028): Note: class Landroid/app/ActivityManagerNative; has 163 unimplemented (abstract) methods
10-20 12:37:01.147: I/ActivityManager(527): START u0 {act=android.intent.action.VIEW dat=http://survey.dolphin.com/int/uninstall?id=014f4d1981d6f88bb56630e7a3a7550a&pn=mobi.mgeek.TunnyBrowser&v=248&s=ofw&it=1382250136565&ut=1382250127000&m=Nexus 4&os=android&osv=4.3&cc=US&no=40471&lang=en&jk=uninstalled&ft=212&ht=957&ct=0&nt=1&res=768*1184&ifi=1<s=1&iow=0&iom=0&iospd=0&iogs=0&debug=false&t=1382252820000 flg=0x10000000 cmp=com.android.chrome/com.google.android.apps.chrome.Main} from pid 4028
10-20 12:37:01.157: D/AndroidRuntime(4028): Shutting down VM
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. :)