GCM framework parameters and GCM Registration ID - android

During a registration request from a subscriber app to the GCM server, the app includes a senderID/projectID and its context. And my guess is when the GCM framework on the client receives the app request, it prepares a request by adding the app package name (uniquely identify the app), device ID (uniquely identify the device), the senderID.
Are there any additional parameters added by the GCM framework?
Is there a relationship between these parameters and the registration ID (or is the registration ID generated randomly)?

Maybe this can help. If you look at table 1 on the attached link, you'll find necessary credentials for GCM:
link

Related

Use GCM / Firebase without clientside SDK

Is it possible to use GCM without any GCM related logic on the client side? The idea is that mobile app shouldn't store / renew tokens etc. Mobile app should just initialise session with the middleware backend which will return back the internal device id and that's it (backend server will register device in GCM / APNs).
The goal is to reduce client side logic and simplify integration, so the flow probably should look like: APP <-> BACKEND <-> GCM
I do not think you can, the documentation states "this app must register with GCM and get a unique identifier called a registration token". There is a whole song and dance the client has to do with GCM that a backend isn't allowed to do. Plus, if the GCM server doesn't know which device is which registration id, it wouldn't know what client to send a notification to.
To GCM documentation states only one process of registering a client:
The client app obtains a registration token using the Instance ID API. The call to this API must have the authorized entity set to your app server's sender ID, and the scope set to the appropriate value for GCM (depending on your platform). Refer to the API reference for full detail on this API.
The client app passes the registration token to the app server.
The app server saves the registration token and acknowledges to the client app that the process completed successfully.

Get GCM Registration ID directly from server

While publishing the Android app, I created a blunder. I commented the code which used to fetch GCM registration ID and send it to our server for persistence. We do have the device ID of all the users, however, their GCM Registration ID is missing on our server side. Is there any way, by which I can register all my users and get their GCM registration ID from the server directly using their respective device ID?
Also, if anyone gives me the correct solution, a Beer treat is assured!
In short No. The GCM InstanceID token identifies an app on a device, so more than the device's ID would be needed to generate the token. Google Play Services on your client device is used to generate the application's InstanceID token. This token cannot be generated from the device ID.
Each app on a device should have a unique InstanceID token, being able to generate this externally from the device with known parameters could be a security issue.

Handle GCM Canonical Id with Amazon SNS

I have questions. How can I handle situation when GCM return canonical id.
I found few same questions on StackOverflow, but there is no solution. Amazon SNS Documentation about token management says that SNS handle this situation automatically. When GCM return canonical id amazon SNS update old tokens with new ones. But how can I know about that? I have my own database with all registered token and endpoints. I don't know if amazon was update token or not and send notification to all of them. As result lots of duplicate messages on device.
P.S. Server have to support multiple devices for one account.
Amazon SNS will handle token management only if your app is registered with them. Since you have your own database and endpoints, you would have to manage it yourself.
After pushing the message from the server, you would recieve the canonical id in the response.
As per Google's docs,
A canonical registration ID is the registration token of the last
registration requested by the client app .This is the ID that the
server should use when sending messages to the device.
If you try to send a message using an old registration token, GCM will
process the request as usual, but it will include the canonical ID in
the registration_id field of the response. Make sure to replace the
registration token stored in your server with this canonical ID, as
eventually the old registration token will stop working.
It is good practice to update your registration id with the canonical id returned after the push.
Also if your device is receiving duplicate notifications these could help:-
It could be due to a bug in the client app triggering multiple registrations for the same device. So make sure the same device is not getting registered many times.
Also, if you uninstall the app from device and you try to send a push to that device, you would get a NotRegistered error from GCM server. Then your server should delete the registration token and not use that registration token again to push messages.
P.S. Even if one user has multiple devices, your db mappings should be such that :- each device of the user will have a different registration token and each of the tokens will be mapped to a single user.
Since the tokens are different, receiving the same message pushed on all devices of the user would not be a problem.
Hope this helps! Cheers!
Please take a look at http://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS for information on how to manage the mobile tokens.

PushSharp Device ID for Android

All,
I'm probably asking a very basic question here, but how does one get your device ID for PushSharp in Android? My setup is VB.net, and we'll be sending to a large number of different Android devices.
Following the PushSharp example here is my code so far:
push.RegisterGcmService(new
GcmPushChannelSettings("YOUR Google API's Console API Access API KEY for Server Apps HERE"));
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(
"DEVICE REGISTRATION ID HERE")
.WithJson("{\"alert\":\"Hello World!\",
\"badge\":7,\"sound\":\"sound.caf\"}"));
I know the API key is from the GCM service, but where does the Device Registration ID come from? Is that setup by the GCM service? Or is that something the android device sends the server should save?
Thanks for the help.
The registration ID is assigned by the GCM service. When the application registers to GCM, it gets a registration ID and should send it to the server.
Registration ID An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
You can read more about it here.
In case you ended up reading this post and could not get yourself sorted out with the selected answer, here is the ultimate link that helped me:
Getting a GCM registration ID

Getting a unique RegistrationID of a Android device to C2DM

To use C2DM for my application i registered new Gmail account with Google as a Sender account.
Now i am confused that how to get RegistrationID for my device and how to associate it with the Sender account. i want to install this application on multiple Andorid phones so do i need unique RegistrationID for each Android phone .
There are two sides to C2DM:
Your server stores registration IDs for the users. It requests n auth code from Google's servers (using ClientLogin) and then uses that auth code to send push messages.
Your Android app requests a registration ID from Google's servers. It is sent one over C2DM. It sends it to the server, to be stored there (so messages can be sent to it).
This tutorial describes it all in detail, with code:
http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
A registration ID is like the address on a postal envelope - it describes where a push message is to be sent, the destination. So yes, you need one for each device. Registration IDs are actually assigned to a specific app (name space) on a specific device.
If you have added the boiler plate C2DM code from http://code.google.com/android/c2dm/ ,when the app registers, it will recieve a registration id , which you have to save it in a database on your server. The registration id can change so you have to notify the server, every time it changes.
To get the registraton id use
C2DMessaging.register(this, "email id");

Categories

Resources