views:

23678

answers:

11

I recently learned about the ability of iPhone apps to receive nearly instantaneous notifications to apps.

This is provided in the form of push notifications, a bespoke protocol which keeps an always on data connection to the iPhone and messages binary packets to the app, which pops up alerts incredibly quickly, between 0.5 - 5 seconds from server app send to phone app response time. This is sent as data - rather than SMS - in very very small packets charged as part of the data plan not as incoming messages.

I would like to know if using Android there is either a similar facility, or whether it's possible to implement something close to this using Android APIs. To clarify I define similar as:

  • Not an SMS message, but some data driven solution
  • As real time as is possible
  • Is scalable - ie: as the server part of a mobile app, I could notify thousands of app instances in seconds

I appreciate the app could be pull based, HTTP request/response style, but ideally I don't want to to be polling that heavily just to check for notification .. besides which it's like drip draining the data plan.

+1  A: 

I cannot find where I read it at, but I believe gmail utilizes an open TCP connection to do the e-mail push.

Will
There is a blog post at http://joelapenna.com/blog/2009/07/android-foursquare-and-push by a developer of an Android app that seems to support this.
dalelane
These seem to me, they are polling too. The mobile device makes a connection to the server and notifies the server it's waiting for updates. Actual push is initiated by the server, which is very difficult for mobile devices, and most of the time involves network provider support (sms/wap push)...
MrSnowflake
"C2DM allows third-party developers to use the same service the Google apps do." from Android Cloud To Device Messaging
colithium
+2  A: 

If you can depend on the Google libraries being there for you target market, then you may want to piggy back on GTalk functionality (registering a resource on the existing username - the intercepting it the messages as they come in with a BroadcastReceiver).

If not, and I expect you can't, then you're into bundling your own versions of XMPP. This is a pain, but may be made easier if XMPP is bundled separately as a standalone library.

You may also consider PubSubHubub, but I have no idea the network usage of it. I believe it is built atop of XMPP.

jamesh
I think the article stats that the piggy back functionality will be always be available as long as the gtalk libraries are on the device. Do you have some resources with examples how to actually do that?
Janusz
GTalk is removed from the SDK since 1.0 (iirc).
MrSnowflake
+6  A: 

I recently started playing with MQTT http://mqtt.org for Android as a way of doing what you're asking for (i.e. not SMS but data driven, almost immediate message delivery, scalable, 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
How is mqtt doing this? There must be some polling involved somewhere? Even apple has to poll but I think they are only doing one connection at a time therefore not draining the battery that much...
Janusz
+2  A: 

I have been looking into this and PubSubHubBub recommended by jamesh is not an option. PubSubHubBub is intended for server to server communications

"I'm behind a NAT. Can I subscribe to a Hub? The hub can't connect to me."

/Anonymous

No, PSHB is a server-to-server protocol. If you're behind NAT, you're not really a server. While we've kicked around ideas for optional PSHB extensions to do hanging gets ("long polling") and/or messagebox polling for such clients, it's not in the core spec. The core spec is server-to-server only.

/Brad Fitzpatrick, San Francisco, CA

Source: http://moderator.appspot.com/#15/e=43e1a&t=426ac&f=b0c2d (direct link not possible)

I've come to the conclusion that the simplest method is to use Comet HTTP push. This is both a simple and well understood solution but it can also be re-used for web applications.

morganchristiansson
+4  A: 

Have a look at the Xtify platform. Looks like this is what they are doing,

peter
http://www.xtify.com/features
j pimmel
+1  A: 

As GTalk is gone from the SDK, it might be a good idea to make a 'standard' push messaging system. That way, only one service has to run, only one extra tcp connection needs to be open. Applications should talk to this service using Intents and should first request permission to send and receive notification from the service. The service should then notify the user a new application wants to send and receive messages. The user will then grant or deny permission, so he stays in control. The application will then register an action + category to the service, so the service knows how to deliver the pushed message.

Would the a good idea or not?

MrSnowflake
+1  A: 

Why dont you go with the XMPP implementation. right now there are so many public servers available including gtalk, jabber, citadel etc. For Android there is one SDK is also available named as SMACK. This we cant say a push notification but using the XMPP you can keep a connection open between client and server which will allow a two way communication. Means Android client and server both can communicate to each other. At present this will fulfill the need of Push in android. I have implemented a sample code and it really works great

Rahul Patel
Care to provide a link to your sample code? Done any testing regarding battery life?
Alex
+1  A: 

There is a new open-source effort to develop a Java library for push notifications on Android, using the Meteor comet server as a backend. You can check it out at the Deacon Project Blog. We need developers, so please spread the word!

medicdave
+5  A: 

I wrote a blog post about how to implement push notifications for Android using MQTT protocol. I have sample code available and a live demo. Have a look: http://tokudu.com/2010/how-to-implement-push-notifications-for-android/

Anton L
+19  A: 

Today for Android 2.2 and above, Google announced Cloud To Device Messaging

j pimmel
Google provides detailed documentation for implementing this into your Android app in Java at http://code.google.com/android/c2dm/ but 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
+1  A: 

I have recently developed http://pushdroid.org its a single application that should be installed on the phone just like google has implemented it in 2.2 this works from 1.5 and is broadcasting via intent.

Stefan