I am developing and android app and I need to know the miui version info of the phone programmatically. There's someone that knows how to do it? In android.os.build and android.os.build.version there's nothing about the rom name just only the version and some stuff about the producer. I need to know which is the rom installed on, such as for example: xiaomi.eu stable or weekly, china developer or global stable etc... Just the same info that I can read from the phone settings when I tap on "phone info".
You have to use Reflection to read the MIUI version name and version code.
MIUI Version code and Version name can be contained by reading the ro.miui.ui.version.code
and ro.miui.ui.version.name
properties
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();
}
}
For now, you can read the information but in future releases, the ability to read these restricted values may be removed.
Just use Build.VERSION.INCREMENTAL
.
In my case, it returns "V12.5.1.0.RJOEUXM"
.
Also, you can extract more than just the MIUI version from this string.
See https://www.xiaomist.com/2020/08/what-do-letters-and-numbers-that.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With