Google Glass Development Without Glass
Technologies emerge. Extremely. Wearable trend takes over the world. It seems like every week we start with articles about brand new devices, which would change our life! We’ve heard about lots of glasses, watches, wristbands, you name it. The most popular one is definitely Google Glass. Actually, it is Glass, who started this wearable hype!
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.
Glass is different from the regular phone or tablet. The usual way of creating Android apps is through the Android SDK. Because of specific Glass’s usage principles, Google introduced Mirror API. We’ll dive into both of them later in the post.
1. Obtaining 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:
- 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
Let’s dive into Glass development with the help of our friend Mr. Bond. James Bond.
2. Example #1: Mirror API
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:
- Populate request fields with values from the API.
- Execute request!
- Here’s a link with some pre-populated data.
Now it’s time to have even more fun! Let’s try setting up demo-project.
- Set up a new project in https://code.google.com/apis/console
- Go to API Access, update project settings:
- Add to Redirect URIs:
- https://mirror-api-playground.appspot.com (will be useful later)
- Add to Redirect URIs:
- 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.
If everything goes smooth, you’ll be able to authorize and have fun with your Glass Timeline! If you want to have even more fun with Mirror API, especially with Subscriptions to Location and Notifications, you should deploy your war to the real webserver. Google sends these updates only to https secured web-sites. For development purposes you can use provided ssl-proxy. Just modify MirrorClient#insertSubscription method.
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 640×360 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!
It’s a good idea to check out Google Glass Quick Start by Google. It explains a lot about Timeline, UI, Gestures and current limitations of the GDK.
|Swipe left||KEYCODE_TAB + isShiftPressed()|
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.