is Glass and is Android - Android Android OS

Android examples for Android OS:OS Build

Description

is Glass and is Android

Demo Code


import java.util.Enumeration;
import java.util.Properties;

public class Main{
    private static Boolean isAndroid;
    private static Boolean isGlass;
    public static boolean isGlass() {
        if (isAndroid()) {
            if (isGlass == null) {
                try {
                    Class<?> Build = Class.forName("android.os.Build");
                    String Build_MANUFACTURER = (String) Build
                            .getDeclaredField("MANUFACTURER").get(
                                    String.class);
                    String Build_MODEL = (String) Build.getDeclaredField(
                            "MODEL").get(String.class);
                    isGlass = "Google".equalsIgnoreCase(Build_MANUFACTURER)
                            && Build_MODEL.startsWith("Glass");
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }//from  w w w . j  a v a2 s .  c o  m
            }
            return isGlass;
        }
        return false;
    }
    public static boolean isAndroid() {
        if (isAndroid == null) {
            try {
                isAndroid = System.getProperties().get("java.vendor")
                        .toString().toLowerCase().contains("android");
                if (isAndroid) {
                    return isAndroid;
                }
            } catch (Exception e) {
            }
            try {
                isAndroid = System.getProperties().get("java.vm.vendor")
                        .toString().toLowerCase().contains("android");
                if (isAndroid) {
                    return isAndroid;
                }
            } catch (Exception e1) {
                try {
                    isAndroid = System.getProperties().get("java.vm.name")
                            .toString().toLowerCase().equals("dalvik");
                } catch (Exception e2) {
                    try {
                        Properties p = System.getProperties();
                        Enumeration keys = p.keys();
                        while (keys.hasMoreElements()) {
                            String key = (String) keys.nextElement();
                            String value = (String) p.get(key);
                            System.out.println("  > " + key + "=" + value);
                            if (value.toLowerCase().contains("android")) {
                                isAndroid = true;
                                return isAndroid;
                            }
                        }
                    } catch (Exception e3) {
                        Log.e("Could not detect if running on Android!");
                        isAndroid = false;
                    }
                }
            }
        }
        return isAndroid;
    }
}

Related Tutorials