androidxmppsmackasmackgoogle-talk

How to notify the user about received GTalk chats when the app is not running


I implemented a chat client using GTalk servers and (a)Smack library. So far so good. Now, what I can't wrap my head around is how to notify the user of received chats when the app is closed, the same way all other chat apps do. I was reading into push notifications but all examples I find have a server component as well, which I obviously don't since my app is just a client for GTalk.

Should I be using GCM and implement the server side for this? Should I instead attempt to start a service that will listen for incoming messages at boot time (similar to this example)?


Solution

  • Service is definitely the way to go, you can keep it running so that your XMPP connection remains open.

    From the server you can receive the messages and through a Broadcast Receiver you can show your notification if the app is closed, when it's opened you disable the previous Broadcast Receiver and you register a new one to manage messages in your activity for example.

    This is pretty much my implementation.

    Thumbs up appreciated!

    Enjoy