//鸿蒙系统
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;
}
}