Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Android MIUI Version Information Programmatically

Tags:

android

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".

like image 286
Codename47 Avatar asked Nov 11 '16 17:11

Codename47


2 Answers

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.

like image 90
Srikar Reddy Avatar answered Sep 28 '22 08:09

Srikar Reddy


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

like image 32
Владислав Стариков Avatar answered Sep 28 '22 06:09

Владислав Стариков