在 Android 上监听自己的应用程序卸载事件 [英] Listen to own application uninstall event on Android
问题描述
据我所知,应用无法获得自己卸载的意图:
As far as I know, apps can't get intents for their own uninstallation:
但是 Dolphin Browser 如何做到接收已删除"事件并像附加图像一样启动浏览器?
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.
在本机代码中使用 inotify
.例如:您可以使用 inotify_add_watch
来监视应用程序的数据缓存文件夹,例如:/data/data/your-package-name/cache
.
当您的应用程序被卸载时,您可以获得文件夹的删除事件.
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.
另一个关键点是 inotify
应该在与您自己的应用程序不同的进程中运行.
您可以调用 fork()
来执行此操作.
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. :)
这篇关于在 Android 上监听自己的应用程序卸载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!