I have setup Google Cloud Messaging on Google App Engine. I have successfully managed to implement downstream messaging to an Android client.
I have the following questions regarding the usage of GCM:
Does it allow user to user messaging?
Where can I check the delivery status of upstream messages?
If user to user is not possible, what's the solution to setup a basic chat between users using GCM?
You can consider this implementation to work with GCM
Device A ------> Your Server ------> GCM Server ------> Device B
Device B ------> Your Server ------> GCM Server ------> Device A
1. Does it allow user to user messaging?
To create a user to user messaging, you can use device to send a request to the GCM server and vice-versa for the corresponding device as illustrated above.
2. Where can I check the delivery status of upstream messages?
I refer the delivery status of the upstream message as the recipient getting a message on his device. When the recipient receives his message, you can send an acknowledge back to your server to indicate the success.
Alternatively, you can also check the status of your message being sent to your server and the GCM server if you wish to simplify the process.
Hope this helps!
Related
I want to know whether push notifications are delivered to all the registrationId mapped to my user database or not.
I have 8000 users and all are having registrationId. I had sent notification to all of them and now i want to determine whether all those user had received the notification or not.
so is there any way to access this analytics using some FCM url.
I am aware that i can see analytics in google publisher from STATISTICS menu and selecting FCM messages and to check the delivery status i can go to FCM Diagnostics
Firebase support page
but using that tool to determine 8k users is nearly impossible so how can i get the analytics of cloud messaging.
Long back i have seen some link but forgot to bookmark :(
There is currently no API to retrieve the delivery status for sent FCM messages.
In general, when the FCM server successfully receives the payload you've sent from your App Server, it should return a success:1 response along with a message_id.
If what you're aiming for is to know if the device has successfully received the message, you should implement Delivery Receipts:
Delivery Receipt: If the app server included delivery_receipt_requested in the downstream message, the XMPP connection server sends a delivery receipt when it receives confirmation that the device received the message.
I am completely new to push notifications, FCM and Ionic.
I have followed this tutorial to create a push notification using Ionic 2 and it works.
It feels like there is no use of device-id (generated at the client side) at the server side in this ionic doc.
I am unable to understand how to send different push notifications to different users using the same app and same server code?
Also whats the purpose of FCM (Server key and Sender ID) here?
What's the exact workflow, does it works like a web-socket?
Thanks for the guidance :)
1. It feels like there is no use of device-id (generated at the client side) at the server side in this ionic doc.
The device-id (aka the Registration Token) is the identifier for the specific device you intend to send the push notification to. Saving this value in your App Server is important so that you can send push notifications specifically towards it (should you decide/need to) later on.
2. I am unable to understand how to send different push notifications to different users using the same app and same server code?
As mentioned above, this is where the device-id (Registration Token) comes into play. For each device, there is a corresponding unique id, which you'll have to specify in your payload.
3. Also whats the purpose of FCM (Server key and Sender ID) here?
You can refer to the FCM docs for these:
Server Key - A server key that authorizes your app server for access to Google services, including sending messages via Firebase Cloud Messaging. You obtain the server key when you create your Firebase project. You can view it in the Cloud Messaging tab of the Firebase console Settings pane.
Important: Do not include the server key anywhere in your client code. Also, make sure to use only server keys to authorize your app server. Android, iOS, and browser keys are rejected by FCM.
Sender ID - A unique numerical value created when you create your Firebase project, available in the Cloud Messaging tab of the Firebase console Settings pane. The sender ID is used to identify each app server that can send messages to the client app.
To keep it short, Server Key is for authenticating, Sender ID is for identifying from which project the message is coming from.
4. What's the exact workflow, does it works like a web-socket?
Not really. Having a web-socket means that having the connection always active until decided to be closed, where in FCM (or even before, GCM), the lifecycle is like this:
Lifecycle Flow
Send and receive downstream messages.
Send a message. The app server sends messages to the client app:
The app server sends a message to GCM connection servers.
The GCM connection server enqueues and stores the message if the device is offline.
When the device is online, the GCM connection server sends the message to the device.
On the device, the client app receives the message according to the platform-specific implementation. See your platform-specific documentation for details.
Receive a message. A client app receives a message from a GCM connection server.
Send and receive upstream messages. This feature is only available if you're using the XMPP connection server.
Send a message. A client app sends messages to the app server:
On the device, the client app sends messages to the XMPP connection server. See your platform-specific documentation for details on how a client app can send a message via XMPP.
The XMPP connection server enqueues and stores the message if the server is disconnected.
When the app server is re-connected, the XMPP connection server sends the message to the app server.
Receive a message. An app server receives a message from the XMPP connection server and then does the following:
Parses the message header to verify client app sender information.
Sends "ack" to the XMPP connection server to acknowledge receiving the message.
Optionally parses the message payload, as defined by the client app.
I am unable to understand how to send different push notifications to different users using the same app and same server code?
It's your task. Your message must contain all neccessary data (i.e. userId) so your app knows which of the users are target for that message.
I was wondering how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application for which it was intended ?
Can anyone let me know how it is done ?
You question : how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application.
From your question it looks like you willing to know about data
workflow & Client Server architecture that exists in applications
which are using the GCM service.
As per google’s documentation “Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. GCM is a service provided by Google for developer that helps developer to send data from server to any number of Android devices.
Simplified Application Specific Work-flow:
The push notification can be broadcasted either to the mass audience
or a select set of users. Mass audience is targeted when the
notification has to be sent about a marketing campaign. A subset of
users are targeted when a personalized information has to be sent.
The below steps explains how push notification works on android devices:
First android device sends sender id, application id to GCM server
for registration.
Upon successful registration, GCM server issues registration id to android device.
After receiving registration id, device will send registration id to our server.
Our server will store registration id in the database for further use.
Whenever push notification is needed, our server sends a message to GCM server along with device registration id (which is
stored earlier in the database).
GCM server will deliver that message to respected mobile device using device registration id.
This can also be understand using following figure
An Example Workflow:
So, from above images it easy to understand that whenever the android
application is first installed by the user, then it registers itself
to GCM server, and obtains unique GCM ID, then it's our Host servers
responsibility to keep this newly registered Registration ID of the
android user into Database, and then it will be used whenever server
side application willing to send the message to that particular
android user.
So, let us consider one case; suppose an Server wants to send Some data to Android User, which has already registered it's GCM ID 1234567 when it's first time installed, and as it's in the server's database the server application will fetch it from DB, and simply make a HTTP POST request to the GCM server in JSON format, which will have registered user's GCM ID along with the data to send , in same way the GCM Server has the record of all the Registered GCM/Android Clients, it directly forwards that message to the intended android user, and android app in user's phone will raise and Notification alert, to indicate an push notification has arrived.
Hope This answers an question!
GCM stands for Google Cloud Messaging.
Every push notification receive on any Android device is sent by the GCM only.
sender -> GCM -> Android Device
when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.
GCM can't deliver Push without Unique Device ID.
while implementing push notification there are two important things, application key and server key ... these are unique Keys.. using these keys GCM identifies the application to whom push notification is related
I am new to GCM and not clear about the registration process between client and the app server. Since GCM upstream messaging is available, when client registers with GCM, is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
I saw a push notification diagram somewhere that shows no connection between app server and the client. All the communication can be passed through GCM.
Thanks!
is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
if you intend to send messages to individual devices you still have to send the reg id to your server.
if you do not need to have the ability to send to individual devices then you can have the app subscribe to topics and then all your server has to do is send a message to a topic and anyone subscribed to that topic will get the message
The client has to inform the token to the app server somehow.
From the docs:
(...)
2 - The client app passes the registration token to the app server
3 - The app server saves the registration token and acknowledges to the client app that the process completed successfully
If you have seen the registration diagram then you may notice that your app connects with GCM server to obtain a key. So basically your app acquires a token ID. That means your app needs to send this id to your server and not GCM server.
Then you can simply send Push Notification to a Single user, Groups of User, or to an Topic.
I'm trying to use GCM to establish communication between some users. They should send to each other their GPS location. Is it even possible? There is a subscribeToCloudMessage method but I don't know whether it will be useful or not.
Info: Server works fine (Google app-engine) with all the required keys.
It's possible for one app to send a message to another app via Google Cloud Messaging if the sending app knows the registration ID of the recipient app. Usually when a app register to Google Cloud Messaging, it sends it's Registration ID to a server, and that server sends GCM notifications. If you want the app to send the notifications directly, you must send each device (where the app is installed) the Registration IDs of other devices that it needs to send messages to.