user1130149
user1130149

Reputation: 21

Setting up Android C2DM App Server

I've built an android application [a knowledge exchange forum, inspired by none other than stackoverflow :) ] that communicates with a remote (free) server. As of now, the application fetches/refreshes content on user demand.

I'd like to implement push notifications, so that a user can be notified when someone posts an answer to his/her question. I've heard that C2DM is a good push notification service for Android devices. The client code I can perhaps take care of, it's the server side programming that has me completely baffled. I don't even know where to start.

The capabilities of the server as listed are CGI, PHP, ASP.NET, SSI, FrontPage Extensions, Perl and Python. I'm currently using PHP scripts to run SQL queries on a MySQL database and transmit data to the client (android device). What feature(s) of the server must I use to implement C2DM? Is it even feasible with the given capabilities?

Push notifications would greatly enhance the functionality and usability of my application. I request you to provide guidance on setting up the server.

Thanks in advance for your response.

EDIT: A difference I've noticed is that while I'm using a WEB Server, http://code.google.com/android/c2dm/ constantly refers to a 3rd party APPLICATION server. Thoughts?

Upvotes: 2

Views: 2772

Answers (3)

Jan
Jan

Reputation: 1

It's very important that you have a low-level socket connection with the push server. Using PHP and mySQL can easily lead to performance issues and overlapping push requests. Cron jobs and launching shell scripts every x minutes should be avoided.

There are also hosted solutions which setup you up directly without having to bother for the serverside implementation, like: www.urbainairship.com and the XS2 push server, http://xs2technology.wordpress.com/2012/05/06/xs2-push-notification-platform_a-hosted-solution/

Upvotes: 0

prashant
prashant

Reputation: 3608

We have implemented C2DM push notification feature completely in java. In order to have the complete push ecosystem we did following

  1. Code changes on client side to get the registration key.

  2. Provide a service using which Android client application can send device registration key to our in house servers. We deployed a simple web service on tomcat which takes in registration key as post parameter. and then persist in the MySQL database.

  3. For sending push message we created a standalone java application, which reads the registration keys from MySQL and then makes a HTTP post request to Google c2dm server. Our application is multithreaded so that it can make multiple POST request to Google servers simultaneously.

Alternatively, you can also look at products such as urban air ship.

Upvotes: 1

Richard Green
Richard Green

Reputation: 2062

I use c2dm push messages via Python Google App Engine. You will need oauth to get your c2dm credentials authenticated into a token and then just http get to actually fire off the c2dm message to the c2dm servers...

This will convert your credentials into a key you can use:

def get_auth_key():
 mk = __name__+".authkey"
 form_fields = {
        "accountType": "HOSTED",
        "Email": constants.c2dm_email,
        "Passwd": constants.c2dm_pwd,
        "service":constants.c2dm_service, ## ( c2dm_service = "ac2dm" )
        "source": constants.c2dm_source,
    }
  form_data = urllib.urlencode(form_fields)
  result = urlfetch.fetch(url=constants.client_auth_url,
                            payload=form_data,
                            method=urlfetch.POST,
                            headers={'Content-Type': 'application/x-www-form-urlencoded'})

  d = dict()
  fields=result.content.split("\n")
  for r in fields:
        if "=" in r:
            (k,v)=r.split("=")
            d[k]=v
            logging.debug(result)           

  logging.debug("Not in memcache :-(" )
  auth = d["Auth"]
  logging.debug("Now got key %s " % auth)
  memcache.set(mk,auth)
  return auth

Then just use that with the c2dm key you got from the Android client registration and you're all good... (please excuse the app engine logging / memcache stuff).

Upvotes: 2

Related Questions