如何以编程方式从 Android 获取自定义 ROM/Android 操作系统名称

问题描述

我希望从设备接收自定义 ROM/Android 操作系统名称,例如假设设备是:

Oppo -> ColorOS

OnePlus -> OxygenOS

华为 -> HarmonyOS

我也使用过以下方法,但没有成功。

Build.disPLAY -> ONEPLUS A6003_22_201116

Build.VERSION.BASE_OS -> "" // 返回空字符串

System.getProperty("os.name") -> Linux

System.getProperty("os.version") -> 4.9.179-perf+

System.getProperty("ro.modversion") -> null // 返回 null

解决方法

您可以通过以下方式查看和获取鸿蒙:

public static boolean isHarmony(Context context) {
    try {
        int id = Resources.getSystem().getIdentifier("config_os_brand","string","android");
        return context.getString(id).equals("harmony");
    } catch (Exception e) {
        return false;
    }
}