I am developing an android chat application using gcm css. My question is that I have already registered user on my xmpp server and I want to login those user using gcm xmpp. I read the google developer tutorials for cloud messaging https://developers.google.com/cloud-messaging/gcm, but there are not much information as per my requirement.
I have some other query as well:-
1) Is gcm server manage users if manage how it manage? Now, We can send message like push notification on particular registration Id. (Using Downstream), But if user uninstall and install the app again then registration id will be changed. So, In this case how can we manage? Will I need the separate server?
If any one have idea. Please reply.
Thanks in advance...
You should need server in order to handle these things.
You need to call your registration mechanism in service class of android; When you get the registration token from GCM during registration save that token in shared preference and send that GCM token with identity such as mobile number/IMEI/Email ID back to the server.
If next time service restarts or GCM token get changes compare with it in shared preference and send the info to server if it doesn't match. In server you can have rest-api/php/java or any other back end tech which will receive request from mobile if in case registration ID changes.
I have checked below links during development which really helped me could help you in case.
Google Samples of GCM
Chat App with XMPP
Chat App using XMPP Smack api
Related
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 trying to make a simple messaging app that has a mysql and php server with an android app. My back end revolves around mysql to store and php to communicate from the database to the device and vise versa.
Now, what I am trying to accomplish is this: sending device->GCM->target device.
What I had in mind was that the database I created stores the gcm Id for all user. That way, when a user wants to send a message, their app sends a message to my database to be stored and retrieves the targets gcm Id and then sends the targets gcm id to the gcm servers to create the push notificiation. When the target receives the gcm message, it sends a response to the database to receive the actual sent message.
Is this possible, and how would I go about doing this?
I already have a gcm receiver implemented from here:
https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging
No. Don't do it.
For any internet connected device (server or mobile) to request a push to a device, it needs to send a POST request to the GCM address (https://gcm-http.googleapis.com/gcm/send) passing the server API key and the device GCM reg id which should receive the message. And having any of those values available on a device is a security risk for your application.
Having your registration ID, means ppl could easily "copy" your ID and start sending messages from their servers on your behalf.
The GCM device registraion ID, means anyone could start spaming your users, and you certainly don't want that.
You could look into GCM Upstream (https://developers.google.com/cloud-messaging/upstream) but that only means your client code will be easier, as it's as simple as calling gcm.send(String);, but you still have to handle that on your server application.
The correct way is to have on your server a table that maps userId with gcmRegId and have devices send to your server messages to their desired userId. Your server should process one device "send" message and create a push to the other device. That logic should be fairly simple on the server side, after you already have a whole chat application developed.
I am developing an app which has login functionality.I am generating only one gcm registration ID per app. If other user sign's in in same app he will start receiving notifications intended for the previous user.
How to handle this situation, so that each user will get notification intended for his/her?
Should I generate gcm reg id for each user?
What is the standard way to handle this situation?
You could try the following things:
When the user logs off, send a request to delete the token on your server, and erase it on your app;
Once the user logs off, you could simply remove the association of "User ID" to "GCM Token" (Or Registration ID) on your server. And when someone logs in again, you make a new association to that Token.
The GCM Token is app specific, but the association you make on your server is totally up to you.
And I can't stress it enough, the token generated by GCM is APP SPECIFIC. If your user logs in on multiple devices, your server should handle that, associating the user ID to multiple Registration ID Tokens.
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.
And from the docs, your server should also:
Before you can write client apps that use GCM, you must have an
application server that meets the following criteria:
Able to communicate with your client.
Able to send properly formatted requests to the GCM connection server.
Able to handle requests and resend them using exponential back-off.
Able to store the API key and client registration tokens.
Able to generate message IDs to uniquely identify each message it sends. Message IDs should be unique per sender ID.
EDIT: You can read more about GCM here.
For further reading, you could also read more on Device Group Messaging.
You can also download some code samples here.
You should store regID as per user.
This is because there is test cases that user1 logs out and user2 logs in. In that case if you have stored regID app specific and not binding with user then user2 will also get notification.
So you need to store regID as per user , app and as well as device specific.
Of course yes every time someone downloads your app, your app should register them with the GCM and be given a reg token, this needs to be sent to your app server, on your app server you need to sort out who you are sending the notification too. you should probably send some login info and reg token when they login so you can identify each person, then write some php or Jquery to send to individual users or all. you should also send the reg token every time they login as these can change without warning.
Your app server should be able to handle removing unused reg tokens and adding new ones
Each android device generate a Unique GCM reg id. push notification from server side will send according to the device id. So at Login time you can send GCM reg id to your server. So from server side push notification will send to device.., that is actual functionality.
Hope this will help
I'm looking to create for my app some authentication. This will basically consist of a user registering (preferably with their google account, although not necessary) and providing a username that is then sent to my server and then having the ability to log in. I then from there would like to be able for the client app to communicate with my server by sending data and receiving push notifications via GCM (google cloud messaging). It is important that the server is able to send a push notification directly to a certain user not to all registered devices.
Would someone be able to point me in the right direction for what I must do? I've had a look at a few tutorials but what I've seen has always sent messages to all registered devices not to a specific user.
Some extra information about the app:
-The client app (user) will need to send a piece of information to the server. This information will also include the user that it needs to be sent to. Once the server receives the piece of information it should send a push notification through GCM to the specified user's client app.
I'm clueless as to how I need to go about setting up the authentication system, any help would be very appreciated!
Thank you very much,
Daniel
Offcourse you can send push notifications to selected users. This process would roughly comprise the following steps:
1) send the User's GCM registration id to your own server along with a unique user id (what ever id you have assigned to that user; could be email or sim id or something like that). Save it in your database.
2) To send Push notifications to selected users, choose users from the database based on some criteria, retrieve their GCM registration ids from the database and forward them the GCM server.
but there is one important thing you must handle. GCM registration ids could change e.g if user uninstalls and re-installs the application. You must update you corresponding database entry in that case.
I m planning to build an android app
the specification of this app is:
1) it should have this ability to send data suach as (new record in database) to the server
2) server also should able to send data or some information to the specific or all android devices
i dont know should all the android-side user register to GCM or not?
if all the user should register to the gcm it is maybe difficult for some people!!!
please give me step by step process about gcm
from client side and server side
You should implement GCM if you need the ability to push information to device and it would be too costly to implement polling. The guide for GCM integration is quite good: http://developer.android.com/google/gcm/index.html and also all the boiler code can be created for you by saying New GCM enabled Android app.
I have done something similar:
Yes all users should have GCM implemented (but this does not require user interaction)
The GCM framework gives each device a unique registration id. Store this id together with other user information on server database.
When server receives a message from say user A with registration id 12345, who wishes to send the message to user B and C.
Now it is easy for the server to look up user B and C and their registration I'd forward the message, possibly adding the information that it came from A.