Detect Google Glass Programmatically

2019-04-26 06:10发布

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");
 }

4条回答
不美不萌又怎样
2楼-- · 2019-04-26 06:27

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

查看更多
Rolldiameter
3楼-- · 2019-04-26 06:42

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

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

查看更多
欢心
4楼-- · 2019-04-26 06:45

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

查看更多
Evening l夕情丶
5楼-- · 2019-04-26 06:48

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

查看更多
登录 后发表回答