如何确定我的代码是否在Google Glass上运行?

时间:2014-02-07 04:24:19

标签: google-glass google-gdk

我想创建一些实用程序类,以便在Android手机和Google Glass上使用(使用GDK)。在Glass上运行时需要注意一些差异(例如获取位置)。

是否有一些静态方法调用可以使用或以其他方式确定代码是否在Glass上运行?

2 个答案:

答案 0 :(得分:4)

好的..这是一种可以用来确定代码是否在Google Glass设备上运行的方法(汇总来自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;
}

答案 1 :(得分:0)

针对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);

将在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

在Nexus平板电脑上打印:

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

使用Android API会告诉您代码运行的实际设备信息 - Get Android Phone Model Programmatically


刚刚测试并确认了以下代码:

String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; Log.v(“>>>”,“构建:”+制造商+“,”+型号);

将在Glass上打印此信息:

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

一般来说,我在GDK沉浸2个多月后学会记住的一个提示是,由于GDK基于Android 4.0.3(API级别15),大多数级别< = 15的Android API都可以在Glass上工作。