Getting Started With Google Glass Development




Today I am very excited to write my first Google Glass tutorial. This is the first article on android wearable devices which is a simple Hello World app. Going forward I’ll cover other android wearables like watches.
I know that Google Glass is very expensive and not everybody afford to have one. But I am sure the price will comedown once the glass is stable and more popular.
As of today there is no official glass emulator to test the apps. But you can try out these options discussed in this forum.
If you are really serious about building apps for glass, you can order it from PlayStore.



The following steps will take you through various stages of glass development like downloading GDK, installing drivers, writing a simple hello world program and deploying the same on glass.

1. Downloading GDK (Glass Development Kit)

Glass Development Kit provides APIs to build glassware applications. These APIs won’t be available in all the versions of android.
1 Open SDK manager from your android’s SDK folder.
2 Select Android 4.2.2 (API 19), Google USB Driver (under Extras) and click on Install Packages. This takes a while to download all the packages.

 Google Glass Installing GDK



2. Installing Google Glass Drivers

Android device drivers can be installed either from android SDK’s google usb drivers or with the software that comes from device manufacturer. For Google Glass we can directly use google usb driver. But before installing we need to do a modification in android_winusb.inf, otherwise, your glass device won’t be listed in Eclipse even though you have installed the drivers correctly.
1. Goto your android_SDK_folder\sdk\extras\google\usb_driver and edit android_winusb.inf. Add the below text at the end of the file.


[Google.NTamd64]
;GoogleGlass
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_4E11&REV_0216
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_4E11&MI_01
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_9001&REV_0216
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_9001&MI_01
[Google.NTx86]
;GoogleGlass
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_4E11&REV_0216
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_4E11&MI_01
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_9001&REV_0216
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_9001&MI_01



2. Now open Run (shortcut Win + R) and type devmgmt.msc and press ok. This opens up Device Manager window.
3. In device manager right click on your Google Glass device and click install drivers. When it ask for browse location, select android_winusb.inf parent folder and follow the instructions.
Following links will help you if you got into any issue.
Google USB Driver
Installing USB Driver
Stackoverflow Discussion




3. Creating new Glass Project

Creating a glass project is same as usual android project, but it differs in choosing proper API version.
1. Create a new project in Eclipse. File ⇒ New ⇒ Android Application Project and give application name, project name and package.
2. Set Minimum Required SDK and Target SDK to API 19: Android 4.4 (KitKat), Compile With to Glass Development Kit Sneak Peek (Google Inc.) (API19) and select the Theme to None
3. Once the project is created open AndroidManifest.xml file and remove the theme android:theme property. By removing this property, glass will apply it’s own theme.
4. Open strings.xml and add below string values.


 

String.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
     
    <string name="app_name">Hello Glass</string>
    <string name="action_settings">Settings</string>
     
    <!-- main activity strings -->
    <string name="hello_glass">Hello Glass !</string>
    <string name="home_url">www.hemanthsomaraju.blogspot.in</string>

     
    <!-- "ok glass" voice command -->
    <string name="start_command">Hello Glass</string>   
</resources>


5. Now open your main activity layout file and paste the following code. In my case my activity layout is activity_main.xml

activity_main.xml
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_glass" />
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/home_url"
        android:textSize="20dp" />
   
</LinearLayout>

 6. I haven’t modified anything in MainActivity.java. Your main activity should look like below.

MainActivity.java
 
package com.gudivada.hemanthsomaraju;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
Until now we are done with simple hello world program. In the next step we’ll learn how to deploy the app on the glass device.

4. Running the application on Glass

7. In order to deploy the app on Glass we need to turn on debug option. So on your glass go to Settings ⇒ Device Info ⇒ Turn on debug.
8. Now connect the Glass to your PC using a USB cable. Right click on the project and Run As ⇒ Android Application. Eclipse will list the glass in the list of devices available. Select the glass device and press ok. You should able see the app running on your glass.

 Google Glass Hello World





Now you have successfully developed your first Hello Glass application. But if you close the app or glass goes to sleep, you can’t find the app again anywhere on glass.
In the next step we’ll learn how to add our app to “Ok Glass” menu. So that we can launch our app using a voice command like other glass apps.

5. Adding our app to “Ok Glass” menu

9. Download app_icon.png and paste it in res ⇒ drawable folder. As per glass guidelines, app icon should be 50x50px with white foreground and transparent background.
10. Create a new folder named xml under res folder.
11. Inside res ⇒ xml folder create an xml file named voice_trigger_start.xml.
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/start_command" />
12. Now add DEVELOPMENT permission in the AndroidManifest.xml which allows us to use unlisted glass voice commands.
Also we need to modify the intent-filter and a meta-data tag for the main activity by adding VOICE_TRIGGER properties.

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
AndroidManifest.xml
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gudivada.hemanthsomaraju"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="15" />
    <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name" >
        <activity
            android:name="com.gudivada.hemanthsomaraju.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
            </intent-filter>
            <meta-data
                android:name="com.google.android.glass.VoiceTrigger"
                android:resource="@xml/voice_trigger_start" />
        </activity>
    </application>
</manifest>
Now deploy the app once again on the glass. This time app won’t be launched automatically. You have to launch the app by saying Ok Glass Hello Glass command.


 Google Glass - Ok Glass Menu