views:

8510

answers:

9

I am looking to write an app which received pushed alerts from a server. I found a couple of methods to do this.

  1. SMS - Intercept the incoming SMS and initiate a pull from the server
  2. Poll the server periodically

Each has its own limitations. SMS- no guarantee on arrival time. Poll may drain the battery.

Do you have a better suggestion please?. Thanks much.

+2  A: 

I'm afraid you've found both possible methods. Google was, at least initially, going to implement a GChat api you could use for a push/pull implementation. Sadly, that library was cut by Android 1.0.

haseman
They've promised to bring it back once the security problems get worked out... if that ever happens.
fiXedd
+6  A: 

or....

3) Keep a connection to the server, send keep-alives every few minutes, and the server can push messages instantly. This is how Gmail, Google Talk, etc. works.

Isaac Waller
I think this will, sadly, produce a hefty amount of battery drain. IF you take this route, make sure to limit the amount of time you do this.
haseman
No, actually, it won't, because idle TCP/IP connections take almost no power on the cell modem.
Isaac Waller
Actually, it will take a lot over time, so you are right. Sending keep-alives with long intervals helps a lot too.
Isaac Waller
Ah! I'm confused, am I wrong or am I right? ;-)
haseman
You're right, it was my mistake.
Isaac Waller
What are "long intervals" in this regard? I know gmail push works like this but I don't know what timeout intervals they use.
tobsen
+9  A: 

(cross-posting from an answer I gave to a similar question - http://stackoverflow.com/questions/1243066/does-android-support-near-real-time-push-notification/ )

I recently started playing with MQTT http://mqtt.org for Android as a way of doing this sort of thing (i.e. push notification that is not SMS but data driven, almost immediate message delivery, not polling, etc.)

I have a blog post with background information on this in case it's helpful

http://dalelane.co.uk/blog/?p=938

(Note: MQTT is an IBM technology, and I should point out that I work for IBM.)

dalelane
Thank you that was very useful
Vinod
Hi Dale,I read your blog post about MQTT and it definitely seems to fit the bill for almost instant notification on mobiles. But I haven't been able to find any information about how it actually does it. Does it keep a socket open at all times? How does it notify the server if its ip address has changed? Would appreciate it if you could shed some light on this.CheersNaren
Naren
dalelane
No, I had not come across that post of yours. Answered a lot of my questions. Thank you very much :)
Naren
+1  A: 

Hi. I dont know if this is still useful. I achieved something like this with a java library at http://www.pushlets.com/

Althoug doing it in a service won't prevent android from shutting it down an killing the listener thread.

gabe
+3  A: 

You can use Xtify (http://developer.xtify.com) - they have a push notifications webservice that works with their SDK. it's free and so far, it's worked really well for me.

peter
I got a response from their VP saying that there's no plans on ever charging for the push service. It's quite an amazing SDK.
Crowe T. Robot
+4  A: 

There is a new open-source effort to develop a Java library for push notifications on Android based on the Meteor web server. You can check it out at the Deacon Project Blog, where you'll find links to Meteor and the project's GitHub repository. We need developers, so please spread the word!

medicdave
+7  A: 

Hi all, I've expanded on Dale Lane's idea mentioned above of using MQTT for push notifications. You can read about it on my blog:

http://tokudu.com/2010/how-to-implement-push-notifications-for-android/

There is some sample code available and a live demo. Enjoy!

Anton L
+1... thanks Anton....it is really good....I just have one question, can php server script be replaced by servlet jsp...
Vijay C
yes! it should be pretty easy. You can reuse the same MQTT jar that I include into the Android app.
Anton L
A: 

pubsub model may be an alternative http://code.google.com/p/pubsubhubbub/

Manu Subramanian
+7  A: 

Google's official answer is the Android Cloud to Device Messaging Framework

It will work on Android >= 2.2 (on phones that have the Market app).

BoD
it's in beta right now, but you can sign up in hopes of being activated.
brack
You can generally get activated very quickly, and it is being used for things like GMail so is know to work in production. Unfortunately their sample code for communicating with the server side aspect of C2DM is lacking. I've written up a tutorial for that aspect here http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/
DavidM