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

XY道衍
发布于 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
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
Whyalone
Whyalone

这是要开发同时兼容A和H设备的应用?

回复
2021-7-7 11:03:21
回复
    相关推荐