Loading

如何判断用户使用的模拟器还是真正的安卓设备?

    /**
     * 判断用户使用的模拟器还是真正的安卓设备?
     *
     * @return
     */
    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;
    }

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

posted @ 2022-03-21 10:00  Roc-xb  阅读(27)  评论(0)    收藏  举报

易微帮源码


易微帮官网