private static final String HARMONY_OS = "harmony";
//判断是否为鸿蒙
public static boolean isHarmonyOSa() {
try {
Class clz = Class.forName("com.huawei.system.BuildEx");
Method method = Method("getOsBrand");
ClassLoader classLoader = ClassLoader();
System.out.println("classLoader: " + classLoader);
//BootClassLoader的parent为null
if (classLoader != null && Parent() == null) {
//return method.invoke(clz).toString();//返回获取的名称
//****返回是否是鸿蒙系统⾃⾏注释并将⽅法返回值改为boolean
return HARMONY_OS.equals(method.invoke(clz));
}
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (Exception e) {
}
return false;
}
亲测有效
发布评论