Making a Google Glass app with C# on Xamarin: PTVGlass

Missing the train by just a minute is mildly frustrating. Every time I see the train roll away from the platform as I walk towards the station makes me wonder what if I had walked a little bit faster or paced up the escalator. (This dilemma keeps me up at night)

Of course there are plenty of cool mobile apps with public transport timetables but pulling out a phone and fiddling about while I’m walking is more trouble than its worth.

After two nights of hacking, I can now access Melbourne’s bus, train and tram timetables while I’m walking to the station with voice and geolocation, thanks to my Google Glass app PTVGlass! I’ll be the Glasshole shouting “trams near me” in the city.

ptvglass

20140326_182408_638_x

Download the source code

I’m making the Xamarin/C# source code freely available on GitHub along with the Glass APK for sideloading.

Unfortunately I know the number of Google Glass Explorers in Melbourne will be in the single digits so this app has very little commercial value. I’m hoping someone can critique my code or be inspired to create more Google Glass apps.

Falling in love with Xamarin

A couple of weeks ago, the state government agency Public Transport Victoria released the first version of their Timetable API. I knew I just had to make an app for Google Glass. Except one problem, I didn’t know Java or how to write Android apps.

Unlike my previous Google Glass apps using the Mirror API which allows web developers to develop apps in the form of Glass push notifications, this particular scenario required a native GDK app which could be initiated through voice and menu commands.

I tried a good effort to quickly get my head around Android development, but the tooling and documentation was simply sub-par compared to C# and .NET development. I’m sure the Glass Development Kit would be a piece of cake for any Android developer but learning Java, Android and the GDK all at once was just too much.

In an amazing coincidence, around the same time rumors of Microsoft acquiring Xamarin floated. I wasn’t entirely familiar with the Xamarin product at the time, but my eyes opened when I saw they supported developing for Google Glass using C# and Visual Studio piqued my interest.

Even as a C# noob, I could appreciate the straightforwardness of C#. (Objective-C makes me want to cry.)

Android Screen Monitor (28)

Although I was skeptical of Xamarin Studio at first, I’m pleasantly surprised by the capabilities of the tooling. It was like Visual Studio Lite. Intellisense for the full Android SDK, multi-threaded breakpoints, variable explorers and integrated device deploys and debugging.

ptvglass debug

I have to admit the only weak aspect of developing with Xamarin is the documentation. Xamarin tries its best in its developer guides to provide an overview of the fundamentals in C#, but this is obviously no match to the official documentation in the native language. Surprisingly though StackOverflow was quite saturated with Xamarin questions and answers which helped with the small quirks here and there.

Unfortunately the current Xamarin licensing cost (upwards from $299 to $999 a year) would scare off most hobbyist developers. If the rumors of Microsoft’s acquisition are true, I certainly look forward to Microsoft opening up access for this amazing technology and tools to more developers via MSDN and the Visual Studio Express programs.

Microsoft already has the best developer tools on Windows. Now imagine if their tools were also the best in class for the competing but dominant mobile platforms.

8 insightful thoughts

  1. I recently brought a cheap Moto G phone thinking it would be neat to try my hand at Android stuff. But like you I am a noob with C# and love how readable it is with clean syntax which is easy to understand.

    We have considered porting one of our Windows Phone apps over to Android, and looked toward Xamarin. It is simply far too expensive a proposition for any officially release for an app.

    I hold out hope that Microsoft purchase them and integrate it into Visual Studio Pro which I have access to through University, and which the other developers I work with have through msdn subscriptions.

  2. Just a quick question – how did you get access to glass being in Australia? I thought it was USA only? Very jealous!

    1. Get a friend to buy it with a US credit card, ship it to them, then get them to ship it to you 🙂

  3. I think Xamarin has good future once the documentation does improve…. which is getting better. We are using titanium and corona right now. But we are looking for other options.

  4. Hey Long Zheng, I’m trying to make a Google Glass app using Xamarin and I’m using your app as a frame of reference. One question: With the ListView that shows the station stops, is there any way to make those voice activated? For example if you have a stop at a Philadelphia Train Station that is listed you can say “Philadelphia Stop” and then you enter another screen with more details about the stop. Just wondering if it’s possible because I’m planning on implementing a feature like this in my App.

Comments are closed.