Sunday, 15 July 2012

GCM Push Notifications for Android


Push notifications are officially awesome for real time multiplayer gaming. If your server has no other players, you can't really have a game. With push notifications however, you can register your interest in playing, and whenever someone logs in, you can immediately be told and be able to log right in and play against them.

Some of the quirks of getting push notifications on Android were.
  • Including the gcm.jar file compiled but always gave me a class not found run time error.
    • To solve, I included the source files provided in gcm-client instead.

  • GCMIntentService must be put in the same class package as your application package. (I tend to re-use a lot of my code between projects, so I have a generic class package name with different application package names).


Apart from that, everything seemed to pretty much work well.

Some good material to get your head around is the Google I/O 2012 talk and the documentation.

If you're doing push messaging with NodeJS and have any problems, let me know and I'll try to help. If you hate server side development, you can always give Parse a try.

3 comments:

  1. This might help with the classpath problem:
    http://stackoverflow.com/questions/2247998/noclassdeffounderror-eclipse-and-android/9916751#9916751

    => rename "lib" to "libs"

    Seems to be an issue with the ADT.

    ReplyDelete
  2. That's it! If you're on SDK 18+, you need to move all your jars into the root of the libs folder.
    Grr.

    ReplyDelete