Android图片管理工具 弹窗 保活 音乐播放器 自定义View 计步器 项目框架HarmonyOS

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

2021-06-16  本文已影响0人  GexYY

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

/**
     * 获取华为系统版本名称
     * @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;
    }
上一篇 下一篇

猜你喜欢

热点阅读