当前位置:   article > 正文

Android代码中判断是否为鸿蒙系统、获取鸿蒙系统版本号_鸿蒙android 代码

鸿蒙android 代码

通过映射,获取鸿蒙系统的版本信息。

  1. /**
  2.  * 是否为鸿蒙系统
  3.  *
  4.  * @return true为鸿蒙系统
  5.  */
  6. public static boolean isHarmonyOs() {
  7.     try {
  8.         Class<?> buildExClass = Class.forName("com.huawei.system.BuildEx");
  9.         Object osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass);
  10.         return "Harmony".equalsIgnoreCase(osBrand.toString());
  11.     } catch (Throwable x) {
  12.         return false;
  13.     }
  14. }
  15.  
  16. /**
  17.  * 获取鸿蒙系统版本号
  18.  *
  19.  * @return 版本号
  20.  */
  21. public static String getHarmonyVersion() {
  22.     return getProp("hw_sc.build.platform.version", "");
  23. }
  24.  
  25. private static String getProp(String property, String defaultValue) {
  26.     try {
  27.         Class spClz = Class.forName("android.os.SystemProperties");
  28.         Method method = spClz.getDeclaredMethod("get", String.class);
  29.         String value = (String) method.invoke(spClz, property);
  30.         if (TextUtils.isEmpty(value)) {
  31.             return defaultValue;
  32.         }
  33.         return value;
  34.     } catch (Throwable e) {
  35.         e.printStackTrace();
  36.     }
  37.     return defaultValue;
  38. }


————————————————

原文链接:https://blog.csdn.net/qq_36961698/article/details/123989852

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/98248
推荐阅读
相关标签
  

闽ICP备14008679号