Client side & Server side & GCM - android

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.

Related

How to send Google cloud messaging message to other devices without logic on 3rd party server

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.

Is it possible log in with existing xmpp user using gcm css?

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

Can I send gcm message directly from one device to another if sender app has registration id of reciever?

I want to know if there is any way to send push notification from one client app to another directly without app server. If for example client app A has GCM registration id of client app B then can A send push notification directly to B without web server. Please guide me on how to accomplish this task if it is possible. I did not find any article about this topic on google and also the official documentation is not pointing out this phenomenon.

GCM between User to User from same Android App

I would like to implement GCM in my Android app:
One Android app
Registered- U_user and another M_user.
I have Google Sign In in my app thats works fine with JSON and GSON and local MySQL database server with tomcat-server restutil to keep storing Gmail login users.
So, I want to send a notification from U_user to M_user.
U_user does a registration that has been pushed to M_user.
How can I do this?
I am assuming you mean the same Android app installed on different phones (U_user's phone and a separate phone for M_user).
To quote a section in the docs:
To make sure that messages go to the intended user:
Your app server can maintain a mapping between the current user and the registration ID.
The app can then check to ensure that messages it receives match the logged in user.
What this means is that you can send messages to another user through GCM. To let the app server know what to send to M_user, let U_user send an upstream message to your GCM app server (only possible in app servers using XMPP - see here). Alternatively, you have the option to do POST requests to your app server via HttpUrlConnection (can work on both XMPP- and HTTP-based GCM app servers).
Regardless of which method you use, specify in these messages to the server that you would like to send a message to M_user.

Android Authentication and GCM Push notifications

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.

Categories

Resources