问题:在鸿蒙系统HarmonyOS 2.0中如何判断手机型号是不是MateX,请给出实现的代码?
回答: 请尝试以下代码: try { Class clz = Class.forName("android.os.Build"); Field[] fields = clz.getFields(); //遍历一下: for (Field field : fields) { System.out.println(field.getName()); System.out.println( field.getName() + " : " +field.get(clz) ); } Field model = clz.getField("MODEL");//型号应该是它 ClassLoader classLoader = clz.getClassLoader(); if (classLoader != null && classLoader.getParent() == null) { System.out.println("MODEL: " + model.get(clz)); } } catch (Exception e) { e.printStackTrace(); }
|