GCM now losing Registration IDs - android

I have several apps on Google Play that extensively use GCM and they have all been working very well for quite some time now. But, all of a sudden (Aug 12, 2015), GCM is sometimes returning "NotRegistered" when my server posts a message to it.
This is happening just occasionally but that is often enough to cause big problems as the messaging can no longer be trusted.
The last part of the web response stream is: [{"error":"NotRegistered"}]}
I log the registration id along with the response stream and the registration id that I attempted to use is the same one that has always been used for that phone. My apps get a new registration id when they are first ran so it is necessary for the application to be uninstalled and reinstalled to make the app work again. Has something changed?
Oddly, (or not) the problem has only occurred on phones running 5.1 lollipop. Did I possibly miss another breaking change?
Thanks,
Dean

If you are using GoogleCloudMessaging to register, one possibility is that these users received an upgrade of your app. See the latest edit to Eran's answer here.They will need to re-register with GCM. Consider using the latest registration method using Instance IDs, which has a listener for token refresh when needed.

Related

Firebase FCM tokens becoming invalid

I run an Android app that has users that wish to stay registered for push notifications indefinitely, and many use the app for years. I switched over my push notifications to Firebase last spring, and I'm now getting a significant number of users complaining who, after receiving notifications for months without issue, no longer receive notifications (when I try to send to the tokens I have in my database for them, I get either a InvalidRegistration or NotRegistered, not sure which tbh).
Is anyone else having this issue, and is it an issue with Firebase FCM itself? Perhaps onTokenRefresh isn't being called when it should be at times or something? (I'm certain that my code to give a refreshed token to the server is solid - I had no problems for years with the old GCM, although I had to have a bunch of hacks to re-register periodically in addition to when the user updated the app or the OS)
I see that FirebaseInstanceId.getInstance().getToken() can throw an IOException, perhaps that is killing my onTokenRefresh method before it can start sending the token to the server? Do robust apps take this possibility into account and have a mechanism to retry on failure?
Basically, just looking into any insight into why this is happening, if others are having the same issue, and any workarounds people have found. At the end of my rope over here:/

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.
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);
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 :
Uninstall the app.
Send a GCM message to old registration ID. Repeat this step until you get a NotRegistered error in the response from Google.
Install the app again, which should re-register to GCM, and this time you should get a new registration ID.

Android GoogleCloudMessaging.register() returns SERVICE_NOT_AVAILABLE after app re-install

Working on a Google Cloud Messaging-enabled App for a class. I had "round-trip" (App->backend server, backend server->GCM->App) working on both my phone and tablet. After getting things stable, I uninstalled the App on the phone (mainly to trash the database that I'd filled with bogus entries) and then re-installed. However now, when the app attempts to re-register with GoogleCloudMessaging, it kicks back "SERVICE_NOT_AVAILABLE." I had run into this a couple days ago, but it seems like after waiting a couple of minutes, it'd be able to register. I figured it was something on Google's end needing to update. However I've let my phone sit for almost 12 hours now and it still is unable to get a new registration ID.
Is there something more required to get a new registration ID than a call to register()? I've tried calling unregister() as well, thinking that maybe GCM needed a "hint" that the phone needed a new registration ID and that the old one was invalid, but that also kicked back SERVICE_NOT_AVAILABLE. As a side note, the tablet (which has a registration ID) continues to work fine. Messages are being received from GCM. I just get nothing on the phone.
Other info: This is using the HTTP (downstream only) GCM configuration, Phone is API 17, Tablet is API 19. Play services are up-to-date. The implementation I used for the receiver and registration is "pretty close" to what Google provided as their example.

GCM (Google Cloud Messaging) not sending error on uninstall of app

I'm trying to migrate from C2DM to GCM, and it mostly works just fine. C2DM used to handle uninstalls of the app very well by sending a NotRegistered error when the user uninstalled the app. GCM supposedly does this as well (albeit not guaranteed). However, it doesn't seem to be working. After sending multiple GCM notifications to a phone which has uninstalled the app, it still keeps responding with a normal "id=..." response.
Has anyone else come across this problem? If so, how did you solve it?
There's really nothing we can do about it. Only Google knows when an app is uninstalled and update their device registration database accordingly. Perhaps it takes a couple of hours for NotRegistered response to come back? If after a day, you're still not getting that, then file a bug report with them: http://code.google.com/p/android/issues/list
I can't imagine Google will let this bug stay for too long, as they are potentially looking at sending phantom notifications to thousands or hundred thousands of devices.
I've been migrating from C2DM to GCM, and I thought I was having this problem as well. Long story short, try uninstalling the app from your phone/emulator, then dont reinstall it on that phone/emulator and leave the phone/emulator running for a few hours, then you should get the NotRegistered error if you try to push to that device's registration id.
If I recall correctly even if you reinstalled the app in C2DM after uninstalling you'd get the NotRegistered error for the first registration id, this is not the case with GCM (usually if not always the two registration id's will be the same) and I spent a week thinking GCM had some bug where it wasn't sending that error...

C2DM Not always registering

So I have a strange problem, my app has C2DM setup and and it works for the most part, however there is quite a few people who never get registered. So the flow is as follows. On login, we make the registration request, when we get the response on that it submits the registration id to my back-end server and stores it in the database. For some reason I can see that some people logged in just fine, but I never received the registration id on the server, any ideas? I haven't be able to reproduce this my self, but it is affecting a lot of people using my app. Any suggestions on how I can make this more reliable? Because when the C2DM does not work they tend to not stay and use my application.
Any help or advice would be much appreciated.
What do you do on the client side if the registration fails? It could fail for a number of reasons. It'd probably be a good idea to send the status to your backend in failure cases so you can track that. Personally, The most common failures I see are due to not having a logged in google account or having background data turned off in settings.
Could the users in question be on unsupported (pre 2.2) devices?
C2DM in intended for android devices running Android 2.2(API 8) or higher that also have the Market application installed. However, you are not limited to deploying your applications through Market.
Also make sure you make the C2DM registration at very beginning of app start say splash screen. As the C2DM to register and obtain the REG_ID take about 3-4 sec depending upon the network connection.
Also make sure the devices that it is having problem that you reported might be showing the ACCOUNT MISSING:: OR ERROR IN REG_ID when C2DM registration works

Categories

Resources