I am conceptualizing an Android app that sends data from one device to another (like a picture message), but because I do not have a server, I am looking into other ways of messaging. Google Cloud Messaging (GCM) seems like a good choice, since its made for Android, and is free to use, but it still requires a server to use. Is there a way around this requirement- such as running the GCM server on the app itself? Or is there a better approach to serverless messaging on Android?
Asked
Active
Viewed 4,867 times
7
-
Buy a Raspberry Pi for £25 (plus another 25 or so for PSU, cables etc) - run your own little dedicated GCM server. Put Apache, PHP, MySql on it and leave it on all the time, it only uses about 3 Watts. – NickT Nov 22 '12 at 19:52
-
2Probably cheaper to just set up a server on Heroku or AWS or something. – twaddington Nov 22 '12 at 20:48
-
SignalR is also a way? No need dedicated server, just a PC work like a server :) – BNK Sep 06 '15 at 08:05
2 Answers
3
Yes you can - it's possible to send the same messages from a device that would be sent from a server. However, this has the following problems:
- You're putting your API key in your app, so somebody could decompile your APK to get it.
- Your users would need some way to share their GCM registration IDs with each other. If two users had both their IDs expire at the same time, there would be no way to share them again.
Really, building your app and hosting it on AppEngine would take about an hour to write, and cost less than $10 a month, even for a ton of users.
For a dead-simple messaging server example written in Java, check out the server backing one of my apps:

Charles Munger
- 1,417
- 12
- 11
-
http://developer.android.com/google/gcm/server.html#choose "Note that Google AppEngine does not support connections to CCS", it will work only with HTTP which supports cloud-to-device only. – Henrique de Sousa Jan 24 '14 at 15:07
1
I think that will be hard to do what you want effectively without a server but you can check out Parse's SDK. It is free to try and free up to a certain monthly limit.
The docs. You may want to read "Sending Pushes to Channels" and "Using Advanced Targeting".

irwinb
- 993
- 2
- 10
- 20
-
-
2Note that Parse uses a [proprietary long-polling connection](http://parse.com/questions/gcm-support) -- it does not use GCM. One benefit of this is that it will work on devices like the Kindle Fire. However, this also makes it less efficient, as it does not benefit from using the shared Google Services connection. [AirBop](http://www.airbop.com) is another Android-specific push notification service that does use GCM, which makes it more battery and network friendly, however it also means it only works on devices where the Google services such as Gmail and Play are enabled. – Lorne Laliberte Dec 04 '12 at 22:11