Anyway, I was motivated to be among the first to develop apps for Glass, but I was surprised that there's no library for Android (or non-web applications at all). There's only an AppEngine app, but that doesn't help when you want your Android app to communicate with Google Glass (without a server in-between). Thankfully, the Glass API is simply about making some REST-calls here and there... However, authorizing your requests isn't that easy, because you have to do the good old OAuth-dance.
Based on my previous blog post "Google OAuth on Android using AccountManager" and the samples provided by Google, I created an Android app which 1. handles the authentication and authorization and 2. is able to make one of the two most important calls to the Glass API: getting the timeline and posting a new card to the timeline. Basically it only comes down to two or three classes, but just to make sure everybody - from beginners to experts - is able to develop for Glass, I've uploaded the whole project to GitHub, instead of a few snippets.
If you want to learn more about the authorization-process, head over to the blog post mentioned above. The important thing is the scope: https://www.googleapis.com/auth/glass.timeline
Subsequent calls go to https://www.googleapis.com/mirror/v1/timeline and friends.
You can find the project here: https://github.com/TomTasche/glassinator
The threading-solution is pretty ugly at the moment, but it was the easiest I could come up with in a few minutes. Maybe I should give the new networking library from Google (Volley) a try, but then I think it's quite a bit overkill to include another library just for some HTTP requests. Please tell me if you have any suggestions.

Just make sure you don't create a porn Glass app... ;)
No comments:
Post a Comment