通过反射判断当前设备是Android还是Harmony

发布于 2021-7-7 10:12
浏览
0收藏

private static final String HARMONY_OS = “harmony”;
/**

  • check the system is harmony os
  • @return true if it is harmony os
    */
    public static boolean isHarmonyOS() {
    try {
    Class clz = Class.forName(“com.huawei.system.BuildEx”);
    Method method = clz.getMethod(“getOsBrand”);
    return HARMONY_OS.equals(method.invoke(clz));
    } catch (ClassNotFoundException e) {
    Log.e(TAG, “occured ClassNotFoundException”);
    } catch (NoSuchMethodException e) {
    Log.e(TAG, “occured NoSuchMethodException”);
    } catch (Exception e) {
    Log.e(TAG, “occur other problem”);
    }
    return false;
    }

标签
1
收藏
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐