Here are the slides of my "Google Glass Development without Glass" presentation. As I promised, here is the follow-up blogpost with some code samples. If you haven't seen my presentation, I strongly suggest clicking through the slides!
0.Intro
You can just imagine, how all the wearbles can impact our daily and extreme activities. Check out, how we imagined that at eleks: https://glass.eleks.com/
From the other point of view, each new device brings new UX, SDKs and APIs. That's why we, developers, have to quickly adopt to the new techs. In this sense, Google Glass is a rather good device for developers. It runs the world-known Android OS. It just has an extremely strange UI and UX.
Google created a set of "best practices" of awesome Glassware. Actually, it can be applied to any wearble software:
- Design for device -- know & test your device and it's abilities.
- Don't get in the way -- show the best data when users want it and be out of the way when they don't.
- Keep it timely -- platform is the most effective when in-the-moment and up-to-date.
- Avoid the unexpected -- surprising users with unexpected functionality is bad. On any platform.
1. Obtaining Glass
If you are among those 10000 people, who have Glass, you can skip this chapter. Unfortunately, that's just 0.000002% of the world's population. So, welcome Stranger to this amazing world of Glass hacking without Glass.
Hopefully, you have some Android device. Then, you can install Google Glass UI there (disclaimer: I've tried this with Nexus 7 tablet with 4.2.2 rom and it worked perfectly, but I can't guarantee it will work on other device). In short, Google Glass UI is just another Home screen provider for your Android. In order to set it up, follow these steps:
Hopefully, you have some Android device. Then, you can install Google Glass UI there (disclaimer: I've tried this with Nexus 7 tablet with 4.2.2 rom and it worked perfectly, but I can't guarantee it will work on other device). In short, Google Glass UI is just another Home screen provider for your Android. In order to set it up, follow these steps:
- Go to: https://github.com/zhuowei/Xenologer
- Download Glass APKs: https://github.com/zhuowei/Xenologer#install
- Install them as you usually install APKs from third-parties
- Follow steps at http://imgur.com/a/IBqFf to set up your "Nexus Glass"
- Say "ok glass, take a picture" and share your "woohoo-reaction" with the world #throughglass
You've obtained Glass. Now its time to hack!
Let's dive into Glass development with the help of our friend Mr. Bond. James Bond.
Let's dive into Glass development with the help of our friend Mr. Bond. James Bond.
Once upon a time, he was in London. Somehow, he's got his Google Glass and enjoys the experience on a daily basis.
2. Example #1: Mirror API
If you are eager to try Mirror API out and don't want to mess with quick-start projects, I have a shortcut for you!
Let's try inserting a simple card into Glass Timeline:
Let's try inserting a simple card into Glass Timeline:
- Go to: Google API Explorer --> Mirror API --> mirror.timeline.insert
- Authorise via OAuth 2.0. Use Glass scopes:
- https://www.googleapis.com/auth/glass.timeline
- https://www.googleapis.com/auth/glass.location
- Populate request fields with values from the API.
- Execute request!
- Here's a link with some pre-populated data.
- Set up a new project in https://code.google.com/apis/console
- Go to API Access, update project settings:
- Add to Redirect URIs:
- http://localhost:8080/oauth2callback
- Add to JavaScript origins:
- https://plusone.google.com
- http://localhost:8080
- https://mirror-api-playground.appspot.com (will be useful later)
- Clone https://github.com/googleglass/mirror-quickstart-java
- Update file src/main/resources/oauth.properties with the values provided in Google API Access Console.
- mvn jetty:run it.
3. Example #2: GDK
Update: Google recently released GDK Sneak Peak. Right now, when you try creating apps with it and running it on Nexus Glass, you'll get [INSTALL_FAILED_MISSING_SHARED_LIBRARY]. We're trying to find the way, to avoid that. As of now, there's no support for the official GDK Sneak Peak (auth, live cards, etc).
Google Glass is just another Android device with 640x360 screen (hello, screen fragmentation), Android 4.0.4, API level 15. Maybe, in the next releases of Glass, this will change. Now, when you want to port your existing Android app to Google Glass, you should just:
- Build your APK.
- Install it.
- Run via adb.
- Understand, that you need to update touch gestures support.
- Understand, that your UI is hardly usable.
- Understand, that your awesome Google Maps stopped working.
- So, double-check your application on real device! Everything can change in the near future!
In order to support touch gestures of Google Glass, have a look at this article: Touch Gestures. In short, here's the table with events corresponding to keycodes:
Tap | KEYCODE_DPAD_CENTER |
Swipe right | KEYCODE_TAB |
Swipe left | KEYCODE_TAB + isShiftPressed() |
Swipe down | KEYCODE_BACK |
Camera | KEYCODE_CAMERA |
4. Example #3: GDK + Timeline API
Update: Google released GDKvXE12 update. It has Static Card support, but it is still limited and lacks menus, html templates, etc. The code mentioned below follows hacky way and may not work on the latest version of Glass.So far, we've tried the official Mirror API way and the hacky GDK road. Now its time to combine both approaches. Let's insert a card into Timeline from withing your app!
I've set up a sample project at github for you: https://github.com/pif/ukrbash-for-glass. After you fork/clone it, you can see glasslib.jar inside libs folder. This library would probably become the aforementioned GDK. It provides everything you need to know about Timeline UI.
All the magic is done via these steps:
- Initialise Timeline, get Timeline contentresolver. Look at:
com.andrusiv.glass.bash.GlassService#onStartCommand(Intent, int, int). - Create MenuItems for your card.
- Create TimelineItem.
- Insert it into ContentResolver.
Look through the classes & methods provided inside glasslib.jar. I hope, you'll find loads of interesting information!
5. Outro
Thanks everyone, for reading all the way down here. I hope now you have your pseudo-Glass and know how to develop for it. Share your experience in the comments and on github! Ok guys, have fun #throughglass!
Hi Ostap!
ReplyDeleteI´d like to thank you about this post, I think it´s and extremely effort first to understand the technology and second to share it with the community.
I´d like though to ask you a couple of questions. After installing following the steps in the Xenologer process, I can get into google glass in my mobile.
However, when I try to execute your github code in eclipse and run it in the mobile, I get a dalvik conversion error followed by java heap space error.
I´m compiling and executing the project with the google glass SDK preview and target is 15.
I´ve also created another project where I´m suppose to create a Live Card. The error I´m getting is NoClassDefFoundError : com.google.android.glass.timeline.TimeLineManager
Any help will be welcome,
Thanks!
Hi luislukas!
ReplyDeleteThanks for the response.
>>I´m compiling and executing the project with the google glass SDK preview
If you want to run any code on it, you should compile with Android API 15 Runtime, not GDK Sneak Peak Runtime.
>>I´m suppose to create a Live Card...
>>I´m getting is NoClassDefFoundError...
As I have mentioned in "3. Example #2: GDK Update", you'll get [INSTALL_FAILED_MISSING_SHARED_LIBRARY] exception or similar, when running GDK examples on Nexus Glass: no support for GDK features (auth, livecards,etc).
Unfortunately, Xenologger APK are based on XE6-7. GDK Sneak Peak was released, when people were using XE11 version of Glass. So, there's no shared library with GDK support.
That's why Nexus Glass doesn't work with GDK Sneak Peak.
GDK Sneak Peak is still very limited. AFAIK, you can't post a static card from GDK to Timeline now.
Google said, they'll be opening new GDK features in following GDK releases.
Regards,
Ostap
Great article, thanks!
ReplyDeleteI am unable to use Camera. Can you please confirm Camera works fine when you say "ok glass, take a picture"?
ReplyDeleteYeap, it works.
DeleteThis comment has been removed by the author.
ReplyDeleteHi, I am trying to use Mirror API. i use the sample code and it gets compiled, but the Timeline on the emulator doesn't get updated. Even when I insert new cards nothing happens... Am I doing someting wrong ?
ReplyDeleteHi Siraj,
DeleteMake sure, that:
1. you see your device on google.com/myglass
2. you ask for these two permissions:
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location
Hope, that helps.