Android App内识别当前鸿蒙系统版本以及纯净模式开启

作者: GexYY | 来源:发表于2021-06-16 14:53 被阅读0次

识别鸿蒙系统以及获取系统版本

/**
     * 获取华为系统版本名称
     * @return String  返回值:harmony
     * */
    public static String osBandName() {
        try {
            Class clz = Class.forName("com.huawei.system.BuildEx");
            return (String) clz.getMethod("getOsBrand").invoke(clz);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 获取华为系统版本号
     * @return 版本号
     */
    public static String harmonyOsv() {
        return getProp("hw_sc.build.platform.version", "");
    }

    private static String getProp(String property, String defaultValue) {
        try {
            Class spClz = Class.forName("android.os.SystemProperties");
            Method method = spClz.getDeclaredMethod("get", String.class);
            String value = (String) method.invoke(spClz, property);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return value;
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return defaultValue;
    }

二、判断鸿蒙系统纯净模式是否开启

/**
     * 获取鸿蒙纯净模式状态
     * 0:开启,1:关闭
     *
     * @param context
     * @return
     */
    public static int readPureModeState(Context context) {
        int result = 1;
        if (!isHarmonyOs()) {
            return result;
        }
        try {
            if (context != null) {
                result = Settings.Secure.getInt(context.getContentResolver(), "pure_mode_state", 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

相关文章

网友评论

    本文标题:Android App内识别当前鸿蒙系统版本以及纯净模式开启

    本文链接:https://www.haomeiwen.com/subject/qlzxyltx.html