SignalR client on Mono for Android

While SignalR is a great library for push notifications it has one “flaw”. There is no included Android client implementation currently, and by Android I mean Mono For Android. Luckily SignalR is an open source project and I decided to see how hard is to make it Mono For Android compatible. It turns out that it is pretty simple.

Here is the recipe (tested on Mono For Android 4.0.x):

  • SignalR depends on Newtonsoft.Json library (free, open source) developed by James Newton-King. Again, there is no Android port included with the original library but there is a port that works fine on Mono For Android. Get it here.
  • Get SignalR client sources. Create new Mono For Android class library and import all (WindowsPhone version of the project) files. Add WINDOWS_PHONE conditional compilation symbol to Project Properties/Build. Then reference the Newtonsoft.Json libary.
  • Mono For Android is currently missing TaskExtensions class required for unwrapping tasks. Get the sources for this class here. I assume it will appear in Mono For Android sooner or later. Add this class to the library and add proper using statements if/where necessary.

That’s it. You are now ready to receive SignalR push notifications.

Here is how you create a PersistentConnection (server part), and here is client code (that runs fine on Mono For Android).

Download the libraries and sources below (1.40 mb)