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.
Related
I followed a tutorial about GCM Notifications located on the link below:
http://techlovejump.com/android-push-notification-using-google-cloud-messaging-gcm-php-google-play-service-library/
Everything worked fine for me, but, it works only on the emulator.
When i transfer the same apk file to mobile devices, they do not receive notifications while the same app on emulator receives them.
Is there any way i can fix this issue?
The only reason I see that this can happen is when the registration_ID is changed. When this happens the device which is supposed to receive the notification as per the expectations does not receives it because the registration_ID is tied to a different device and account.
Make sure you have a distinct registration_ID for the new test device. And even if the versions of Android OS are different on both you need to re-register. Also you need to check that the Registration_ID is getting refreshed everytime in the Broadcast receiver Bundle when it receives a new Registration_ID from Google.
Since gcm.register() is deprecated make use of the new concept Instance_ID by Google.
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.
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.
I am using Uniqush to send GCM messages to an app I'm developing, and so far this is working well. However, for obvious reasons I am uninstalling and reinstalling the app as I develop, and it's re-registering for GCM with each new install.
I understand GCM is supposed to handle this automatically:
http://developer.android.com/guide/google/gcm/adv.html#unreg
if a message can't be delivered to a device, it sends an error to the server, which handles it. Unfortunately (even after sending a test push message while the app wasn't installed) I am getting duplicate messages to my device.
Is this a failure in Uniqush, my program, GCM, or some combination of the three?
If notifications are sent to a device while it has the app uninstalled, eventually the duplicates clear.
Given your description, I am unable to reproduce your situation. Here are the steps to try to reproduce it:
Install the test app on my phone and push notification to it using uniqush. Correct. Uniqush's log shows it is successfully delivered and my phone shows the correct result.
Uninstall the test app.
push another notification again using uniqush. Uniqush's log shows the message saying the user is unsubscribed the service: [Unsubscribe][Info] 2012/12/21 19:18:08 [UnsubscribeRequest] RequestId=3992a14e4987e94e3ce16bb7394ee06d2d9e7231 Success
DeliveryPoint=gcm:47e6551857be173b1418e56b63dbdb8cd58c94a2
Then push one more notification to the device, uniqush says it cannot find the device (because it has already been removed.)
Check the database using redis-cli, the device's information is no longer stored. It is successfully unsubscribed.
However, I did found some problem: if you check the error message returned from uniqush from HTTP, then you will see Success on the second notification. I have already fixed this bug in next release. It will be online soon. (If you are interested in that, check the .deb package )
In fact, uniqush is designed to be able to handle such situation so that the user don't need to care about unsubscription, device token/registration id update, etc.
If you have any future question, please feel free to comment or contact me.
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...