Detect Google Glass Programmatically
Asked Answered
M

4

7

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");
 }
Maje answered 10/9, 2013 at 15:58 Comment(0)
F
6

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

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

Furniture answered 10/9, 2013 at 16:58 Comment(2)
I am going this for the time being: if(android.os.Build.Model.Contains("Glass"));Maje
I recommend you check both the MANUFACTURER and MODEL. (For a foolproof mechanism, we may need to use a GDK unique class/method. I will research that.Accent
A
4

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

Accent answered 27/2, 2014 at 6:40 Comment(0)
F
0

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

Furniture answered 10/9, 2013 at 16:56 Comment(0)
R
0

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

Reportage answered 13/9, 2017 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.