Android 依据Build相关信息判断机型

2023-12-13 03:30:03

Android 依据Build相关信息判断机型

本文主要通过Build的相关信息获取机型,目前机型判断的较少,后续继续维护更新

public static String parseBuild() {
    StringBuilder sb = new StringBuilder();
    String deriveFingerprint = Build.FINGERPRINT;
    String manufacturer = Build.MANUFACTURER;
    if (!TextUtils.isEmpty(deriveFingerprint)
            && !TextUtils.equals(deriveFingerprint, Build.UNKNOWN)) {
        sb.append(deriveFingerprint.toLowerCase(Locale.US));
    }
    if (!TextUtils.isEmpty(manufacturer)
            && !TextUtils.equals(manufacturer, Build.UNKNOWN)) {
        sb.append(",");
        sb.append(manufacturer.toLowerCase(Locale.US));
    }
    return sb.toString();
}

public static String getRom(){
    String s = parseBuild();
    if (TextUtils.isEmpty(s)){
        return "";
    }
    if (s.contains("xiaomi"))  return "xiaomi";
    if (s.contains("samsung"))  return "samsung";
    if (s.contains("vivo"))  return "vivo";
    if (s.contains("oppo"))  return "oppo";
    if (s.contains("realme"))  return "realme";
    if (s.contains("meizu")) return "meizu";
    if (s.contains("huawei") || s.contains("honor") ) {
        if (s.contains("honor")) {
            return "honor";
        }
        return "huawei";
    }
    if (s.contains("oneplus")) return "oneplus";
    if (s.contains("lenovo")) return "lenovo";
    return "";
}

文章来源:https://blog.csdn.net/qq_23025319/article/details/134885039
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。