Google Glass is cool and you know it. I fell in love with it the first time I tried it, although I think it's a bit over-hyped. You can read more about my thoughts on Glass here.
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.
I plan to add some more API calls to this project soon, but I'm sure you can implement most of them for yourself. Again, authorization is the "hard" part here, in my opinion.
Just make sure you don't create a porn Glass app... ;)
No comments:
Post a Comment