GCM - Old Server key - android

I have a very weird issue in my android app that uses GCM for sending notifications to the user.
Initially, I created a new project on Google console and activated the GCM API. I added the JSON file into my app and my server was sending the notification with the provided API key.
Few days back, I created a new project under a new account. So I got a new JSON file and a new API key for server. I added the new JSON file in my app and added the new API key in my server script. But the issue is, some devices get the notifications with the new key but for some devices, I still need to send the notification using the old API key. These devices have the updated application installed on them.
I am not able to figure why is this happening. I am planning to migrate to FCM soon but still I would like to figure out the reason behind such behavior if in case it repeats in the future.

Related

GCM new server key - What to do with old server key?

Today I implemented the new GCM flow in one of our apps which has been on the market for several years already and uses the old GCM. I must have missed when they changed it in October.
So I did all the stuff that had to be done, registered the app in the Google API console, downloaded the google-services.json and so I also generated a new server API key.
Now this new server API key works fine with the new GCM flow, but in our backend there is still the old server key which still works for the user with the currently released app.
So what do we do now? Just replace the old server key and hope the users will update the app? Or put in some condition depending on app version?
What is the best way to handle this transition?
Thx in advance :)

How does the communication between app, proxy and google work?

I'm currently developing an android application with two versions prod and dev. Everything is working fine, however I don't understand what is actually happening in the background. I have created a diagram to illustrate my setup.
My communication setup (app->server->google):
Both versions have the same GCM sender (created in the same google project) and different google api keys (each app has its own applicationID). A server is responsible for the communication between the users of each app version. An app sends the server the user's regID and message. The server then forwards this request and the google api key 1 of prod to google. Google then sends the corresponding push notifications.
This setup is working for both app versions prod and dev. I tried to switch the google api key (1/prod) of the server to the other one (2/dev) in case the dev app is communicating with the server. As a result no messages could be sent anymore.
Can somebody help me understand what is actually happening?
My theory is that google registers the regIDs with the initially sent google api key.

PushNotification Phonegap in Android

I'm using this plugin (https://github.com/phonegap-build/PushPlugin) to send notifications to my users using my android app. Well, so far it's ok.
I have the following questions:
Every time the user opens my app I need to generate a new "RegID"? Or,is not necessary?
Because I'm saving the "RegID" in the database, for later make a shipping notification with PHP to the user's device.
What if every time open the app necessary generate a new "RegID" need to update my database alright?
Somebody can help?
No, you don't have to generate a new Registration ID in each launch of your app. You should only generate it the first time your app is launched (and it's also recommended by Google to generate it again when a new version of your app is installed).
Even when you request Google for a new Registration ID, you might get in response the same registration ID you already had, in which case make sure you don't duplicate that Registration ID in your DB.

Why re-register to gcm when application gets updated?

I am using gcm in my application.
In Google Developers Console page, I created a project and obtained a project id:
Using this project id in my application, the user gets registered to the gcm servers and obtain a registeration id. Then it is sent to my 3rd party server to be stored.
When 3rd party server wants to send message to the user, it uses the apikey I've obtained in the Google Developer Console page in the header of the post action and uses ther registeration id that has been stored for this particular user. The api key I'm using is from:
Please note that it's the key for server applications and the way i'm using this information is as just as I explained.
Everything works fine, messages are retrieved by the correct users and so on.I'm planning to deploy my app on google play but what is written in the section:GCM advanced topics confuses me. it says :
When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version
and on the comment section of the sample code in Implementing GCM client sample code there is this comment:
// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.
What is meant by these two explanations? I thought unless I press regenerate key here:
my api key wouldn't change. Why should it (or does it really) change when I update my application? or am I getting something wrong?
You are mixing between two different terms - API key and Registration ID. You don't have to create a new API key when deploying a new version.
What Google recommend to do (in the quotes you included above) is to re-register each device that installs the new version to GCM (and not rely on a previously obtained Registration ID), because the existing Registration ID assigned to the device for your application is not guaranteed to work for the new version of the app.

GCM HTTP Error 401: Unauthorized

I have integrated GCM on client also made its Server side component. Every thing was working fine, I was able to send push notification from server to all the registered client. I am using google App engine as my server.
Problem came when:
I changed the API Key on server.
Earlier I was using my personal GMail account to get API Key and all other access was through my account. Just before pushing the application live I moved the server to Production account and also changed the IDs as per production Ids. By Id I mean API Key, project ID, Production Keystore etc. Now the issue is when I want to send Push notification on Server I am getting URL Exception "HTTP Error 401: Unauthorized"
I tried doing:
- Deleting my older Ids.
- Deleting Old Public API access keys.
The same code works fine if I try to send Push notification from my old Server.
Does it has something to do with : Project package name and API key... which gets registered once can only be used....If yes How to delete that without changing the client project package name.
Please help we cannot go live with Old Server.
Check if ports 5228-5230(GCM ports) are open in the new server. It could be the problem.
The issue can be beacause you are using the old server api key for the new server as well. For sending the push notification from server side, you need the api key generated with the help of server's public IP address.
If it is testing purposes, make sure your server API key on the google console has the relevant ip addresses in the whitelist:
0.0.0.0/0
::/0
These are for ipv4 and ipv6 ips
Since this is an older question that was never answered but still gets views, I'll post here that this issue may have been obsoleted as the Cloud Console has gone through a couple of iterations since then.
Also, Google Cloud Messaging has been superseded by Firebase Cloud Messaging. New projects should use FCM, and existing projects are encouraged to upgrade in order to benefit from new features.
Firebase Cloud Messaging
https://firebase.google.com/docs/cloud-messaging/

Categories

Resources