最近在做推送 集成了华为 小米 得推送 根据判断设备是华为还是小米分别进行处理
现在给出官方给的判断方法 以供参考
public class DeviceUtils {
//判断是否是华为系统 官网提供
public static boolean isEMUI(){
//emuiApiLevel>0 即华为系统
int emuiApiLevel = 0;
try {
Class cls = Class.forName("android.os.SystemProperties");
Method method = cls.getDeclaredMethod("get", new Class[]{String.class});
emuiApiLevel = Integer.parseInt((String) method.invoke(cls, new Object[]{"ro.build.hw_emui_api_level"}));
} catch (Exception e) {
e.printStackTrace();
}
return emuiApiLevel>0;
}
//判官是否是小米系统 官网提供
public static boolean isMIUI(){
String manufacturer = Build.MANUFACTURER;
//这个字符串可以自己定义,例如判断华为就填写huawei,魅族就填写meizu
if ("xiaomi".equalsIgnoreCase(manufacturer)) {
return true;
}
return false;
}
}