Martin Melka
Martin Melka

Reputation: 7789

How to force device to get new GCM ID?

I am having a weird issue with my app - I have two devices on which I test it. One is 4.4.4, second one 4.0.4. I have made one app which used GCM. It worked without a problem on both phones. Then I made a second one, which had the GCM module copy-pasted from the first one, without any changes.

Now, when I send GCM message to the KitKat phone, it receives it without problems. But I cannot get it on the second phone. It doesn't register it at all (BroadcastReceiver doesn't receive anything). All the while the first app is still working ok. Both phones have the exact apk installed via adb.

I store the GCM registration id in the phone, yet when I run the app on the KitKat, receive an ID, close app, erase data, run it again - I get a different ID second time. This doesn't happen with the second phone, which leads me to believe there has been some kind of error on the side of Google.

I stumbled on this thread, probably dealing with the same issue - GCM not working on Gingerbread, but is working on Ice Cream Sandwich. I tried reinstalling the app, but that didn't help, I am still getting the old (non working) GCM ID.


tl;dr I am unable to receive GCM messages on one phone, while the same app works on another. Probably a problem with registering GCM. Upon reinstallation I am still getting the same GCM ID. How to force Google to get me a new one?


EDIT: The answer below provided the info needed, yet it didn't fix the issue. I will open another thread to avoid misleading title.

Upvotes: 2

Views: 2280

Answers (2)

Rhodesie
Rhodesie

Reputation: 261

I tore my hair out over this for two days... If you are using a device for testing, you need to delete the InstanceID before obtaining the token because once you overwrite your APK it de-registered that InstanceId for some reason... or something along those lines, it ended up working for me. So in your RegisterIntentService class, in the onHandleIntent function do the following:

InstanceID instanceID = InstanceID.getInstance(this);
try
{
    instanceID.deleteInstanceID();
} catch(IOException e) 
{
    e.printStackTrace();
}
instanceID = InstanceID.getInstance(this);

Upvotes: 3

Eran
Eran

Reputation: 393841

I don't think getting a new registration ID would solve your problem, but here's the way I use to get a new registration ID :

  1. Uninstall the app.
  2. Send a GCM message to old registration ID. Repeat this step until you get a NotRegistered error in the response from Google.
  3. Install the app again, which should re-register to GCM, and this time you should get a new registration ID.

Upvotes: 0

Related Questions