Get MIUI version - Android Android OS

Android examples for Android OS:OS Version

Description

Get MIUI version

Demo Code


import android.os.Build;
import java.lang.reflect.Method;

public class Main{
    /**//from  www. j  av a2 s .  c  o  m
     * Get MIUI version
     *
     * @return the MIUI version or -1 if failed to get this value.
     */
    public static int getMIUIVersion() {
        int result = -1;
        String miuiVer = PropertyUtils.getQuickly(
                "ro.miui.ui.version.name", null);
        if (miuiVer != null && miuiVer.contains("V")) {
            int versionStart = miuiVer.indexOf("V") + 1;
            if (versionStart < miuiVer.length()) {
                String version = miuiVer.substring(versionStart);
                try {
                    result = Integer.parseInt(version);
                } catch (NumberFormatException e) {
                    //omit
                }
            }
        }
        return result;
    }
}

Related Tutorials