/**
* 是否为鸿蒙系统
*
* @return true为鸿蒙系统
*/
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 x) {
return false;
}
}
/**
* 获取鸿蒙系统版本号
*
* @return 版本号
*/
public static String getHarmonyVersion() {
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;
}
Android代码中判断是否为鸿蒙系统、获取鸿蒙系统版本号
最新推荐文章于 2025-09-11 21:39:30 发布
此篇博客介绍了如何通过Java代码判断设备是否运行鸿蒙系统,并提供获取鸿蒙系统版本的方法,对于开发者检查系统兼容性很有帮助。
3943





