Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android duplicate registration id for different devices

I am seeing this issue on my push notifications server - different Android devices (identified by their IMEI) receive the SAME registration id from Google's GCM service. Isn't the registration id supposed to be unique? at east for the same application or GCM API Key?

I saw this thread but there doesn't seem to be an answer there: Can two different devices have same GCM Registration ID?

Any help would be much appreciated

EDIT here is the relevant code for registration:

 Intent intent = new Intent(
                                   "com.google.android.c2dm.intent.REGISTER");
                   intent.setPackage("com.google.android.gsf");
                   intent.putExtra("app",
                                   PendingIntent.getBroadcast(context, 0, new Intent(), 0));

                   intent.putExtra("sender", flatSenderIds);
                   context.startService(intent);
like image 864
Orr Avatar asked Feb 28 '14 17:02

Orr


1 Answers

The only idea that comes to my mind is that this deprecated method will assign the same ID on different devices if the extra value for sender is the same on all of them. That differs from the current version where you don't say who you are, you don't even send an Intent, you just call register() and Google determines who you are and what ID you should be given.

If you finally use this new library, there's an example snippet of how to register (inside an AsyncTask or a Thread):

GoogleCloudMessaging gcm = null;

try {
  // Will be for the first time
  if (gcm == null)
    gcm = GoogleCloudMessaging.getInstance(your_context);

  // Registration against the GCM service
  String regid = gcm.register(YOUR_SENDER_ID_OBTAINED_FROM_YOUR_PROJECT);

  // You'll need to send the registration info to your remote server
  registerRemoteServer(regid);

  Log.d("MyGCM", "Registered on GCM as " + regid);
}
catch (final IOException ex) { ex.printStackTrace(); }
like image 104
nKn Avatar answered Oct 26 '22 17:10

nKn