2014-02-07 59 views

回答

4

確定..這裏是一個可以用它來確定代碼是否被谷歌眼鏡設備上運行(從傑夫·唐捲起信息)的方法:

/** 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

更新了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); 

將打印在玻璃:

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


只是測試並確認以下代碼:

字符串製造商= Build.MANUFACTURER; String model = Build.MODEL; Log.v(「>>>」,「Build:」+ manufacturer +「,」+ model);

將玻璃上打印此信息:

02-07 22:35:16.659:V/>>>(1705):體形:谷歌,玻璃1

一般來說,小費我已經在GDK中進行了2個月的沉浸式學習後,記住GDK基於Android 4.0.3(API級別15),大多數級別爲< = 15的Android API都可以在Glass上工作。

+0

這只是告訴我,這個類是可用的。但並不是代碼實際上是在Google Glass設備上運行的。另外,一組「可變」代碼可能需要android.glass類在Glass設備上運行時纔可用。但是,感謝您的想法! – ErstwhileIII

+0

感謝您的評論。我現在沒有Glass,但我相信你可以使用Android API來查找設備信息。請看我編輯的答案。 –

+1

上面進行了新的編輯。 –

相關問題