Detect Google Glass Programmatically

淺唱寂寞╮ 提交于 2019-12-14 03:44:09

问题


From a native application how can we detect Google Glass verses a smart phone from code?

Moving correct answer to question:

boolean isRunningOnGlass() {
     return "Google".equalsIgnoreCase(Build.MANUFACTURER) && Build.MODEL.startsWith("Glass");
 }

回答1:


Another way of doing this would be to use the Build API:

http://developer.android.com/reference/android/os/Build.html




回答2:


Using the GDK, you could use:

 boolean isRunningOnGlass() {
     return "Google".equalsIgnoreCase(Build.MANUFACTURER) && Build.MODEL.startsWith("Glass");
 }

(The model check may be good if a new model of Google Glas comes out.)




回答3:


I suspect that there will be an official way of getting this, but perhaps you could use the browser user-agent:

1) On Android, you can get the user-agent programmatically via: how to get the default HTTP USER AGENT from the android device?

2) The user-agent can change, of course, but at of July 2013 it is/was:

Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; Glass 1 Build/IMM76L; XE7) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30




回答4:


You can figure out your android app is running on which OS Build, Product, Device etc. by using the android.os.Build class.

Eg: You can detect if your app is running on google glass(API 19) like this:

if(Build.VERSION.SDK_INT==Build.VERSION_CODES.KITKAT){
        Log.e("SDK_INT",""+Build.VERSION.SDK_INT);
        Log.e("MODEL",""+Build.MODEL);
        Log.e("DEVICE",""+Build.DEVICE);
        Log.e("TYPE",""+Build.TYPE);
        Log.e("HARDWARE",""+Build.HARDWARE);
        Log.e("BRAND",""+Build.BRAND);
        Log.e("DISPLAY",""+Build.DISPLAY);
        Log.e("MANUFACTURER",""+Build.MANUFACTURER);
        Log.e("PRODUCT",""+Build.PRODUCT);
        if (isGlass()){
            Log.e("isGlass","True");
        }
    } else {
    Log.e("Other",""+Build.VERSION.SDK_INT);
}
boolean isGlass(){return"Google".equalsIgnoreCase(Build.MANUFACTURER)&&Build.MODEL.startsWith("Glass");
}

Log Results

09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/SDK_INT: 19
09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/MODEL: Glass 1
09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/DEVICE: glass-1

Similarly, for watches (API KITKAT_WATCH = 20).



来源:https://stackoverflow.com/questions/18723689/detect-google-glass-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!