Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instant Messaging on Android with Google Cloud Messaging

I was just looking at the new Google Cloud Messaging (GCM) and I was wondering if it is possible to use GCM for Instant Messaging on your Android application?

I saw you can send data, like a message, from a server, but is it also possible to send from one device to another one? And how would this work? Some example code would be really helpful..

Tnx!

like image 579
dumazy Avatar asked Jul 06 '12 19:07

dumazy


People also ask

How does Google Cloud Messaging work?

PRO TIP: Google Cloud Messaging for Android (GCM) is a service that allows developers to send data from their servers to their users' devices, and vice versa. GCM is completely free, and you can use it to send or receive any data, up to 4kb in size. You can then add recipients, recipients' addresses, and messages.

What is the difference between Cloud Messaging and in app messaging?

What is the difference between cloud messaging and in-app messaging? Cloud messaging is simply sending messages from one platform to another. In other words, it is a cross-platform messaging method. In-app messaging, on the other hand, is sending messages to your users on your own app.


2 Answers

The official docs on Google Cloud Messaging for Android does mention that GCM can be used to develop an instant messaging app.

...or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly).

So we went ahead and created an instant messaging app using GCM. The server-side is powered by Google App Engine. You can read the complete tutorial here. Create an Instant Messaging app using Google Cloud Messaging (GCM)

So it is possible to use GCM for Instant Messaging on Android, to answer your question. However, reliability of GCM compared to XMPP for IM is another topic.

like image 124
appsroxcom Avatar answered Oct 12 '22 01:10

appsroxcom


Just my two cents:

I think you should not use GCM for delivering IM. You should have a dedicated server where your Android IM apps will connect to, using a persistent socket connection. Your server will know who is online or not and therefore can present an 'online list' to all the apps.

GCM can come into play, while users are offline or not running your app. A GCM message can be sent to them to indicate 'XXXX wants to chat'. They can then launch your app and automatically connects to a chat session.

Google has said that the delivery of GCM messages are not guaranteed. This reason alone is not a good idea to rely on them for Instant Messaging.

like image 31
azgolfer Avatar answered Oct 12 '22 01:10

azgolfer