You have to check this on your server. You cannot do it from the application code since there is no way of knowing when the user is uninstalling the application.
See: Implement Canonical IDs.
Reference: https://developers.google.com/cloud-messaging/http#request
A canonical registration ID is defined to be the ID of the last registration requested by your application. This is the ID that the server should use when sending messages to the device.
If later on you try to send a message using a different registration ID, GCM will process the request as usual, but it will include the canonical registration ID in the registration_id field of the response. Make sure to replace the registration ID stored in your server with this canonical ID, as eventually the ID you're using will stop working.
Reference: https://stuff.mit.edu/afs/sipb/project/android/docs/google/gcm/adv.html#canonical
If the Canonical ID is not 0, then you have a duplicate registration.
Say for instance, you have 2 registrations in your database:
registration_A
registration_B
When you send a push notification, your server will get respond with something that looks like this:
{"multicast_id":########,"success":1,"failure":0,"canonical_ids":1,"results":
[{"registration_id":"new_id_registration_id","message_id":"0:########"}]}
{"multicast_id":######### ,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:################"}]}
Store this data in an array. Notice that the first one has a "canonical_ids":1. This means there was a duplicate. So to know which record in your database is the old one. Just search for "registration_id" in the above and save the index value. This index value points to the old record in your database.
In the above example, registration_A would be the old registration_id.
Get all the records from your database. Then delete it based on the index value that you retrieved. OR you can update it. That depends on how you set up your database.
Good luck!