Android判断真机和模拟器

private static String getSystemProperty(String name) throws Exception {
    Class systemPropertyClazz = Class.forName("android.os.SystemProperties");
    return (String) systemPropertyClazz.getMethod("get", new Class[]{String.class})
            .invoke(systemPropertyClazz, new Object[]{name});
}

public static boolean checkEmulator() {
    try {
        boolean goldfish = getSystemProperty("ro.hardware").contains("goldfish");
        boolean emu = getSystemProperty("ro.kernel.qemu").length() > 0;
        boolean sdk = getSystemProperty("ro.product.model").equals("sdk");
        if (emu || goldfish || sdk) {
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}

你可能感兴趣的:(android,android,真机,模拟器)