Android开发判断是否为鸿蒙系统

//鸿蒙系统
public static boolean isHarmonyOs(){
    try {
        Class<?> buildExClass = Class.forName("com.huawei.system.BuildEx");
        Object osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass);
        return "harmony".equalsIgnoreCase(osBrand.toString());
    }catch (Throwable e){
	return false;
    }
}
//鸿蒙3.0以上系统
public static boolean isHarmonyOs3(){
    try {
        Class<?> clz = Class.forName("android.os.Build");
        Method getStringMethod  = clz.getDeclaredMethod("getString", String.class);
        getStringMethod.setAccessible(true);
        String value = (String)getStringMethod.invoke(null, "hw_sc.build.os.apiversion");
        return Integer.parseInt(value) >= 8;
    }catch (Throwable e){
	return false;
    }
}
posted @ 2021-06-30 11:31  yongfengnice  阅读(1660)  评论(1编辑  收藏  举报