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.

google glass hello world program

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.

android installing google glass 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.

<?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.androidhive.info</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

<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.

package info.androidhive.helloglass;

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 program

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" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.androidhive.helloglass"
    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="info.androidhive.helloglass.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
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info
  • Jay Donga

    Awesome tutorial for getting started with Glass Development. I’m waiting for your other tutorials on wearable development.

    • Yeah. I am ordering watch too. Let’s see how it goes 🙂

  • Guest

    Awesome tutorial! Although currently I don’t have Google Glass, I’m very interested to see your next tutorial.. 😀

  • Steve

    Awesome Tutorial as usual!! I just purchased a Moto 360 and now I am search the web for some Android Wear tutorials. Not much out there yet, but I am excited to see what you have in store for us.

  • Xan

    I’m crazy about android wear apps & i wanna purchase Google Glasses, can you please guide me?

    • Just for the information, Google glass and android wear both are different things!

  • Ismail

    Thanks you Mr Ravi for this awesome tutorial. Although i don’t have Google glass.but I’m still interested in android wear and glass.

  • We are waiting for a giveaway contest.

  • Ramiro Madriaga

    Great. I hove buy one soon. Thanks ravi.

  • mayank

    when will you deploy tutorial for android wear watch……i have installed and connected with that but not being able to write a code in it so…hoping soon.

  • Aryan Gaikwad

    I don’t have a Google Glass. Can I run it on a emulator?

  • bhavna

    i want to create a ribbon menu in my app like the one which is present in gmail’s app..can you tell me the code.

  • sungan

    Thanks for amazing tutorial .. I am purchasing one glass and trying to run a sample code, but i cant see “Google USB driver” under extras.. need help 🙁

    • sungan

      and one more thing. I know i should specify minimum API as 19, but my glass API is 15.. is there any way to upgrade it?

  • Rob LaPointe

    Interesting but the annoying thing is that I can’t use emulator as of now! Is there a any other way yo step forward with google glass app development goo.gl/jfftmY, also clear me is it different from other wearable app development? What do you think about app UI designs are they tougher or easier to accomplish?