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
- http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED
- https://stackoverflow.com/questions/6209730/is-it-possible-to-detect-android-app-uninstall
- http://developer.android.com/google/gcm/adv.html#unreg