赞
踩
现在华为更新了鸿蒙,今天搜了一波是否为鸿蒙,记录一下。
String manufacturer = getDeviceManufacturer(); //是否为华为和手机系统是否大于Android10 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && manufacturer.equals("HUAWEI")){ boolean harmonyOs = isHarmonyOs(); if(harmonyOs){ ConfigTest.isHarmonyOs = "Harmony"; } }else{ ConfigTest.isHarmonyOs = "Android"; }
//返回手机厂商 public String getDeviceManufacturer() { Build b = new Build(); String manufacturer = b.MANUFACTURER; return manufacturer; }
/** * 是否为鸿蒙系统 * * @return true为鸿蒙系统 */ public static boolean isHarmonyOs() { try { Class<?> buildExClass = Class.forName("com.huawei.system.BuildEx"); Object osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass); return HARMONY_OS.equalsIgnoreCase(osBrand.toString()); } catch (Throwable x) { return false; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。