Run a GCM function before uninstalling app

Asked

Viewed 299 times

3

I’m with an Android application that is using GCM, I wanted to know how the unregistered method works, how can I do, so that when the user uninstalles the application he automatically leaves my GCM and also would like to take from my database the id of it, something I already find more complex.

1 answer

4


There is no Intent/Receiver or "callback" that your application may notified of its own uninstallation.

There is a Broadcast of ACTION_PACKAGE_REMOVED1, which is shot to all receivers who are registered for this Intent, but your application is not notified2 if they are being uninstalled.

GCM has a form of detection, and is based on status NotRegistered of a message sent to the GCM server.

This is the only indication that the application has been uninstalled and is no longer available to receive messages. The steps are as follows3:

  • User uninstall your application.
  • Your server tries to send a message to the GCM server, targeting your application that has been uninstalled on a particular device.
  • GCM sends the message to the device.
  • The device’s GCM Client receives the message, consult the PackageManager checking if you have a BroadcastReceiver configured to accept this message, returning false for the application that was uninstalled.
  • GCM Client notifies the GCM server that the application has been uninstalled. And the GCM server marks that registration_id for deletion.
  • Your server tries to send a new message to the same application/device.
  • The GCM Server will respond to your server with a NotRegistered for such a message.
  • Your server removes the registration_id bank.

This is the only way using GCM to detect uninstallation.

Take a look at the status type of the HTTP response, more specifically in the field failure and in the field error of each registration_id (that there was failure), it comes with the value NotRegistered, which the MCG may send in accordance with documentation.

References

  1. http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED
  2. https://stackoverflow.com/questions/6209730/is-it-possible-to-detect-android-app-uninstall
  3. http://developer.android.com/google/gcm/adv.html#unreg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.