gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:24:57 28 4
gpt4 key购买 nike

我正在开发 Android 应用程序,我需要以编程方式了解手机的 miui 版本信息。有人知道怎么做吗?在 android.os.build 和 android.os.build.version 中,没有关于 rom 名称的任何内容,只有版本和有关生产者的一些信息。我需要知道安装的 ROM 是哪个,例如:xiaomi.eu stable 或 Weekly、china Developer 或 Global stable 等...与我点击“手机”时可以从手机设置中读取的信息相同信息”。

最佳答案

您必须使用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();
}
}

目前,您可以读取这些信息,但在未来的版本中,读取这些受限值的功能可能会被删除。

关于android - 以编程方式获取 Android MIUI 版本信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40552878/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com