Is it possible to detect Android app uninstall?
Asked Answered
U

7

68

My app is using Google's C2DM (push notification) to notify users about new activity from friends. Once they install the app I register the device with C2DM servers and store user's phone number. So I know that the user is using my app and I can send him/her the push notifications. But what happens if users uninstalls my app, is there a way to catch it in my app? Or the only way is to catch an error on my server when I send a C2DM and it's unreachable, then mark a user as inactive?

I would love to notify users when their friends are using an app and when they no longer do.

What's is the best solution for this scenario?

Undaunted answered 2/6, 2011 at 2:15 Comment(3)
The following app (somehow) opens a new tab in the default browser as soon as you have uninstalled it: play.google.com/store/apps/details?id=com.UCMobile.intlPhotomontage
For new app developers: please don't store the user's phone number. Use the advertising ID instead.Swelter
@MsYvette: this question is a duplicate of How can an app detect that it's going to be uninstalled, which has better answers. That one should be canonical.Swelter
C
27

Unfortunately the ACTION_PACKAGE_REMOVED intent will be sent out to all receivers except for your own. This is confirmed here.

Some questions for your C2DM plan, since I'm not very familiar with it. If the user just leaves their device off for a long period of time, will that trigger the error condition you use? How does C2DM actually report an "unreachable" device? Is that a condition that only occurs when it attempts to send the push notification and fails or is it when it somehow determines it reaches the device but fails to be handled properly? Obviously in the second scenario your plan would work, but I can see some "false positives" occurring otherwise.

Older SO question for reference: android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package

Chemoreceptor answered 2/6, 2011 at 2:23 Comment(6)
The application NQ Mobile Security is calling an Activity at uninstall look at the i.imgur.com/Fos9N.png, i.imgur.com/fIZbK.png, i.imgur.com/cG9Hr.png and the question #10219828Fumikofumitory
Ok, someone downvoted me recently on this. Did it change since I answered this 5 years ago?Chemoreceptor
@MattC: I've fixed the docs on the Android site. Maybe the downvote is due to other answers offering some solutions?Swelter
If it isnt possible then how Firebase Analytics provides app_remove events automatically?Herbivorous
@OfekRon I wrote this answer 5 years ago. It occasionally would show up for me and my own packages but not always. Perhaps now it is always delivered before your app is uninstalled.Chemoreceptor
@OfekRon so the documentation I posted still states "The package that is being removed does not receive this Intent." so there must be some other way aside from registering for that particular broadcast intent.Chemoreceptor
O
50

The GCM documentation explains this situation here:

https://developers.google.com/cloud-messaging/registration#how-uninstalled-client-app-unregistration-works

"An application can be automatically unregistered after it is uninstalled from the device. However, this process does not happens right away, as Android does not provide an uninstall callback."

Basically when GCM tries to send the next push notification, the device will tell GCM the receiving application was uninstalled.

As for notifying friends that their friends aren't using the app any more, GCM will send a NotRegistered error to your notification server when this failure occurs; it won't be immediate, but could you use that?

Onwards answered 3/12, 2012 at 14:56 Comment(0)
C
27

Unfortunately the ACTION_PACKAGE_REMOVED intent will be sent out to all receivers except for your own. This is confirmed here.

Some questions for your C2DM plan, since I'm not very familiar with it. If the user just leaves their device off for a long period of time, will that trigger the error condition you use? How does C2DM actually report an "unreachable" device? Is that a condition that only occurs when it attempts to send the push notification and fails or is it when it somehow determines it reaches the device but fails to be handled properly? Obviously in the second scenario your plan would work, but I can see some "false positives" occurring otherwise.

Older SO question for reference: android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package

Chemoreceptor answered 2/6, 2011 at 2:23 Comment(6)
The application NQ Mobile Security is calling an Activity at uninstall look at the i.imgur.com/Fos9N.png, i.imgur.com/fIZbK.png, i.imgur.com/cG9Hr.png and the question #10219828Fumikofumitory
Ok, someone downvoted me recently on this. Did it change since I answered this 5 years ago?Chemoreceptor
@MattC: I've fixed the docs on the Android site. Maybe the downvote is due to other answers offering some solutions?Swelter
If it isnt possible then how Firebase Analytics provides app_remove events automatically?Herbivorous
@OfekRon I wrote this answer 5 years ago. It occasionally would show up for me and my own packages but not always. Perhaps now it is always delivered before your app is uninstalled.Chemoreceptor
@OfekRon so the documentation I posted still states "The package that is being removed does not receive this Intent." so there must be some other way aside from registering for that particular broadcast intent.Chemoreceptor
B
8

Yes, but it is quite hacky. The method is based on the fact that the first thing android does when uninstalling your app is deleting your data file. So you could use a file watcher to detect the deletion. Also you need to write this in native code. If you write your code in java, your app will be uninstalled before it could execute any code. please see this demo : https://github.com/sevenler/Uninstall_Statics

Bangle answered 2/7, 2015 at 2:54 Comment(0)
J
7

Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.

First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.

The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.

Joanejoanie answered 1/3, 2012 at 16:5 Comment(0)
B
5

I have some points to tell you ,

  1. Android community recommends you to use GCM instead of C2DM as it's no longer available.
  2. In android there is no way for applications to get itself notified that app is getting uninstalled.
  3. in GCM if you want to stop sending messages to uninstalled apps you can refer this

When you send messages to GCM from your server you will get response string.In that if you are getting error as "NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device or it does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents."

Billiards answered 18/1, 2013 at 6:46 Comment(0)
N
3

I know only one way with server response 200 with "NotRegistered" message in body.

NotRegistered — The registration_id is no longer valid, for example user has uninstalled the application or turned off notifications. Sender should stop sending messages to this device.

Necktie answered 4/6, 2011 at 9:31 Comment(0)
W
2

Look into this GCM doc: GCM Unregistration

You should never unregister your app. This is taken care from server side.

Walkout answered 26/8, 2013 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.