Currenlty I am trying to develop a simple chat application for Android. I want to create something that works like WhatsApp. Because it should be realtime, I think C2DM is the best way to send a notification when a user sends a message to another user.
Because I have read that C2DM is build for noticiations only, and not for messages I have to find a way to deliver those messages to that other contact.
Now, I have a application server, that can send C2DM notifications. But what's the best and the most energy saving way to send and receive the 'textmessages'?
I have read about polling, but it's not that energy saving I think. I have read something about 'XMPP', but how can I combine that with C2DM?
User A sends message to User B, that is, it sends a message to your application server.
You app server receives a message from A to B. It sends a C2DM notification to B telling that there is new data.
User B receives the C2DM notification of new data, connects to your app server and retrieves the message from User A.
This mechanism only pushes data, there is no polling.
Related
My clients are Android devices. A client wants to send some info to another client which will first be sent to the app server and then the server will notify a middleware service(some kind of message broker) which will be responsible for sending the target client a push notification(to tell it to poll from the app server).
I want to know:
How will this middleware service identify which client device to notify?
more concretely, How does a push notification server locate which physical device to fire off the notification to?
My requirement is that the client should be able to obtain notifications even while using a VPN or proxy(similar to WhatsApp). Also, if the client is powered off then the middleware queues the messages and delivers them once the client power backs on again.
I have been looking at things like Firebase Cloud Messaging and MQTT brokers and stuff but I want to implement similar things on my own.
I want to implement this in Java.
Your client ( having an unique id and token ) will send the message to another client who also have a unique id and token in the database .. So the,
Server will map the receivers' id to the receivers token and send the notification to the receiver..
The database(backend) will have unique ids (maybe primary keys) against each client and also a unique token (for sending notification) against each client. So , when the sender-client sends the message , the backend script maps the receiver-client's (to whom the sender is sending) id to the receiver clients token. Then send the notification to the particular token.
If sender is sending apns notifications to user successfully and suddenly user sets device to air plane mode or do not disturb mode then how does the sender know if the device has got the notification or not.
Will Apns notify of success or failure to the sender.
----Update to above question below,
is there a way for IOS app to tell the sending java client about the notifications received, without the user's action of launching the app or clicking one the notification.
For e.g. user might be busy and the device may be idle. In such case if a notification arrives, is there a way or API/Method in IOS to send acknowledgement to the sender, that notification with 'someID' is reviced in notification tray.
Reason being, if someOne wants to charge for notifications sent to a device. if user does not recieve it than it may cause problems.
You need to understand the concept of APNS properly. Have a look at the docs to understand it better :) Though, lemme add some key info here to help you :)
There are few wrong assumptions you have about APNS :)
Mistake 1
"If sender is sending apns notifications to user successfully"
I believe by that statement, you mean user using an app sends a APNS to other user using APNS :)
Sorry :) iOS client applications dont directly talk with APNS to send push notifications :) Request to send a push notification might generate at iOS client app (like user types a text and clicks on send) App wont directly make a call to APNS and handover the payload to it :) There is another important entity playing a very important role in background that is your App Server
What happens when I send a text to other user using APNS??
Your application should gather user text and send it to your Application server :) Your Application server then establishes a two way hand shake with APNS :) Once successful it creates the payload in perticular format :) gets the device ID's to which it has to send the data and sends it to APNS finally APNS delivers it to client apps :)
Mistake 2
Will Apns notify of success or failure to the sender.
Apple documentations clearly says APNS is a best effort service :) Which means APNS will not take any guarantee of delivering every single request sent to it :) and does not provide any feedback regarding the successful delivery of packages at client end :)
All the requests that your Application server sends to APNS gets queued and gets delivered when APNS is free to process them :) If request-1 is yet to be processed and request-2 comes from your application server to APNS request-1 will be discarded and request-2 will be processed :)
How to deal with this kind of situations then ?
Once receiving the message your receiver iOS app should talk with your application server and inform that it has received the message/package :)
Assume user 1 sends 2 message :) lets say message1 and message 2 :) now your application server sends message1 to APNS hoping that it will deliver the message :) If APNS sends it to user 2, user 2's app should talk with your app server and say hey I got message 1 :) Now when user 1 sends message 2 your application server knows that no messages are pending to send to user 2 :)
If user 1 sends message 3 and user 2 does not receive anything from APNS when user 1 again sends message 4 and user 2 informs that he has recieved message 4 your application server should be able to identify that it has not recieved the feed back for messge 3 so it should re-send it again :)
There are 100 other ways to keep your Client and server in sync :)
TIP
If you are developing chat app depending on APNS is not feasible solution :) Hope I guided you atleast with the concept :) Happy coding all the best
I want to implement push notification for Android and IOS, we have our own app for android and ios from that app user can send various request and after request completion user will get notification by using push notification.
So my question is
1. How I can detect the device to which i need to send notification.
2. I am new to GCM so can somebody help me from how to start this.
3. Every where I have found GCM send RegId to server, so whenever request comes every time I need to generate RegId or I need to check whether that user is registered or not if not register it first and then sends notification.
Thank You.
You don't need to regenerate the Registration ID every time.
In simple terms:
Client registers with GCM and client gets a registration ID.
You need to store the registration ID in your server.
Your server will need to send a list of registration ids with message content to GCM. GCM will respond with a list of successful and unsucessful messages to
the server.
The push events that are successful will go to the corresponding device. Note that the push notification will only show if you have
code on the client that receives it in addition you need to have the
app installed.
The client and server code example on the documentation is easy to implement. Have fun :)
I am using the Google-GCM service for pushing notifications to a mobile device & building this application in Java EE.
I'm perfectly able to push notifications to the mobile device. And from the client-end (mobile) I'm able to receive input(string).
Henceforth my conceptual question starts: When I'm receiving input from a mobile (let's say: "Hello, Server"), I'm trying to build an automated process on the server-side and in reply it will push a notification (let's say: "Hi client, I'm fine; How are you?") automatically.
I want to grab some idea to push the notification automatically whenever the mobile device is registered. How do I do it?
All realistic implementations of GCM include a stage where an app receives a RegID, and communicates the RegID back to the server, typically via an HTTP service, typically along with some other business specific data. The server would store the RegID, associating it with other data, and later use it to send messages.
Have you implemented automated the delivery of the GCM registration ID to the server yet? If so, in the same piece of code, you might as well push a notification back. If not, do put together some. Server-side implementation would depend on your server's platform, naturally.
I am familiar in using xmpp library,for android i'm using asmack library.In Google chat also asmack is used.i can write an application to send/receive messages using xmpp.But now i want to track google chat messages in my application.what ever the user do in google chat the same sholud be happening in my application.Suppose that user logged in google chat,in my appication also he is logged in.Sent messages /Incomming messages also should be in sync.i m able to do every thing except synchronizing outgoing sms.How to capture the packet when user is send a message from google chat into my application. ?
You should not be able to do that (unless rooted) as it would be security issue - anyone could sniff your any network activity that way. If your app sign in to the google talk server (as any other client) then you should receive copies of all the conversations, but that's it.