Detect if an app was uninstalled

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

Is there a way to get a system notification when an app has been uninstalled?

I would like to maintain a table of all clients' info currently using my app. However, that seems impossible if there is no way to detect this event.

The first solution I can think of is to have an always running service in the background listening for android.intent.action.PACKAGE_REMOVED. But then would that service be killed once the uninstallation process has ended, or would it be stopped just before the process has kicked off? Also even if this is a solution it's has the potential to put off a lot of people when they realise that part of the app is running in the background.

Any suggestions? Thanks!

回答1:

You could simply do it the other way round and maintain a table of users actively using your app. Just call a webservice at a point in the program that show it is active. If an app isn't used for a certain time mark it as inactive.



回答2:

The documentation for the PACKAGE_REMOVED action says the following:

The package that is being uninstalled does not receive this Intent.

So you can monitor for other applications being uninstalled but not your own.

So you'll probably need track who is still using your application, not who has stopped using it. If you don't want the overhead of having your own server to do this you could use a free service like Flurry.



回答3:

From Android document, the app uninstalled by user can't not get

Intent.ACTION_PACKAGE_REMOVE 

But we can use other method to implement this feature. We all know that there is a directory named with your package name under the /data/data directory after your app installed by user. If your app is uninstalled by user, the root directory of your app(/data/data/com.example.yourappname) will be removed by system. The remove action happen immediately when user click "uninstall", and the directory will be removed by framework package manager system.

So, we can monitor the existence of your app data directory(which usually /data/data/com.example.yourappname) to detect if your app uninstalled by user.

In order to monitor this directory, we have to fork a detached process from JNI. In this new fork process, we can use Linux system api inotify(7) or access(3) to determine the existence of app's data directory.

Here is a workable implementation. But it got the permission problem when try to send an intent to start system browser on high version Android device. I have no idea how to bypass this. However the example above is enough for your question.

Hope it will be helpful!



回答4:

Android doesn't provide an inbuilt function for tracking the app uninstall.

Notification can be used as an alternate way to track the app uninstall. For this send notification on the app and track the status of the notification. Count the number of undelivered notification for a particular time period. If status of undelivered notification doesn't change in that particular time period, then consider that the app has been uninstalled from the device.

For example, i have used a cron script which run every 3 days and check the status of last 10 notifications delivered to the device (2 notifications are sent in a day). If all of these 10 notifications have status "undelivered", then the app is considered to be uninstalled from the device.



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