5

I would like to create some utility classes to use on both Android phones and on Google Glass (using the GDK). There are some differences to take care of when running on Glass (e.g. getting location).

Is there some static method call one can use or another way to determine whether the code is running on Glass?

2 Answers 2

4

Ok .. here is a method that one can use to determine whether code is running on Google Glass device (rolling up information from Jeff Tang):

/** Determine whethe the code is runnong on Google Glass
 * @return True if and only if Manufacturer is Google and Model begins with Glass
 */
public boolean isRunningOnGlass() {
    boolean result;

    result = "Google".equalsIgnoreCase(Build.MANUFACTURER) && Build.MODEL.startsWith("Glass");
    Log.d(getLocalClassName(), "Running on Glass = " + result + "Manufacturer is " + Build.MANUFACTURER + ", Model is " + Build.MODEL);

    return result;
}
0

Updated for XE 16:

try {
    Class.forName ("com.google.android.glass.timeline.TimelineManager");
    Log.v(">>>", "TimelineManager found");
}
catch (ClassNotFoundException e) {
    Log.v(">>>", "TimelineManager ClassNotFound");
}

try {
    Class.forName ("com.google.android.glass.timeline.LiveCard");
    Log.v(">>>", "LiveCard found");
}
catch (ClassNotFoundException e) {
    Log.v(">>>", "LiveCard ClassNotFound");
}


String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; 
Log.v(">>>", "Build: " + manufacturer + ", " + model);

will print on Glass:

04-26 08:00:49.616: V/>>>(1988): TimelineManager ClassNotFound
04-26 08:00:49.616: V/>>>(1988): LiveCard found
04-26 08:00:49.616: V/>>>(1988): Build: Google, Glass 1

and print on a Nexus tablet:

04-26 08:19:27.128: V/>>>(23528): TimelineManager ClassNotFound
04-26 08:19:27.128: V/>>>(23528): LiveCard ClassNotFound
04-26 08:19:27.128: V/>>>(23528): Build: asus, Nexus 7

Using the Android API should tell you the actual device info your code is running on - Get Android Phone Model Programmatically


Just tested and confirmed that the following code:

String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; Log.v(">>>", "Build: " + manufacturer + ", " + model);

will print on Glass this info:

02-07 22:35:16.659: V/>>>(1705): Build: Google, Glass 1

Generally, a tip I've learned to remember after 2+ months of immersion in GDK is that as GDK is based on Android 4.0.3 (API level 15), most of the Android APIs of level <=15 can work on Glass.

3
  • This only tells me that the class is available .. but not that the code is actually running on a Google Glass device. In addition, a "mutable" set of code may require android.glass class to be available for when one is running on a Glass device. Thanks for the thought, however!!! Feb 7, 2014 at 23:45
  • Thanks for your comment. I don't have Glass around now, but I believe you can use Android API to find out the device info. Please see me edited answer.
    – Jeff Tang
    Feb 8, 2014 at 0:58
  • this is not a preferred way to determine whether code is running on Google Glass, see accepted answer below. Also, Google Glass code has been updated to the API 19 level for most things. Jul 23, 2014 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.