以编程方式获取Android MIUI版本信息

时间:2016-11-11 17:06:02

标签: android

我正在开发和Android应用程序,我需要以编程方式知道手机的miui版本信息。有人知道怎么做吗?在android.os.build和android.os.build.version中,rom名称只是关于生产者的版本和一些东西。我需要知道哪个是安装的rom,例如:xiaomi.eu stable或weekly,china developer或global stable等...当我点击&#时,我可以从手机设置中读取相同的信息34;电话信息"。

1 个答案:

答案 0 :(得分:1)

您必须使用Reflection来读取MIUI版本名称和版本代码。

可以通过读取ro.miui.ui.version.codero.miui.ui.version.name属性来包含MIUI版本代码和版本名称

private void readMIVersion() {
    try {
        @SuppressLint("PrivateApi") final Class<?> propertyClass = Class.forName("android.os.SystemProperties");
        final Method method = propertyClass.getMethod("get", String.class);
        final String versionCode = (String) method.invoke(propertyClass, "ro.miui.ui.version.code");
        final String versionName = (String) method.invoke(propertyClass, "ro.miui.ui.version.name");
        Log.d(TAG, "Version Code: " + versionCode);
        Log.d(TAG, "Version Name: " + versionName);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
    }
}

目前,您可以阅读信息,但是在将来的版本中,可能会删除读取这些限制值的功能。

相关问题