见以下代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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 ignored) { } return false; } public static String getHarmonyVersion() { return getProp("hw_sc.build.platform.version", ""); } private static String getProp(String property, String defaultValue) { try { Class clz = Class.forName("android.os.SystemProperties"); Method method = clz.getDeclaredMethod("get", String.class); String value = (String) method.invoke(clz, property); if (!TextUtils.isEmpty(value)) return value; } catch (Throwable ignored) { } return defaultValue; } |