Run a GCM function before uninstalling app

3

I have an Android application that is using GCM, I wanted to know how the unRegistered method works, how can I do it, so that when the user uninstalls the application it automatically quits my GCM and also like to take it out of my database the id of it, which I think is more complex.

    
asked by anonymous 23.07.2014 / 22:40

1 answer

4

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

There is Broadcast of ACTION_PACKAGE_REMOVED 1 , which is triggered for all receivers that are registered for this Intent , but your application is not notified 2 if they are being uninstalled.

GCM has a form of detection, and is based on the NotRegistered status of the response of a message sending 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 follows 3 :

  • The user uninstalls 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 GCM Client on the device receives the message, queries PackageManager checking to see if it has a BroadcastReceiver configured to accept this message, returning false to the application that has been uninstalled.
  • The 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.
  • GCM Server will respond to your server with a NotRegistered error for this message.
  • Your server removes registration_id from the bank.

This is the only way GCM can detect uninstallation.

Take a look at the HTTP response status type, specifically in the failure field and in the error field of each registration_id (which failed), it comes with the NotRegistered value, which GCM you can submit according to documentation .

References

  • link
  • link
  • link
  • 23.07.2014 / 22:58